-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(streaming): plan asof join #18683
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0ff2609
iinit
yuhao-su 8cc75e2
Merge branch 'main' of github.com:singularity-data/risingwave into yu…
yuhao-su d501577
stream node
yuhao-su ca0ea76
Merge branch 'main' of github.com:singularity-data/risingwave into yu…
yuhao-su 4153f2b
e2e
yuhao-su 40b0e8f
fix
yuhao-su 7cf0c0c
Merge branch 'main' of github.com:singularity-data/risingwave into yu…
yuhao-su 45fe957
fmt
yuhao-su f5abfdd
try bump node
yuhao-su 878d482
revert bump
yuhao-su bc8991f
improve
yuhao-su File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
- 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 |
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
# 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 ineuqual 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 ineuqual 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest to use "LEFT ASOF JOIN" instead of
ASOF LEFT JOIN
, because clickhouse uses this syntax.https://clickhouse.com/docs/en/sql-reference/statements/select/join#:~:text=ASOF%20JOIN%20and-,LEFT%20ASOF%20JOIN,-%2C%20joining%20sequences%20with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But duckdb use
ASOF LEFT JOIN
https://duckdb.org/docs/guides/sql_features/asof_join.html. @st1page any insight on this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, then I have no preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both can be easily supported, so no need to block merging on this 😆 . We can always support the other syntax later.