MCPcopy
hub / github.com/pathwaycom/pathway / _merge

Method _merge

python/pathway/stdlib/temporal/_asof_join.py:259–403  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

257 return SubstitutionDesugaring({})
258
259 def _merge(self) -> pw.Table:
260 right_first = (
261 self._direction == Direction.BACKWARD and self._mode == pw.JoinMode.LEFT
262 ) or (self._direction == Direction.FORWARD and self._mode == pw.JoinMode.RIGHT)
263 orig_data = {
264 k: data.table.select(
265 side=data.side,
266 instance=data.make_instance(),
267 orig_id=data.table.id,
268 key=data.make_sort_key(right_first),
269 t=data.t,
270 **{
271 req_col.internal_name: (
272 req_col.column if data.side == req_col.side else req_col.default
273 )
274 for req_col in self._all_cols
275 },
276 )
277 for k, data in self._side_data.items()
278 }
279 target = pw.Table.concat_reindex(*orig_data.values())
280
281 target += target.sort(key=pw.this.key, instance=pw.this.instance)
282
283 next_table = _build_groups(target, dir_next=True)
284 prev_table = _build_groups(target, dir_next=False)
285 m = target + target.select(
286 next_same=next_table.peer_same,
287 next_diff=next_table.peer_diff,
288 prev_same=prev_table.peer_same,
289 prev_diff=prev_table.peer_diff,
290 )
291 peer_elem = None
292 if self._direction == Direction.BACKWARD:
293 peer_elem = m.prev_diff
294 elif self._direction == Direction.FORWARD:
295 peer_elem = m.next_diff
296 elif self._direction == Direction.NEAREST:
297
298 def select_nearest(
299 cur_t: expr.ColumnReference,
300 prev_id: expr.ColumnReference,
301 next_id: expr.ColumnReference,
302 prev_t: expr.ColumnReference,
303 next_t: expr.ColumnReference,
304 ):
305 return pw.if_else(
306 prev_id.is_none(),
307 next_id,
308 pw.if_else(
309 next_id.is_none(),
310 prev_id,
311 pw.if_else(
312 cur_t - pw.unwrap(prev_t) < pw.unwrap(next_t) - cur_t,
313 prev_id,
314 next_id,
315 ),
316 ),

Callers 1

__init__Method · 0.95

Calls 13

_build_groupsFunction · 0.85
make_instanceMethod · 0.80
make_sort_keyMethod · 0.80
itemsMethod · 0.80
concat_reindexMethod · 0.80
valuesMethod · 0.80
sortMethod · 0.80
update_typesMethod · 0.80
with_columnsMethod · 0.80
selectMethod · 0.45
ixMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected