-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(streaming): plan asof join (#18683)
- Loading branch information
Showing
27 changed files
with
897 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
statement ok | ||
SET RW_IMPLICIT_FLUSH TO true; | ||
|
||
# asof inner join | ||
|
||
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 | ||
create materialized view mv1 as 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; | ||
|
||
statement ok | ||
insert into t1 values (1, 2, 3); | ||
|
||
statement ok | ||
insert into t2 values (1, 3, 4); | ||
|
||
query III | ||
select * from mv1; | ||
---- | ||
1 2 3 1 3 4 | ||
|
||
statement ok | ||
insert into t2 values (1, 2, 3); | ||
|
||
query III | ||
select * from mv1; | ||
---- | ||
1 2 3 1 2 3 | ||
|
||
statement ok | ||
delete from t1 where v3 = 3; | ||
|
||
query III | ||
select * from mv1; | ||
---- | ||
|
||
|
||
statement ok | ||
insert into t1 values (2, 3, 4); | ||
|
||
statement ok | ||
insert into t2 values (2, 3, 6), (2, 3, 7), (2, 3, 5); | ||
|
||
query III | ||
select * from mv1; | ||
---- | ||
2 3 4 2 3 5 | ||
|
||
statement ok | ||
insert into t2 values (2, 3, 1), (2, 3, 2); | ||
|
||
query III | ||
select * from mv1; | ||
---- | ||
2 3 4 2 3 1 | ||
|
||
statement ok | ||
drop materialized view mv1; | ||
|
||
statement ok | ||
drop table t1; | ||
|
||
statement ok | ||
drop table t2; | ||
|
||
|
||
# asof left join | ||
|
||
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 | ||
create materialized view mv1 as 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; | ||
|
||
statement ok | ||
insert into t1 values (1, 2, 3); | ||
|
||
statement ok | ||
insert into t2 values (1, 2, 4); | ||
|
||
query III | ||
select * from mv1; | ||
---- | ||
1 2 3 NULL NULL NULL | ||
|
||
statement ok | ||
insert into t2 values (1, 1, 3); | ||
|
||
query III | ||
select * from mv1; | ||
---- | ||
1 2 3 1 1 3 | ||
|
||
statement ok | ||
delete from t1 where v3 = 3; | ||
|
||
query III | ||
select * from mv1; | ||
---- | ||
|
||
|
||
statement ok | ||
insert into t1 values (2, 3, 4); | ||
|
||
statement ok | ||
insert into t2 values (2, 2, 6), (2, 2, 7), (2, 2, 5); | ||
|
||
query III | ||
select * from mv1; | ||
---- | ||
2 3 4 2 2 5 | ||
|
||
statement ok | ||
insert into t2 values (2, 2, 1), (2, 2, 2); | ||
|
||
query III | ||
select * from mv1; | ||
---- | ||
2 3 4 2 2 1 | ||
|
||
statement ok | ||
delete from t2 where v1 = 2; | ||
|
||
query III | ||
select * from mv1; | ||
---- | ||
2 3 4 NULL NULL NULL | ||
|
||
statement ok | ||
drop materialized view mv1; | ||
|
||
statement ok | ||
drop table t1; | ||
|
||
statement ok | ||
drop table t2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/frontend/planner_test/tests/testdata/input/asof_join.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
- sql: | ||
CREATE TABLE t1(v1 varchar, v2 int, v3 int); | ||
CREATE TABLE t2(v1 varchar, v2 int, v3 int); | ||
SELECT * FROM t1 ASOF JOIN t2 ON t1.v1 = t2.v1; | ||
expected_outputs: | ||
- stream_error | ||
|
||
- sql: | ||
CREATE TABLE t1(v1 varchar, v2 int, v3 int); | ||
CREATE TABLE t2(v1 varchar, v2 int, v3 int); | ||
SELECT t1.v1 t1_v1, t1.v2 t1_v2, t2.v1 t2_v1, t2.v2 t2_v2 FROM t1 ASOF JOIN t2 ON t1.v1 = t2.v1 || 'a' and t1.v2 > t2.v2; | ||
expected_outputs: | ||
- batch_error | ||
- stream_plan | ||
|
||
- sql: | ||
CREATE TABLE t1(v1 varchar, v2 int, v3 int); | ||
CREATE TABLE t2(v1 varchar, v2 int, v3 int); | ||
SELECT t1.v1 t1_v1, t1.v2 t1_v2, t2.v1 t2_v1, t2.v2 t2_v2 FROM t1 ASOF LEFT JOIN t2 ON t1.v1 = t2.v1 and t1.v2 *2 < t2.v2; | ||
expected_outputs: | ||
- stream_plan | ||
|
||
- sql: | ||
CREATE TABLE t1(v1 varchar, v2 int, v3 int); | ||
CREATE TABLE t2(v1 varchar, v2 int, v3 int); | ||
SELECT t1.v1 t1_v1, t1.v2 t1_v2, t2.v1 t2_v1, t2.v2 t2_v2 FROM t1 ASOF JOIN t2 ON t1.v1 = t2.v1 and t1.v2 < t2.v2 and t1.v3 < t2.v3; | ||
expected_outputs: | ||
- stream_error | ||
|
||
- sql: | ||
CREATE TABLE t1(v1 varchar, v2 int, v3 int); | ||
CREATE TABLE t2(v1 varchar, v2 int, v3 int); | ||
SELECT t1.v1 t1_v1, t1.v2 t1_v2, t2.v1 t2_v1, t2.v2 t2_v2 FROM t1 ASOF JOIN t2 ON t1.v2 < t2.v2; | ||
expected_outputs: | ||
- stream_error |
28 changes: 28 additions & 0 deletions
28
src/frontend/planner_test/tests/testdata/output/asof_join.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# This file is automatically generated. See `src/frontend/planner_test/README.md` for more information. | ||
- sql: CREATE TABLE t1(v1 varchar, v2 int, v3 int); CREATE TABLE t2(v1 varchar, v2 int, v3 int); SELECT * FROM t1 ASOF JOIN t2 ON t1.v1 = t2.v1; | ||
stream_error: 'Invalid input syntax: AsOf join requires exactly 1 ineuquality condition' | ||
- sql: CREATE TABLE t1(v1 varchar, v2 int, v3 int); CREATE TABLE t2(v1 varchar, v2 int, v3 int); SELECT t1.v1 t1_v1, t1.v2 t1_v2, t2.v1 t2_v1, t2.v2 t2_v2 FROM t1 ASOF JOIN t2 ON t1.v1 = t2.v1 || 'a' and t1.v2 > t2.v2; | ||
stream_plan: |- | ||
StreamMaterialize { columns: [t1_v1, t1_v2, t2_v1, t2_v2, t1._row_id(hidden), t2._row_id(hidden)], stream_key: [t1._row_id, t2._row_id, t1_v1], pk_columns: [t1._row_id, t2._row_id, t1_v1], pk_conflict: NoCheck } | ||
└─StreamAsOfJoin { type: AsofInner, predicate: t1.v1 = $expr1 AND (t1.v2 > t2.v2), output: [t1.v1, t1.v2, t2.v1, t2.v2, t1._row_id, t2._row_id] } | ||
├─StreamExchange { dist: HashShard(t1.v1) } | ||
│ └─StreamTableScan { table: t1, columns: [t1.v1, t1.v2, t1._row_id], stream_scan_type: ArrangementBackfill, stream_key: [t1._row_id], pk: [_row_id], dist: UpstreamHashShard(t1._row_id) } | ||
└─StreamExchange { dist: HashShard($expr1) } | ||
└─StreamProject { exprs: [t2.v1, t2.v2, ConcatOp(t2.v1, 'a':Varchar) as $expr1, t2._row_id] } | ||
└─StreamTableScan { table: t2, columns: [t2.v1, t2.v2, t2._row_id], stream_scan_type: ArrangementBackfill, stream_key: [t2._row_id], pk: [_row_id], dist: UpstreamHashShard(t2._row_id) } | ||
batch_error: |- | ||
Not supported: AsOf join in batch query | ||
HINT: AsOf join is only supported in streaming query | ||
- sql: CREATE TABLE t1(v1 varchar, v2 int, v3 int); CREATE TABLE t2(v1 varchar, v2 int, v3 int); SELECT t1.v1 t1_v1, t1.v2 t1_v2, t2.v1 t2_v1, t2.v2 t2_v2 FROM t1 ASOF LEFT JOIN t2 ON t1.v1 = t2.v1 and t1.v2 *2 < t2.v2; | ||
stream_plan: |- | ||
StreamMaterialize { columns: [t1_v1, t1_v2, t2_v1, t2_v2, t1._row_id(hidden), t2._row_id(hidden)], stream_key: [t1._row_id, t2._row_id, t1_v1], pk_columns: [t1._row_id, t2._row_id, t1_v1], pk_conflict: NoCheck } | ||
└─StreamAsOfJoin { type: AsofLeftOuter, predicate: t1.v1 = t2.v1 AND ($expr1 < t2.v2), output: [t1.v1, t1.v2, t2.v1, t2.v2, t1._row_id, t2._row_id] } | ||
├─StreamExchange { dist: HashShard(t1.v1) } | ||
│ └─StreamProject { exprs: [t1.v1, t1.v2, (t1.v2 * 2:Int32) as $expr1, t1._row_id] } | ||
│ └─StreamTableScan { table: t1, columns: [t1.v1, t1.v2, t1._row_id], stream_scan_type: ArrangementBackfill, stream_key: [t1._row_id], pk: [_row_id], dist: UpstreamHashShard(t1._row_id) } | ||
└─StreamExchange { dist: HashShard(t2.v1) } | ||
└─StreamTableScan { table: t2, columns: [t2.v1, t2.v2, t2._row_id], stream_scan_type: ArrangementBackfill, stream_key: [t2._row_id], pk: [_row_id], dist: UpstreamHashShard(t2._row_id) } | ||
- sql: CREATE TABLE t1(v1 varchar, v2 int, v3 int); CREATE TABLE t2(v1 varchar, v2 int, v3 int); SELECT t1.v1 t1_v1, t1.v2 t1_v2, t2.v1 t2_v1, t2.v2 t2_v2 FROM t1 ASOF JOIN t2 ON t1.v1 = t2.v1 and t1.v2 < t2.v2 and t1.v3 < t2.v3; | ||
stream_error: 'Invalid input syntax: AsOf join requires exactly 1 ineuquality condition' | ||
- sql: CREATE TABLE t1(v1 varchar, v2 int, v3 int); CREATE TABLE t2(v1 varchar, v2 int, v3 int); SELECT t1.v1 t1_v1, t1.v2 t1_v2, t2.v1 t2_v1, t2.v2 t2_v2 FROM t1 ASOF JOIN t2 ON t1.v2 < t2.v2; | ||
stream_error: 'Invalid input syntax: AsOf join requires at least 1 equal condition' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.