Skip to content

Commit

Permalink
feat(on conflict): introduce do update if not null conflict behavior (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wcy-fdu authored Apr 3, 2024
1 parent 0a8e8f9 commit 28e320a
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 19 deletions.
53 changes: 53 additions & 0 deletions e2e_test/streaming/on_conflict.slt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
statement ok
SET RW_IMPLICIT_FLUSH TO true;

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

Expand All @@ -20,6 +23,9 @@ select v1, v2, v3 from mv1;
2 3 3
3 4 5

statement ok
SET RW_IMPLICIT_FLUSH TO true;

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

Expand Down Expand Up @@ -53,3 +59,50 @@ drop table t1;

statement ok
drop table t2;


statement ok
SET RW_IMPLICIT_FLUSH TO true;

statement ok
create table t3 (v1 int, v2 int, v3 int, primary key(v1)) on conflict do update if not null;

statement ok
insert into t3 values (1,null,2), (2,3,null);

statement ok
insert into t3 values (3,null,5), (3,6,null);

statement ok
insert into t3 values (1,5,null), (2,null,null);

statement ok
create materialized view mv3 as select * from t3;


query III rowsort
select v1, v2, v3 from mv3;
----
1 5 2
2 3 NULL
3 6 5


statement ok
update t3 set v2 = 2 where v1 > 1;

statement ok
flush;

query IIII rowsort
select v1, v2, v3 from mv3;
----
1 5 2
2 2 NULL
3 2 5

statement ok
drop materialized view mv3;

statement ok
drop table t3;
2 changes: 1 addition & 1 deletion src/sqlparser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2823,7 +2823,7 @@ impl Parser {
Keyword::NOT,
Keyword::NULL,
]) {
return parser_err!("On conflict behavior do update if not null is not supported yet.");
Ok(Some(OnConflict::DoUpdateIfNotNull))
} else {
Ok(None)
}
Expand Down
2 changes: 1 addition & 1 deletion src/sqlparser/tests/testdata/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
- input: CREATE TABLE T ("FULL" INT) ON CONFLICT IGNORE
formatted_sql: CREATE TABLE T ("FULL" INT) ON CONFLICT IGNORE
- input: CREATE TABLE T ("FULL" INT) ON CONFLICT DO UPDATE IF NOT NULL
error_msg: 'sql parser error: On conflict behavior do update if not null is not supported yet.'
formatted_sql: CREATE TABLE T ("FULL" INT) ON CONFLICT DO UPDATE IF NOT NULL
- input: CREATE USER user WITH SUPERUSER CREATEDB PASSWORD 'password'
formatted_sql: CREATE USER user WITH SUPERUSER CREATEDB PASSWORD 'password'
- input: CREATE SINK snk
Expand Down
Loading

0 comments on commit 28e320a

Please sign in to comment.