fix: add missing expression predicate to impala parser(#225)

* fix(impala): add select supprt is true/false/unknown and support more SEMICOLON

* fix(impala): not use emptyStatement replace SEMICOLON

* test(impala): add select unit test sql and test splitSQLByStatement
This commit is contained in:
霜序
2023-11-30 19:56:07 +08:00
committed by GitHub
parent f93ffb93bf
commit 484c881583
14 changed files with 6957 additions and 6245 deletions

View File

@ -127,6 +127,8 @@ KW_INTERVAL : 'INTERVAL';
KW_INTERMEDIATE : 'INTERMEDIATE';
KW_INTO : 'INTO';
KW_INIT_FN : 'INIT_FN';
KW_IREGEXP : 'IREGEXP';
KW_ILIKE : 'ILIKE';
KW_INVALIDATE : 'INVALIDATE';
KW_IS : 'IS';
KW_JOIN : 'JOIN';
@ -230,6 +232,7 @@ KW_USER : 'USER';
KW_USING : 'USING';
KW_UPDATE_FN : 'UPDATE_FN';
KW_UPSERT : 'UPSERT';
KW_UNKNOWN : 'UNKNOWN';
KW_URI : 'URI';
KW_VALUE : 'VALUE';
KW_VALUES : 'VALUES';

View File

@ -19,31 +19,41 @@ options
tokenVocab=ImpalaSqlLexer;
}
program : (statement SEMICOLON?)* EOF;
program: statement EOF;
statement
: queryStatement
| useStatement
| createStatement
| alterStatement
| truncateTableStatement
| describeStatement
| computeStatement
| dropStatement
| grantStatement
| revokeStatement
| insertStatement
| deleteStatement
| updateStatement
| upsertStatement
| showStatement
| addCommentStatement
| explainStatement
| setStatement
| shutdownStatement
| invalidateMetaStatement
| loadDataStatement
| refreshStatement
: sqlStatements EOF
;
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?
;
useStatement: KW_USE databaseNamePath;
@ -671,9 +681,9 @@ predicate[ParserRuleContext value]
| KW_NOT? KW_BETWEEN lower=valueExpression KW_AND upper=valueExpression #between
| KW_NOT? KW_IN LPAREN expression (COMMA expression)* RPAREN #inList
| KW_NOT? KW_IN subQueryRelation #inSubquery
| KW_NOT? KW_LIKE pattern=valueExpression (KW_ESCAPE escape=valueExpression)? #like
| KW_REGEXP pattern=valueExpression #REGEXP
| KW_IS KW_NOT? KW_NULL #nullPredicate
| KW_NOT? (KW_LIKE | KW_ILIKE | KW_RLIKE) pattern=valueExpression (KW_ESCAPE escape=valueExpression)? #like
| (KW_REGEXP | KW_IREGEXP) pattern=valueExpression #REGEXP
| KW_IS KW_NOT? (KW_NULL | KW_UNKNOWN | KW_TRUE | KW_FALSE) #nullOrUnKnownOrBooleanPredicate
| KW_IS KW_NOT? KW_DISTINCT KW_FROM right=valueExpression #distinctFrom
;
@ -934,6 +944,7 @@ nonReserved
| KW_UNBOUNDED
| KW_USE
| KW_USER
| KW_UNKNOWN
| KW_VIEW
| KW_VIEWS
| KW_YEAR
@ -943,4 +954,6 @@ nonReserved
| KW_AVRO
| KW_SEQUENCEFILE
| KW_RCFILE
| KW_IREGEXP
| KW_ILIKE
;