Skip to content

Commit 23f5aac

Browse files
authored
Fix/split listener (#228)
* feat: improve FlinkSqlSplitListener * feat: improve ImpalaSqlSplitListener * feat: improve MysqlSplitListener * fix: correct PgSqlSplitListener * feat: improve TrinoSqlSplitListener * test: add split listener unit test * chore: ignore iml file * feat: add pgsql missing rules * test: fix pgsql unit tests
1 parent 8c594cf commit 23f5aac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+37721
-37552
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ dist/
77
src/**/.antlr
88
coverage
99
.idea
10-
gen/
10+
gen/
11+
src/**/*.iml

src/grammar/flinksql/FlinkSqlParser.g4

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@ parser grammar FlinkSqlParser;
22

33
options { tokenVocab=FlinkSqlLexer; }
44

5-
program: statement EOF;
5+
program: singleStatement* EOF;
66

7-
statement
8-
: sqlStatements EOF
9-
;
10-
11-
sqlStatements
12-
: (sqlStatement | emptyStatement)*
7+
singleStatement
8+
: sqlStatement SEMICOLON?
9+
| emptyStatement
1310
;
1411

1512
sqlStatement
16-
: ddlStatement SEMICOLON? | dmlStatement SEMICOLON? | describeStatement SEMICOLON?
17-
| explainStatement SEMICOLON? | useStatement SEMICOLON?| showStatememt SEMICOLON?
18-
| loadStatement SEMICOLON?| unloadStatememt SEMICOLON?| setStatememt SEMICOLON?
19-
| resetStatememt SEMICOLON?| jarStatememt SEMICOLON?| dtAddStatement SEMICOLON?
13+
: ddlStatement | dmlStatement | describeStatement
14+
| explainStatement | useStatement | showStatememt
15+
| loadStatement | unloadStatememt | setStatememt
16+
| resetStatememt | jarStatememt | dtAddStatement
2017
;
2118

2219
emptyStatement

src/grammar/impala/ImpalaSqlParser.g4

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,35 @@ options
1919
tokenVocab=ImpalaSqlLexer;
2020
}
2121

22-
program: statement EOF;
22+
program: singleStatement* EOF;
2323

24-
statement
25-
: sqlStatements EOF
24+
singleStatement
25+
: sqlStatement SEMICOLON?
2626
;
2727

28-
sqlStatements
29-
: (sqlStatement | emptyStatement)*
30-
;
31-
32-
emptyStatement: SEMICOLON;
33-
3428
sqlStatement
35-
: queryStatement SEMICOLON?
36-
| useStatement SEMICOLON?
37-
| createStatement SEMICOLON?
38-
| alterStatement SEMICOLON?
39-
| truncateTableStatement SEMICOLON?
40-
| describeStatement SEMICOLON?
41-
| computeStatement SEMICOLON?
42-
| dropStatement SEMICOLON?
43-
| grantStatement SEMICOLON?
44-
| revokeStatement SEMICOLON?
45-
| insertStatement SEMICOLON?
46-
| deleteStatement SEMICOLON?
47-
| updateStatement SEMICOLON?
48-
| upsertStatement SEMICOLON?
49-
| showStatement SEMICOLON?
50-
| addCommentStatement SEMICOLON?
51-
| explainStatement SEMICOLON?
52-
| setStatement SEMICOLON?
53-
| shutdownStatement SEMICOLON?
54-
| invalidateMetaStatement SEMICOLON?
55-
| loadDataStatement SEMICOLON?
56-
| refreshStatement SEMICOLON?
29+
: queryStatement
30+
| useStatement
31+
| createStatement
32+
| alterStatement
33+
| truncateTableStatement
34+
| describeStatement
35+
| computeStatement
36+
| dropStatement
37+
| grantStatement
38+
| revokeStatement
39+
| insertStatement
40+
| deleteStatement
41+
| updateStatement
42+
| upsertStatement
43+
| showStatement
44+
| addCommentStatement
45+
| explainStatement
46+
| setStatement
47+
| shutdownStatement
48+
| invalidateMetaStatement
49+
| loadDataStatement
50+
| refreshStatement
5751
;
5852

5953
useStatement: KW_USE databaseNamePath;
@@ -337,7 +331,7 @@ addTableComments: KW_COMMENT KW_ON KW_TABLE tableNamePath KW_IS (stringLiteral |
337331

338332
addColumnComments: KW_COMMENT KW_ON KW_COLUMN columnNamePath KW_IS (stringLiteral | KW_NULL);
339333

340-
explainStatement: KW_EXPLAIN statement;
334+
explainStatement: KW_EXPLAIN sqlStatement;
341335

342336
setStatement: KW_SET (KW_ALL | identifier EQ expression)?;
343337

src/grammar/mysql/MySqlParser.g4

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ options { tokenVocab = MySqlLexer; }
3636
// Top Level Description
3737

3838
program
39-
: sqlStatements? EOF
39+
: singleStatement* EOF
4040
;
4141

42-
sqlStatements
43-
: (sqlStatement | emptyStatement_)*
44-
(sqlStatement SEMI? | emptyStatement_)
42+
singleStatement
43+
: sqlStatement SEMI?
44+
| emptyStatement_
4545
;
4646

4747
sqlStatement

src/grammar/pgsql/PostgreSQLLexer.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ KW_COMPRESSION: 'COMPRESSION';
671671
KW_PLAIN: 'PLAIN';
672672
KW_EXTENDED: 'EXTENDED';
673673
KW_MAIN: 'MAIN';
674+
KW_SKIP_LOCKED: 'SKIP_LOCKED';
675+
KW_BUFFER_USAGE_LIMIT: 'BUFFER_USAGE_LIMIT';
674676
//
675677

676678
// IDENTIFIERS (4.1.1)

src/grammar/pgsql/PostgreSQLParser.g4

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ options {
4040
tokenVocab = PostgreSQLLexer;
4141
}
4242

43-
program: stmtmulti;
43+
program: singleStmt* EOF;
4444

4545
plsqlroot: pl_function;
4646

47-
stmtmulti: (stmt SEMI?)*;
47+
singleStmt: stmt SEMI?;
4848

4949
stmt:
5050
altereventtrigstmt
@@ -617,7 +617,8 @@ colconstraintelem:
617617
KW_IDENTITY optparenthesizedseqoptlist?
618618
| OPEN_PAREN a_expr CLOSE_PAREN KW_STORED
619619
)
620-
| KW_REFERENCES qualified_name opt_column_list? key_match? key_actions?;
620+
| KW_REFERENCES qualified_name opt_column_list? key_match? key_actions?
621+
| opt_collate;
621622

622623
nulls_distinct: KW_NULLS KW_NOT? KW_DISTINCT;
623624

@@ -1406,7 +1407,7 @@ defacl_privilege_target:
14061407

14071408
indexstmt:
14081409
KW_CREATE opt_unique? KW_INDEX opt_concurrently? opt_if_not_exists? opt_index_name? KW_ON relation_expr access_method_clause
1409-
? OPEN_PAREN index_params CLOSE_PAREN opt_include? opt_reloptions? opttablespace?
1410+
? OPEN_PAREN index_params CLOSE_PAREN opt_include? nulls_distinct? opt_reloptions? opttablespace?
14101411
where_clause?;
14111412

14121413
opt_unique: KW_UNIQUE;
@@ -1981,7 +1982,7 @@ vacuumstmt:
19811982

19821983
analyzestmt:
19831984
analyze_keyword opt_verbose? opt_vacuum_relation_list?
1984-
| analyze_keyword OPEN_PAREN vac_analyze_option_list CLOSE_PAREN opt_vacuum_relation_list?;
1985+
| analyze_keyword OPEN_PAREN analyze_options_list CLOSE_PAREN opt_vacuum_relation_list?;
19851986

19861987
vac_analyze_option_list:
19871988
vac_analyze_option_elem (COMMA vac_analyze_option_elem)*;
@@ -1997,8 +1998,16 @@ vac_analyze_option_arg: opt_boolean_or_string | numericonly;
19971998

19981999
opt_analyze: analyze_keyword;
19992000

2001+
analyze_options_list: analyze_option_elem (COMMA analyze_option_elem)*;
2002+
2003+
analyze_option_elem: opt_verbose | opt_skiplock | opt_buffer_usage_limit; // support on v12+
2004+
20002005
opt_verbose: KW_VERBOSE (KW_FALSE | KW_TRUE)?;
20012006

2007+
opt_skiplock: KW_SKIP_LOCKED (KW_FALSE | KW_TRUE)?;
2008+
2009+
opt_buffer_usage_limit: KW_BUFFER_USAGE_LIMIT (numericonly | sconst);
2010+
20022011
opt_full: KW_FULL;
20032012

20042013
opt_freeze: KW_FREEZE;
@@ -2229,15 +2238,19 @@ sortby_list: sortby (COMMA sortby)*;
22292238
sortby:
22302239
column_expr_noparen (KW_USING qual_all_op | opt_asc_desc)? opt_nulls_order?;
22312240

2232-
select_limit:
2241+
select_limit: // https://www.postgresql.org/docs/16/sql-select.html#SQL-LIMIT
22332242
limit_clause offset_clause?
2234-
| offset_clause limit_clause?;
2243+
| offset_clause fetch_clause?
2244+
| fetch_clause offset_clause?
2245+
;
22352246

22362247
opt_select_limit: select_limit;
22372248

22382249
limit_clause:
2239-
KW_LIMIT select_limit_value (COMMA select_offset_value)?
2240-
| KW_FETCH first_or_next (
2250+
KW_LIMIT select_limit_value (COMMA select_offset_value)?;
2251+
2252+
fetch_clause:
2253+
KW_FETCH first_or_next (
22412254
select_fetch_first_value row_or_rows (KW_ONLY | KW_WITH KW_TIES)
22422255
| row_or_rows (KW_ONLY | KW_WITH KW_TIES)
22432256
);
@@ -2263,7 +2276,7 @@ row_or_rows: KW_ROW | KW_ROWS;
22632276

22642277
first_or_next: KW_FIRST | KW_NEXT;
22652278

2266-
group_clause: KW_GROUP KW_BY group_by_list;
2279+
group_clause: KW_GROUP KW_BY (all_or_distinct)? group_by_list;
22672280

22682281
group_by_list: group_by_item (COMMA group_by_item)*;
22692282

@@ -3110,6 +3123,7 @@ unreserved_keyword:
31103123
| KW_BACKWARD
31113124
| KW_BEFORE
31123125
| KW_BEGIN
3126+
| KW_BUFFER_USAGE_LIMIT
31133127
| KW_BY
31143128
| KW_CACHE
31153129
| KW_CALL
@@ -3330,6 +3344,7 @@ unreserved_keyword:
33303344
| KW_SHOW
33313345
| KW_SIMPLE
33323346
| KW_SKIP
3347+
| KW_SKIP_LOCKED
33333348
| KW_SNAPSHOT
33343349
| KW_SQL
33353350
| KW_STABLE

src/lib/flinksql/FlinkSqlParser.interp

Lines changed: 2 additions & 3 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)