Skip to content

Commit

Permalink
feat(batch): introduce batch AsOf join (#19790)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhao-su authored Jan 28, 2025
1 parent 0f5bae0 commit c89eeed
Show file tree
Hide file tree
Showing 14 changed files with 402 additions and 127 deletions.
43 changes: 43 additions & 0 deletions e2e_test/batch/join/asof_join.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
statement ok
SET RW_IMPLICIT_FLUSH TO true;

statement ok
create table t1 (v1 int, v2 int, v3 int primary key);

statement ok
create table t2 (v1 int, v2 int, v3 int primary key);

statement ok
insert into t1 values (1, 2, 3), (2, 3, 4), (1, 2, 9);

statement ok
insert into t2 values (1, NULL, 8), (1, 3, 4), (1, 2, 5), (1, 2, 6);

# asof inner join
query IIIIII
SELECT t1.v1 t1_v1, t1.v2 t1_v2, t1.v3 t1_v3, t2.v1 t2_v1, t2.v2 t2_v2, t2.v3 t2_v3 FROM t1 ASOF JOIN t2 ON t1.v1 = t2.v1 and t1.v2 < t2.v2 order by t1.v1, t1.v3;
----
1 2 3 1 3 4
1 2 9 1 3 4

# asof left join
query IIIIII
SELECT t1.v1 t1_v1, t1.v2 t1_v2, t1.v3 t1_v3, t2.v1 t2_v1, t2.v2 t2_v2, t2.v3 t2_v3 FROM t1 ASOF LEFT JOIN t2 ON t1.v1 = t2.v1 and t1.v2 < t2.v2 order by t1.v1, t1.v3;
----
1 2 3 1 3 4
1 2 9 1 3 4
2 3 4 NULL NULL NULL

# asof left join
query IIIIII
SELECT t1.v1 t1_v1, t1.v2 t1_v2, t1.v3 t1_v3, t2.v1 t2_v1, t2.v2 t2_v2, t2.v3 t2_v3 FROM t1 ASOF LEFT JOIN t2 ON t1.v1 = t2.v1 and t1.v2 > t2.v2 order by t1.v1, t1.v3;
----
1 2 3 NULL NULL NULL
1 2 9 NULL NULL NULL
2 3 4 NULL NULL NULL

statement ok
drop table t1;

statement ok
drop table t2;
1 change: 1 addition & 0 deletions proto/batch_plan.proto
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ message HashJoinNode {
// Null safe means it treats `null = null` as true.
// Each key pair can be null safe independently. (left_key, right_key, null_safe)
repeated bool null_safe = 6;
optional plan_common.AsOfJoinDesc asof_desc = 7;
}

message SortMergeJoinNode {
Expand Down
1 change: 1 addition & 0 deletions src/batch/executors/benches/hash_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn create_hash_join_executor(
"HashJoinExecutor".into(),
CHUNK_SIZE,
None,
None,
BatchSpillMetrics::for_test(),
ShutdownToken::empty(),
MemoryContext::none(),
Expand Down
Loading

0 comments on commit c89eeed

Please sign in to comment.