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
This commit is contained in:
Hayden
2023-12-08 18:33:16 +08:00
committed by GitHub
parent 8c594cf0f2
commit 23f5aac113
44 changed files with 38405 additions and 38236 deletions

View File

@ -2,21 +2,18 @@ parser grammar FlinkSqlParser;
options { tokenVocab=FlinkSqlLexer; }
program: statement EOF;
program: singleStatement* EOF;
statement
: sqlStatements EOF
;
sqlStatements
: (sqlStatement | emptyStatement)*
singleStatement
: sqlStatement SEMICOLON?
| emptyStatement
;
sqlStatement
: ddlStatement SEMICOLON? | dmlStatement SEMICOLON? | describeStatement SEMICOLON?
| explainStatement SEMICOLON? | useStatement SEMICOLON?| showStatememt SEMICOLON?
| loadStatement SEMICOLON?| unloadStatememt SEMICOLON?| setStatememt SEMICOLON?
| resetStatememt SEMICOLON?| jarStatememt SEMICOLON?| dtAddStatement SEMICOLON?
: ddlStatement | dmlStatement | describeStatement
| explainStatement | useStatement | showStatememt
| loadStatement | unloadStatememt | setStatememt
| resetStatememt | jarStatememt | dtAddStatement
;
emptyStatement

View File

@ -19,41 +19,35 @@ options
tokenVocab=ImpalaSqlLexer;
}
program: statement EOF;
program: singleStatement* EOF;
statement
: sqlStatements EOF
singleStatement
: sqlStatement SEMICOLON?
;
sqlStatements
: (sqlStatement | emptyStatement)*
;
emptyStatement: SEMICOLON;
sqlStatement
: queryStatement SEMICOLON?
| useStatement SEMICOLON?
| createStatement SEMICOLON?
| alterStatement SEMICOLON?
| truncateTableStatement SEMICOLON?
| describeStatement SEMICOLON?
| computeStatement SEMICOLON?
| dropStatement SEMICOLON?
| grantStatement SEMICOLON?
| revokeStatement SEMICOLON?
| insertStatement SEMICOLON?
| deleteStatement SEMICOLON?
| updateStatement SEMICOLON?
| upsertStatement SEMICOLON?
| showStatement SEMICOLON?
| addCommentStatement SEMICOLON?
| explainStatement SEMICOLON?
| setStatement SEMICOLON?
| shutdownStatement SEMICOLON?
| invalidateMetaStatement SEMICOLON?
| loadDataStatement SEMICOLON?
| refreshStatement SEMICOLON?
: queryStatement
| useStatement
| createStatement
| alterStatement
| truncateTableStatement
| describeStatement
| computeStatement
| dropStatement
| grantStatement
| revokeStatement
| insertStatement
| deleteStatement
| updateStatement
| upsertStatement
| showStatement
| addCommentStatement
| explainStatement
| setStatement
| shutdownStatement
| invalidateMetaStatement
| loadDataStatement
| refreshStatement
;
useStatement: KW_USE databaseNamePath;
@ -337,7 +331,7 @@ addTableComments: KW_COMMENT KW_ON KW_TABLE tableNamePath KW_IS (stringLiteral |
addColumnComments: KW_COMMENT KW_ON KW_COLUMN columnNamePath KW_IS (stringLiteral | KW_NULL);
explainStatement: KW_EXPLAIN statement;
explainStatement: KW_EXPLAIN sqlStatement;
setStatement: KW_SET (KW_ALL | identifier EQ expression)?;

View File

@ -36,12 +36,12 @@ options { tokenVocab = MySqlLexer; }
// Top Level Description
program
: sqlStatements? EOF
: singleStatement* EOF
;
sqlStatements
: (sqlStatement | emptyStatement_)*
(sqlStatement SEMI? | emptyStatement_)
singleStatement
: sqlStatement SEMI?
| emptyStatement_
;
sqlStatement

View File

@ -671,6 +671,8 @@ KW_COMPRESSION: 'COMPRESSION';
KW_PLAIN: 'PLAIN';
KW_EXTENDED: 'EXTENDED';
KW_MAIN: 'MAIN';
KW_SKIP_LOCKED: 'SKIP_LOCKED';
KW_BUFFER_USAGE_LIMIT: 'BUFFER_USAGE_LIMIT';
//
// IDENTIFIERS (4.1.1)

View File

@ -40,11 +40,11 @@ options {
tokenVocab = PostgreSQLLexer;
}
program: stmtmulti;
program: singleStmt* EOF;
plsqlroot: pl_function;
stmtmulti: (stmt SEMI?)*;
singleStmt: stmt SEMI?;
stmt:
altereventtrigstmt
@ -617,7 +617,8 @@ colconstraintelem:
KW_IDENTITY optparenthesizedseqoptlist?
| OPEN_PAREN a_expr CLOSE_PAREN KW_STORED
)
| KW_REFERENCES qualified_name opt_column_list? key_match? key_actions?;
| KW_REFERENCES qualified_name opt_column_list? key_match? key_actions?
| opt_collate;
nulls_distinct: KW_NULLS KW_NOT? KW_DISTINCT;
@ -1406,7 +1407,7 @@ defacl_privilege_target:
indexstmt:
KW_CREATE opt_unique? KW_INDEX opt_concurrently? opt_if_not_exists? opt_index_name? KW_ON relation_expr access_method_clause
? OPEN_PAREN index_params CLOSE_PAREN opt_include? opt_reloptions? opttablespace?
? OPEN_PAREN index_params CLOSE_PAREN opt_include? nulls_distinct? opt_reloptions? opttablespace?
where_clause?;
opt_unique: KW_UNIQUE;
@ -1981,7 +1982,7 @@ vacuumstmt:
analyzestmt:
analyze_keyword opt_verbose? opt_vacuum_relation_list?
| analyze_keyword OPEN_PAREN vac_analyze_option_list CLOSE_PAREN opt_vacuum_relation_list?;
| analyze_keyword OPEN_PAREN analyze_options_list CLOSE_PAREN opt_vacuum_relation_list?;
vac_analyze_option_list:
vac_analyze_option_elem (COMMA vac_analyze_option_elem)*;
@ -1997,8 +1998,16 @@ vac_analyze_option_arg: opt_boolean_or_string | numericonly;
opt_analyze: analyze_keyword;
analyze_options_list: analyze_option_elem (COMMA analyze_option_elem)*;
analyze_option_elem: opt_verbose | opt_skiplock | opt_buffer_usage_limit; // support on v12+
opt_verbose: KW_VERBOSE (KW_FALSE | KW_TRUE)?;
opt_skiplock: KW_SKIP_LOCKED (KW_FALSE | KW_TRUE)?;
opt_buffer_usage_limit: KW_BUFFER_USAGE_LIMIT (numericonly | sconst);
opt_full: KW_FULL;
opt_freeze: KW_FREEZE;
@ -2229,15 +2238,19 @@ sortby_list: sortby (COMMA sortby)*;
sortby:
column_expr_noparen (KW_USING qual_all_op | opt_asc_desc)? opt_nulls_order?;
select_limit:
select_limit: // https://www.postgresql.org/docs/16/sql-select.html#SQL-LIMIT
limit_clause offset_clause?
| offset_clause limit_clause?;
| offset_clause fetch_clause?
| fetch_clause offset_clause?
;
opt_select_limit: select_limit;
limit_clause:
KW_LIMIT select_limit_value (COMMA select_offset_value)?
| KW_FETCH first_or_next (
KW_LIMIT select_limit_value (COMMA select_offset_value)?;
fetch_clause:
KW_FETCH first_or_next (
select_fetch_first_value row_or_rows (KW_ONLY | KW_WITH KW_TIES)
| row_or_rows (KW_ONLY | KW_WITH KW_TIES)
);
@ -2263,7 +2276,7 @@ row_or_rows: KW_ROW | KW_ROWS;
first_or_next: KW_FIRST | KW_NEXT;
group_clause: KW_GROUP KW_BY group_by_list;
group_clause: KW_GROUP KW_BY (all_or_distinct)? group_by_list;
group_by_list: group_by_item (COMMA group_by_item)*;
@ -3110,6 +3123,7 @@ unreserved_keyword:
| KW_BACKWARD
| KW_BEFORE
| KW_BEGIN
| KW_BUFFER_USAGE_LIMIT
| KW_BY
| KW_CACHE
| KW_CALL
@ -3330,6 +3344,7 @@ unreserved_keyword:
| KW_SHOW
| KW_SIMPLE
| KW_SKIP
| KW_SKIP_LOCKED
| KW_SNAPSHOT
| KW_SQL
| KW_STABLE