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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
;

File diff suppressed because one or more lines are too long

View File

@ -102,172 +102,175 @@ KW_INTERVAL=101
KW_INTERMEDIATE=102
KW_INTO=103
KW_INIT_FN=104
KW_INVALIDATE=105
KW_IS=106
KW_JOIN=107
KW_KEY=108
KW_KUDU=109
KW_LAST=110
KW_LATERAL=111
KW_LEFT=112
KW_LIKE=113
KW_LIMIT=114
KW_LINES=115
KW_LOAD=116
KW_LOCALTIME=117
KW_LOCALTIMESTAMP=118
KW_METADATA=119
KW_MAP=120
KW_MINUTE=121
KW_MINUTES=122
KW_MONTH=123
KW_MONTHS=124
KW_MERGE_FN=125
KW_NFC=126
KW_NFD=127
KW_NFKC=128
KW_NFKD=129
KW_NORMALIZE=130
KW_NOT=131
KW_NULL=132
KW_NULLS=133
KW_OFFSET=134
KW_ON=135
KW_OPTION=136
KW_OR=137
KW_ORDER=138
KW_ORDINALITY=139
KW_OUTER=140
KW_OWNER=141
KW_OVER=142
KW_OVERWRITE=143
KW_PARTITION=144
KW_PARTITIONS=145
KW_PARQUET=146
KW_POSITION=147
KW_PRECEDING=148
KW_PRIMARY=149
KW_REPLICATION=150
KW_PRIVILEGES=151
KW_PROPERTIES=152
KW_RANGE=153
KW_RECOVER=154
KW_RENAME=155
KW_REPEATABLE=156
KW_REPLACE=157
KW_RESTRICT=158
KW_RETURNS=159
KW_REVOKE=160
KW_REFRESH=161
KW_REGEXP=162
KW_RLIKE=163
KW_RIGHT=164
KW_ROLE=165
KW_ROLES=166
KW_ROW=167
KW_ROWS=168
KW_SCHEMA=169
KW_SCHEMAS=170
KW_SECOND=171
KW_SECONDS=172
KW_SELECT=173
KW_SERDEPROPERTIES=174
KW_SET=175
KW_SEMI=176
KW_SERVER=177
KW_SHOW=178
KW_SHUTDOWN=179
KW_SOME=180
KW_STATS=181
KW_STRUCT=182
KW_STRAIGHT_JOIN=183
KW_SUBSTRING=184
KW_SYSTEM=185
KW_SYMBOL=186
KW_SERIALIZE_FN=187
KW_TABLE=188
KW_TABLES=189
KW_TABLESAMPLE=190
KW_TERMINATED=191
KW_THEN=192
KW_TO=193
KW_TRUE=194
KW_TRY_CAST=195
KW_TRUNCATE=196
KW_UNCACHED=197
KW_UESCAPE=198
KW_UNBOUNDED=199
KW_UNION=200
KW_UNNEST=201
KW_UNSET=202
KW_USE=203
KW_USER=204
KW_USING=205
KW_UPDATE_FN=206
KW_UPSERT=207
KW_URI=208
KW_VALUE=209
KW_VALUES=210
KW_VIEW=211
KW_VIEWS=212
KW_WHEN=213
KW_WHERE=214
KW_WITH=215
KW_YEAR=216
KW_YEARS=217
KW_TEXTFILE=218
KW_ORC=219
KW_AVRO=220
KW_SEQUENCEFILE=221
KW_RCFILE=222
KW_REFERENCES=223
KW_NOVALIDATE=224
KW_RELY=225
STATS_NUMDVS=226
STATS_NUMNULLS=227
STATS_AVGSIZE=228
STATS_MAXSIZE=229
EQ=230
NEQ=231
LT=232
LTE=233
GT=234
GTE=235
PLUS=236
MINUS=237
ASTERISK=238
SLASH=239
PERCENT=240
CONCAT=241
DOT=242
SEMICOLON=243
COMMA=244
COLON=245
LPAREN=246
RPAREN=247
LSQUARE=248
RSQUARE=249
LCURLY=250
RCURLY=251
BITWISEOR=252
QUESTION=253
RIGHT_ARROW=254
STRING=255
UNICODE_STRING=256
BINARY_LITERAL=257
INTEGER_VALUE=258
DECIMAL_VALUE=259
DOUBLE_VALUE=260
IDENTIFIER=261
DIGIT_IDENTIFIER=262
QUOTED_IDENTIFIER=263
BACKQUOTED_IDENTIFIER=264
TIME_WITH_TIME_ZONE=265
TIMESTAMP_WITH_TIME_ZONE=266
DOUBLE_PRECISION=267
SIMPLE_COMMENT=268
BRACKETED_COMMENT=269
WS=270
KW_IREGEXP=105
KW_ILIKE=106
KW_INVALIDATE=107
KW_IS=108
KW_JOIN=109
KW_KEY=110
KW_KUDU=111
KW_LAST=112
KW_LATERAL=113
KW_LEFT=114
KW_LIKE=115
KW_LIMIT=116
KW_LINES=117
KW_LOAD=118
KW_LOCALTIME=119
KW_LOCALTIMESTAMP=120
KW_METADATA=121
KW_MAP=122
KW_MINUTE=123
KW_MINUTES=124
KW_MONTH=125
KW_MONTHS=126
KW_MERGE_FN=127
KW_NFC=128
KW_NFD=129
KW_NFKC=130
KW_NFKD=131
KW_NORMALIZE=132
KW_NOT=133
KW_NULL=134
KW_NULLS=135
KW_OFFSET=136
KW_ON=137
KW_OPTION=138
KW_OR=139
KW_ORDER=140
KW_ORDINALITY=141
KW_OUTER=142
KW_OWNER=143
KW_OVER=144
KW_OVERWRITE=145
KW_PARTITION=146
KW_PARTITIONS=147
KW_PARQUET=148
KW_POSITION=149
KW_PRECEDING=150
KW_PRIMARY=151
KW_REPLICATION=152
KW_PRIVILEGES=153
KW_PROPERTIES=154
KW_RANGE=155
KW_RECOVER=156
KW_RENAME=157
KW_REPEATABLE=158
KW_REPLACE=159
KW_RESTRICT=160
KW_RETURNS=161
KW_REVOKE=162
KW_REFRESH=163
KW_REGEXP=164
KW_RLIKE=165
KW_RIGHT=166
KW_ROLE=167
KW_ROLES=168
KW_ROW=169
KW_ROWS=170
KW_SCHEMA=171
KW_SCHEMAS=172
KW_SECOND=173
KW_SECONDS=174
KW_SELECT=175
KW_SERDEPROPERTIES=176
KW_SET=177
KW_SEMI=178
KW_SERVER=179
KW_SHOW=180
KW_SHUTDOWN=181
KW_SOME=182
KW_STATS=183
KW_STRUCT=184
KW_STRAIGHT_JOIN=185
KW_SUBSTRING=186
KW_SYSTEM=187
KW_SYMBOL=188
KW_SERIALIZE_FN=189
KW_TABLE=190
KW_TABLES=191
KW_TABLESAMPLE=192
KW_TERMINATED=193
KW_THEN=194
KW_TO=195
KW_TRUE=196
KW_TRY_CAST=197
KW_TRUNCATE=198
KW_UNCACHED=199
KW_UESCAPE=200
KW_UNBOUNDED=201
KW_UNION=202
KW_UNNEST=203
KW_UNSET=204
KW_USE=205
KW_USER=206
KW_USING=207
KW_UPDATE_FN=208
KW_UPSERT=209
KW_UNKNOWN=210
KW_URI=211
KW_VALUE=212
KW_VALUES=213
KW_VIEW=214
KW_VIEWS=215
KW_WHEN=216
KW_WHERE=217
KW_WITH=218
KW_YEAR=219
KW_YEARS=220
KW_TEXTFILE=221
KW_ORC=222
KW_AVRO=223
KW_SEQUENCEFILE=224
KW_RCFILE=225
KW_REFERENCES=226
KW_NOVALIDATE=227
KW_RELY=228
STATS_NUMDVS=229
STATS_NUMNULLS=230
STATS_AVGSIZE=231
STATS_MAXSIZE=232
EQ=233
NEQ=234
LT=235
LTE=236
GT=237
GTE=238
PLUS=239
MINUS=240
ASTERISK=241
SLASH=242
PERCENT=243
CONCAT=244
DOT=245
SEMICOLON=246
COMMA=247
COLON=248
LPAREN=249
RPAREN=250
LSQUARE=251
RSQUARE=252
LCURLY=253
RCURLY=254
BITWISEOR=255
QUESTION=256
RIGHT_ARROW=257
STRING=258
UNICODE_STRING=259
BINARY_LITERAL=260
INTEGER_VALUE=261
DECIMAL_VALUE=262
DOUBLE_VALUE=263
IDENTIFIER=264
DIGIT_IDENTIFIER=265
QUOTED_IDENTIFIER=266
BACKQUOTED_IDENTIFIER=267
TIME_WITH_TIME_ZONE=268
TIMESTAMP_WITH_TIME_ZONE=269
DOUBLE_PRECISION=270
SIMPLE_COMMENT=271
BRACKETED_COMMENT=272
WS=273
'ADD'=1
'ALL'=2
'ANALYTIC'=3
@ -372,152 +375,155 @@ WS=270
'INTERMEDIATE'=102
'INTO'=103
'INIT_FN'=104
'INVALIDATE'=105
'IS'=106
'JOIN'=107
'KEY'=108
'KUDU'=109
'LAST'=110
'LATERAL'=111
'LEFT'=112
'LIKE'=113
'LIMIT'=114
'LINES'=115
'LOAD'=116
'LOCALTIME'=117
'LOCALTIMESTAMP'=118
'METADATA'=119
'MAP'=120
'MINUTE'=121
'MINUTES'=122
'MONTH'=123
'MONTHS'=124
'MERGE_FN'=125
'NFC'=126
'NFD'=127
'NFKC'=128
'NFKD'=129
'NORMALIZE'=130
'NOT'=131
'NULL'=132
'NULLS'=133
'OFFSET'=134
'ON'=135
'OPTION'=136
'OR'=137
'ORDER'=138
'ORDINALITY'=139
'OUTER'=140
'OWNER'=141
'OVER'=142
'OVERWRITE'=143
'PARTITION'=144
'PARTITIONS'=145
'PARQUET'=146
'POSITION'=147
'PRECEDING'=148
'PRIMARY'=149
'REPLICATION'=150
'PRIVILEGES'=151
'PROPERTIES'=152
'RANGE'=153
'RECOVER'=154
'RENAME'=155
'REPEATABLE'=156
'REPLACE'=157
'RESTRICT'=158
'RETURNS'=159
'REVOKE'=160
'REFRESH'=161
'REGEXP'=162
'RLIKE'=163
'RIGHT'=164
'ROLE'=165
'ROLES'=166
'ROW'=167
'ROWS'=168
'SCHEMA'=169
'SCHEMAS'=170
'SECOND'=171
'SECONDS'=172
'SELECT'=173
'SERDEPROPERTIES'=174
'SET'=175
'SEMI'=176
'SERVER'=177
'SHOW'=178
'SHUTDOWN'=179
'SOME'=180
'STATS'=181
'STRUCT'=182
'STRAIGHT_JOIN'=183
'SUBSTRING'=184
'SYSTEM'=185
'SYMBOL'=186
'SERIALIZE_FN'=187
'TABLE'=188
'TABLES'=189
'TABLESAMPLE'=190
'TERMINATED '=191
'THEN'=192
'TO'=193
'TRUE'=194
'TRY_CAST'=195
'TRUNCATE'=196
'UNCACHED'=197
'UESCAPE'=198
'UNBOUNDED'=199
'UNION'=200
'UNNEST'=201
'UNSET'=202
'USE'=203
'USER'=204
'USING'=205
'UPDATE_FN'=206
'UPSERT'=207
'URI'=208
'VALUE'=209
'VALUES'=210
'VIEW'=211
'VIEWS'=212
'WHEN'=213
'WHERE'=214
'WITH'=215
'YEAR'=216
'YEARS'=217
'TEXTFILE'=218
'ORC'=219
'AVRO'=220
'SEQUENCEFILE'=221
'RCFILE'=222
'REFERENCES'=223
'NOVALIDATE'=224
'RELY'=225
'\'NUMDVS\''=226
'\'NUMNULLS\''=227
'\'AVGSIZE\''=228
'\'MAXSIZE\''=229
'='=230
'<'=232
'<='=233
'>'=234
'>='=235
'+'=236
'-'=237
'*'=238
'/'=239
'%'=240
'||'=241
'.'=242
';'=243
','=244
':'=245
'('=246
')'=247
'['=248
']'=249
'{'=250
'}'=251
'|'=252
'?'=253
'->'=254
'IREGEXP'=105
'ILIKE'=106
'INVALIDATE'=107
'IS'=108
'JOIN'=109
'KEY'=110
'KUDU'=111
'LAST'=112
'LATERAL'=113
'LEFT'=114
'LIKE'=115
'LIMIT'=116
'LINES'=117
'LOAD'=118
'LOCALTIME'=119
'LOCALTIMESTAMP'=120
'METADATA'=121
'MAP'=122
'MINUTE'=123
'MINUTES'=124
'MONTH'=125
'MONTHS'=126
'MERGE_FN'=127
'NFC'=128
'NFD'=129
'NFKC'=130
'NFKD'=131
'NORMALIZE'=132
'NOT'=133
'NULL'=134
'NULLS'=135
'OFFSET'=136
'ON'=137
'OPTION'=138
'OR'=139
'ORDER'=140
'ORDINALITY'=141
'OUTER'=142
'OWNER'=143
'OVER'=144
'OVERWRITE'=145
'PARTITION'=146
'PARTITIONS'=147
'PARQUET'=148
'POSITION'=149
'PRECEDING'=150
'PRIMARY'=151
'REPLICATION'=152
'PRIVILEGES'=153
'PROPERTIES'=154
'RANGE'=155
'RECOVER'=156
'RENAME'=157
'REPEATABLE'=158
'REPLACE'=159
'RESTRICT'=160
'RETURNS'=161
'REVOKE'=162
'REFRESH'=163
'REGEXP'=164
'RLIKE'=165
'RIGHT'=166
'ROLE'=167
'ROLES'=168
'ROW'=169
'ROWS'=170
'SCHEMA'=171
'SCHEMAS'=172
'SECOND'=173
'SECONDS'=174
'SELECT'=175
'SERDEPROPERTIES'=176
'SET'=177
'SEMI'=178
'SERVER'=179
'SHOW'=180
'SHUTDOWN'=181
'SOME'=182
'STATS'=183
'STRUCT'=184
'STRAIGHT_JOIN'=185
'SUBSTRING'=186
'SYSTEM'=187
'SYMBOL'=188
'SERIALIZE_FN'=189
'TABLE'=190
'TABLES'=191
'TABLESAMPLE'=192
'TERMINATED '=193
'THEN'=194
'TO'=195
'TRUE'=196
'TRY_CAST'=197
'TRUNCATE'=198
'UNCACHED'=199
'UESCAPE'=200
'UNBOUNDED'=201
'UNION'=202
'UNNEST'=203
'UNSET'=204
'USE'=205
'USER'=206
'USING'=207
'UPDATE_FN'=208
'UPSERT'=209
'UNKNOWN'=210
'URI'=211
'VALUE'=212
'VALUES'=213
'VIEW'=214
'VIEWS'=215
'WHEN'=216
'WHERE'=217
'WITH'=218
'YEAR'=219
'YEARS'=220
'TEXTFILE'=221
'ORC'=222
'AVRO'=223
'SEQUENCEFILE'=224
'RCFILE'=225
'REFERENCES'=226
'NOVALIDATE'=227
'RELY'=228
'\'NUMDVS\''=229
'\'NUMNULLS\''=230
'\'AVGSIZE\''=231
'\'MAXSIZE\''=232
'='=233
'<'=235
'<='=236
'>'=237
'>='=238
'+'=239
'-'=240
'*'=241
'/'=242
'%'=243
'||'=244
'.'=245
';'=246
','=247
':'=248
'('=249
')'=250
'['=251
']'=252
'{'=253
'}'=254
'|'=255
'?'=256
'->'=257

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -102,172 +102,175 @@ KW_INTERVAL=101
KW_INTERMEDIATE=102
KW_INTO=103
KW_INIT_FN=104
KW_INVALIDATE=105
KW_IS=106
KW_JOIN=107
KW_KEY=108
KW_KUDU=109
KW_LAST=110
KW_LATERAL=111
KW_LEFT=112
KW_LIKE=113
KW_LIMIT=114
KW_LINES=115
KW_LOAD=116
KW_LOCALTIME=117
KW_LOCALTIMESTAMP=118
KW_METADATA=119
KW_MAP=120
KW_MINUTE=121
KW_MINUTES=122
KW_MONTH=123
KW_MONTHS=124
KW_MERGE_FN=125
KW_NFC=126
KW_NFD=127
KW_NFKC=128
KW_NFKD=129
KW_NORMALIZE=130
KW_NOT=131
KW_NULL=132
KW_NULLS=133
KW_OFFSET=134
KW_ON=135
KW_OPTION=136
KW_OR=137
KW_ORDER=138
KW_ORDINALITY=139
KW_OUTER=140
KW_OWNER=141
KW_OVER=142
KW_OVERWRITE=143
KW_PARTITION=144
KW_PARTITIONS=145
KW_PARQUET=146
KW_POSITION=147
KW_PRECEDING=148
KW_PRIMARY=149
KW_REPLICATION=150
KW_PRIVILEGES=151
KW_PROPERTIES=152
KW_RANGE=153
KW_RECOVER=154
KW_RENAME=155
KW_REPEATABLE=156
KW_REPLACE=157
KW_RESTRICT=158
KW_RETURNS=159
KW_REVOKE=160
KW_REFRESH=161
KW_REGEXP=162
KW_RLIKE=163
KW_RIGHT=164
KW_ROLE=165
KW_ROLES=166
KW_ROW=167
KW_ROWS=168
KW_SCHEMA=169
KW_SCHEMAS=170
KW_SECOND=171
KW_SECONDS=172
KW_SELECT=173
KW_SERDEPROPERTIES=174
KW_SET=175
KW_SEMI=176
KW_SERVER=177
KW_SHOW=178
KW_SHUTDOWN=179
KW_SOME=180
KW_STATS=181
KW_STRUCT=182
KW_STRAIGHT_JOIN=183
KW_SUBSTRING=184
KW_SYSTEM=185
KW_SYMBOL=186
KW_SERIALIZE_FN=187
KW_TABLE=188
KW_TABLES=189
KW_TABLESAMPLE=190
KW_TERMINATED=191
KW_THEN=192
KW_TO=193
KW_TRUE=194
KW_TRY_CAST=195
KW_TRUNCATE=196
KW_UNCACHED=197
KW_UESCAPE=198
KW_UNBOUNDED=199
KW_UNION=200
KW_UNNEST=201
KW_UNSET=202
KW_USE=203
KW_USER=204
KW_USING=205
KW_UPDATE_FN=206
KW_UPSERT=207
KW_URI=208
KW_VALUE=209
KW_VALUES=210
KW_VIEW=211
KW_VIEWS=212
KW_WHEN=213
KW_WHERE=214
KW_WITH=215
KW_YEAR=216
KW_YEARS=217
KW_TEXTFILE=218
KW_ORC=219
KW_AVRO=220
KW_SEQUENCEFILE=221
KW_RCFILE=222
KW_REFERENCES=223
KW_NOVALIDATE=224
KW_RELY=225
STATS_NUMDVS=226
STATS_NUMNULLS=227
STATS_AVGSIZE=228
STATS_MAXSIZE=229
EQ=230
NEQ=231
LT=232
LTE=233
GT=234
GTE=235
PLUS=236
MINUS=237
ASTERISK=238
SLASH=239
PERCENT=240
CONCAT=241
DOT=242
SEMICOLON=243
COMMA=244
COLON=245
LPAREN=246
RPAREN=247
LSQUARE=248
RSQUARE=249
LCURLY=250
RCURLY=251
BITWISEOR=252
QUESTION=253
RIGHT_ARROW=254
STRING=255
UNICODE_STRING=256
BINARY_LITERAL=257
INTEGER_VALUE=258
DECIMAL_VALUE=259
DOUBLE_VALUE=260
IDENTIFIER=261
DIGIT_IDENTIFIER=262
QUOTED_IDENTIFIER=263
BACKQUOTED_IDENTIFIER=264
TIME_WITH_TIME_ZONE=265
TIMESTAMP_WITH_TIME_ZONE=266
DOUBLE_PRECISION=267
SIMPLE_COMMENT=268
BRACKETED_COMMENT=269
WS=270
KW_IREGEXP=105
KW_ILIKE=106
KW_INVALIDATE=107
KW_IS=108
KW_JOIN=109
KW_KEY=110
KW_KUDU=111
KW_LAST=112
KW_LATERAL=113
KW_LEFT=114
KW_LIKE=115
KW_LIMIT=116
KW_LINES=117
KW_LOAD=118
KW_LOCALTIME=119
KW_LOCALTIMESTAMP=120
KW_METADATA=121
KW_MAP=122
KW_MINUTE=123
KW_MINUTES=124
KW_MONTH=125
KW_MONTHS=126
KW_MERGE_FN=127
KW_NFC=128
KW_NFD=129
KW_NFKC=130
KW_NFKD=131
KW_NORMALIZE=132
KW_NOT=133
KW_NULL=134
KW_NULLS=135
KW_OFFSET=136
KW_ON=137
KW_OPTION=138
KW_OR=139
KW_ORDER=140
KW_ORDINALITY=141
KW_OUTER=142
KW_OWNER=143
KW_OVER=144
KW_OVERWRITE=145
KW_PARTITION=146
KW_PARTITIONS=147
KW_PARQUET=148
KW_POSITION=149
KW_PRECEDING=150
KW_PRIMARY=151
KW_REPLICATION=152
KW_PRIVILEGES=153
KW_PROPERTIES=154
KW_RANGE=155
KW_RECOVER=156
KW_RENAME=157
KW_REPEATABLE=158
KW_REPLACE=159
KW_RESTRICT=160
KW_RETURNS=161
KW_REVOKE=162
KW_REFRESH=163
KW_REGEXP=164
KW_RLIKE=165
KW_RIGHT=166
KW_ROLE=167
KW_ROLES=168
KW_ROW=169
KW_ROWS=170
KW_SCHEMA=171
KW_SCHEMAS=172
KW_SECOND=173
KW_SECONDS=174
KW_SELECT=175
KW_SERDEPROPERTIES=176
KW_SET=177
KW_SEMI=178
KW_SERVER=179
KW_SHOW=180
KW_SHUTDOWN=181
KW_SOME=182
KW_STATS=183
KW_STRUCT=184
KW_STRAIGHT_JOIN=185
KW_SUBSTRING=186
KW_SYSTEM=187
KW_SYMBOL=188
KW_SERIALIZE_FN=189
KW_TABLE=190
KW_TABLES=191
KW_TABLESAMPLE=192
KW_TERMINATED=193
KW_THEN=194
KW_TO=195
KW_TRUE=196
KW_TRY_CAST=197
KW_TRUNCATE=198
KW_UNCACHED=199
KW_UESCAPE=200
KW_UNBOUNDED=201
KW_UNION=202
KW_UNNEST=203
KW_UNSET=204
KW_USE=205
KW_USER=206
KW_USING=207
KW_UPDATE_FN=208
KW_UPSERT=209
KW_UNKNOWN=210
KW_URI=211
KW_VALUE=212
KW_VALUES=213
KW_VIEW=214
KW_VIEWS=215
KW_WHEN=216
KW_WHERE=217
KW_WITH=218
KW_YEAR=219
KW_YEARS=220
KW_TEXTFILE=221
KW_ORC=222
KW_AVRO=223
KW_SEQUENCEFILE=224
KW_RCFILE=225
KW_REFERENCES=226
KW_NOVALIDATE=227
KW_RELY=228
STATS_NUMDVS=229
STATS_NUMNULLS=230
STATS_AVGSIZE=231
STATS_MAXSIZE=232
EQ=233
NEQ=234
LT=235
LTE=236
GT=237
GTE=238
PLUS=239
MINUS=240
ASTERISK=241
SLASH=242
PERCENT=243
CONCAT=244
DOT=245
SEMICOLON=246
COMMA=247
COLON=248
LPAREN=249
RPAREN=250
LSQUARE=251
RSQUARE=252
LCURLY=253
RCURLY=254
BITWISEOR=255
QUESTION=256
RIGHT_ARROW=257
STRING=258
UNICODE_STRING=259
BINARY_LITERAL=260
INTEGER_VALUE=261
DECIMAL_VALUE=262
DOUBLE_VALUE=263
IDENTIFIER=264
DIGIT_IDENTIFIER=265
QUOTED_IDENTIFIER=266
BACKQUOTED_IDENTIFIER=267
TIME_WITH_TIME_ZONE=268
TIMESTAMP_WITH_TIME_ZONE=269
DOUBLE_PRECISION=270
SIMPLE_COMMENT=271
BRACKETED_COMMENT=272
WS=273
'ADD'=1
'ALL'=2
'ANALYTIC'=3
@ -372,152 +375,155 @@ WS=270
'INTERMEDIATE'=102
'INTO'=103
'INIT_FN'=104
'INVALIDATE'=105
'IS'=106
'JOIN'=107
'KEY'=108
'KUDU'=109
'LAST'=110
'LATERAL'=111
'LEFT'=112
'LIKE'=113
'LIMIT'=114
'LINES'=115
'LOAD'=116
'LOCALTIME'=117
'LOCALTIMESTAMP'=118
'METADATA'=119
'MAP'=120
'MINUTE'=121
'MINUTES'=122
'MONTH'=123
'MONTHS'=124
'MERGE_FN'=125
'NFC'=126
'NFD'=127
'NFKC'=128
'NFKD'=129
'NORMALIZE'=130
'NOT'=131
'NULL'=132
'NULLS'=133
'OFFSET'=134
'ON'=135
'OPTION'=136
'OR'=137
'ORDER'=138
'ORDINALITY'=139
'OUTER'=140
'OWNER'=141
'OVER'=142
'OVERWRITE'=143
'PARTITION'=144
'PARTITIONS'=145
'PARQUET'=146
'POSITION'=147
'PRECEDING'=148
'PRIMARY'=149
'REPLICATION'=150
'PRIVILEGES'=151
'PROPERTIES'=152
'RANGE'=153
'RECOVER'=154
'RENAME'=155
'REPEATABLE'=156
'REPLACE'=157
'RESTRICT'=158
'RETURNS'=159
'REVOKE'=160
'REFRESH'=161
'REGEXP'=162
'RLIKE'=163
'RIGHT'=164
'ROLE'=165
'ROLES'=166
'ROW'=167
'ROWS'=168
'SCHEMA'=169
'SCHEMAS'=170
'SECOND'=171
'SECONDS'=172
'SELECT'=173
'SERDEPROPERTIES'=174
'SET'=175
'SEMI'=176
'SERVER'=177
'SHOW'=178
'SHUTDOWN'=179
'SOME'=180
'STATS'=181
'STRUCT'=182
'STRAIGHT_JOIN'=183
'SUBSTRING'=184
'SYSTEM'=185
'SYMBOL'=186
'SERIALIZE_FN'=187
'TABLE'=188
'TABLES'=189
'TABLESAMPLE'=190
'TERMINATED '=191
'THEN'=192
'TO'=193
'TRUE'=194
'TRY_CAST'=195
'TRUNCATE'=196
'UNCACHED'=197
'UESCAPE'=198
'UNBOUNDED'=199
'UNION'=200
'UNNEST'=201
'UNSET'=202
'USE'=203
'USER'=204
'USING'=205
'UPDATE_FN'=206
'UPSERT'=207
'URI'=208
'VALUE'=209
'VALUES'=210
'VIEW'=211
'VIEWS'=212
'WHEN'=213
'WHERE'=214
'WITH'=215
'YEAR'=216
'YEARS'=217
'TEXTFILE'=218
'ORC'=219
'AVRO'=220
'SEQUENCEFILE'=221
'RCFILE'=222
'REFERENCES'=223
'NOVALIDATE'=224
'RELY'=225
'\'NUMDVS\''=226
'\'NUMNULLS\''=227
'\'AVGSIZE\''=228
'\'MAXSIZE\''=229
'='=230
'<'=232
'<='=233
'>'=234
'>='=235
'+'=236
'-'=237
'*'=238
'/'=239
'%'=240
'||'=241
'.'=242
';'=243
','=244
':'=245
'('=246
')'=247
'['=248
']'=249
'{'=250
'}'=251
'|'=252
'?'=253
'->'=254
'IREGEXP'=105
'ILIKE'=106
'INVALIDATE'=107
'IS'=108
'JOIN'=109
'KEY'=110
'KUDU'=111
'LAST'=112
'LATERAL'=113
'LEFT'=114
'LIKE'=115
'LIMIT'=116
'LINES'=117
'LOAD'=118
'LOCALTIME'=119
'LOCALTIMESTAMP'=120
'METADATA'=121
'MAP'=122
'MINUTE'=123
'MINUTES'=124
'MONTH'=125
'MONTHS'=126
'MERGE_FN'=127
'NFC'=128
'NFD'=129
'NFKC'=130
'NFKD'=131
'NORMALIZE'=132
'NOT'=133
'NULL'=134
'NULLS'=135
'OFFSET'=136
'ON'=137
'OPTION'=138
'OR'=139
'ORDER'=140
'ORDINALITY'=141
'OUTER'=142
'OWNER'=143
'OVER'=144
'OVERWRITE'=145
'PARTITION'=146
'PARTITIONS'=147
'PARQUET'=148
'POSITION'=149
'PRECEDING'=150
'PRIMARY'=151
'REPLICATION'=152
'PRIVILEGES'=153
'PROPERTIES'=154
'RANGE'=155
'RECOVER'=156
'RENAME'=157
'REPEATABLE'=158
'REPLACE'=159
'RESTRICT'=160
'RETURNS'=161
'REVOKE'=162
'REFRESH'=163
'REGEXP'=164
'RLIKE'=165
'RIGHT'=166
'ROLE'=167
'ROLES'=168
'ROW'=169
'ROWS'=170
'SCHEMA'=171
'SCHEMAS'=172
'SECOND'=173
'SECONDS'=174
'SELECT'=175
'SERDEPROPERTIES'=176
'SET'=177
'SEMI'=178
'SERVER'=179
'SHOW'=180
'SHUTDOWN'=181
'SOME'=182
'STATS'=183
'STRUCT'=184
'STRAIGHT_JOIN'=185
'SUBSTRING'=186
'SYSTEM'=187
'SYMBOL'=188
'SERIALIZE_FN'=189
'TABLE'=190
'TABLES'=191
'TABLESAMPLE'=192
'TERMINATED '=193
'THEN'=194
'TO'=195
'TRUE'=196
'TRY_CAST'=197
'TRUNCATE'=198
'UNCACHED'=199
'UESCAPE'=200
'UNBOUNDED'=201
'UNION'=202
'UNNEST'=203
'UNSET'=204
'USE'=205
'USER'=206
'USING'=207
'UPDATE_FN'=208
'UPSERT'=209
'UNKNOWN'=210
'URI'=211
'VALUE'=212
'VALUES'=213
'VIEW'=214
'VIEWS'=215
'WHEN'=216
'WHERE'=217
'WITH'=218
'YEAR'=219
'YEARS'=220
'TEXTFILE'=221
'ORC'=222
'AVRO'=223
'SEQUENCEFILE'=224
'RCFILE'=225
'REFERENCES'=226
'NOVALIDATE'=227
'RELY'=228
'\'NUMDVS\''=229
'\'NUMNULLS\''=230
'\'AVGSIZE\''=231
'\'MAXSIZE\''=232
'='=233
'<'=235
'<='=236
'>'=237
'>='=238
'+'=239
'-'=240
'*'=241
'/'=242
'%'=243
'||'=244
'.'=245
';'=246
','=247
':'=248
'('=249
')'=250
'['=251
']'=252
'{'=253
'}'=254
'|'=255
'?'=256
'->'=257

File diff suppressed because one or more lines are too long

View File

@ -12,7 +12,7 @@ import { InListContext } from "./ImpalaSqlParser";
import { InSubqueryContext } from "./ImpalaSqlParser";
import { LikeContext } from "./ImpalaSqlParser";
import { REGEXPContext } from "./ImpalaSqlParser";
import { NullPredicateContext } from "./ImpalaSqlParser";
import { NullOrUnKnownOrBooleanPredicateContext } from "./ImpalaSqlParser";
import { DistinctFromContext } from "./ImpalaSqlParser";
import { DecimalLiteralContext } from "./ImpalaSqlParser";
import { DoubleLiteralContext } from "./ImpalaSqlParser";
@ -78,6 +78,9 @@ import { LogicalNotContext } from "./ImpalaSqlParser";
import { LogicalBinaryContext } from "./ImpalaSqlParser";
import { ProgramContext } from "./ImpalaSqlParser";
import { StatementContext } from "./ImpalaSqlParser";
import { SqlStatementsContext } from "./ImpalaSqlParser";
import { EmptyStatementContext } from "./ImpalaSqlParser";
import { SqlStatementContext } from "./ImpalaSqlParser";
import { UseStatementContext } from "./ImpalaSqlParser";
import { CreateStatementContext } from "./ImpalaSqlParser";
import { CreateTableSelectContext } from "./ImpalaSqlParser";
@ -381,17 +384,17 @@ export interface ImpalaSqlParserListener extends ParseTreeListener {
exitREGEXP?: (ctx: REGEXPContext) => void;
/**
* Enter a parse tree produced by the `nullPredicate`
* Enter a parse tree produced by the `nullOrUnKnownOrBooleanPredicate`
* labeled alternative in `ImpalaSqlParser.predicate`.
* @param ctx the parse tree
*/
enterNullPredicate?: (ctx: NullPredicateContext) => void;
enterNullOrUnKnownOrBooleanPredicate?: (ctx: NullOrUnKnownOrBooleanPredicateContext) => void;
/**
* Exit a parse tree produced by the `nullPredicate`
* Exit a parse tree produced by the `nullOrUnKnownOrBooleanPredicate`
* labeled alternative in `ImpalaSqlParser.predicate`.
* @param ctx the parse tree
*/
exitNullPredicate?: (ctx: NullPredicateContext) => void;
exitNullOrUnKnownOrBooleanPredicate?: (ctx: NullOrUnKnownOrBooleanPredicateContext) => void;
/**
* Enter a parse tree produced by the `distinctFrom`
@ -1234,6 +1237,39 @@ export interface ImpalaSqlParserListener extends ParseTreeListener {
*/
exitStatement?: (ctx: StatementContext) => void;
/**
* Enter a parse tree produced by `ImpalaSqlParser.sqlStatements`.
* @param ctx the parse tree
*/
enterSqlStatements?: (ctx: SqlStatementsContext) => void;
/**
* Exit a parse tree produced by `ImpalaSqlParser.sqlStatements`.
* @param ctx the parse tree
*/
exitSqlStatements?: (ctx: SqlStatementsContext) => void;
/**
* Enter a parse tree produced by `ImpalaSqlParser.emptyStatement`.
* @param ctx the parse tree
*/
enterEmptyStatement?: (ctx: EmptyStatementContext) => void;
/**
* Exit a parse tree produced by `ImpalaSqlParser.emptyStatement`.
* @param ctx the parse tree
*/
exitEmptyStatement?: (ctx: EmptyStatementContext) => void;
/**
* Enter a parse tree produced by `ImpalaSqlParser.sqlStatement`.
* @param ctx the parse tree
*/
enterSqlStatement?: (ctx: SqlStatementContext) => void;
/**
* Exit a parse tree produced by `ImpalaSqlParser.sqlStatement`.
* @param ctx the parse tree
*/
exitSqlStatement?: (ctx: SqlStatementContext) => void;
/**
* Enter a parse tree produced by `ImpalaSqlParser.useStatement`.
* @param ctx the parse tree

View File

@ -12,7 +12,7 @@ import { InListContext } from "./ImpalaSqlParser";
import { InSubqueryContext } from "./ImpalaSqlParser";
import { LikeContext } from "./ImpalaSqlParser";
import { REGEXPContext } from "./ImpalaSqlParser";
import { NullPredicateContext } from "./ImpalaSqlParser";
import { NullOrUnKnownOrBooleanPredicateContext } from "./ImpalaSqlParser";
import { DistinctFromContext } from "./ImpalaSqlParser";
import { DecimalLiteralContext } from "./ImpalaSqlParser";
import { DoubleLiteralContext } from "./ImpalaSqlParser";
@ -78,6 +78,9 @@ import { LogicalNotContext } from "./ImpalaSqlParser";
import { LogicalBinaryContext } from "./ImpalaSqlParser";
import { ProgramContext } from "./ImpalaSqlParser";
import { StatementContext } from "./ImpalaSqlParser";
import { SqlStatementsContext } from "./ImpalaSqlParser";
import { EmptyStatementContext } from "./ImpalaSqlParser";
import { SqlStatementContext } from "./ImpalaSqlParser";
import { UseStatementContext } from "./ImpalaSqlParser";
import { CreateStatementContext } from "./ImpalaSqlParser";
import { CreateTableSelectContext } from "./ImpalaSqlParser";
@ -339,12 +342,12 @@ export interface ImpalaSqlParserVisitor<Result> extends ParseTreeVisitor<Result>
visitREGEXP?: (ctx: REGEXPContext) => Result;
/**
* Visit a parse tree produced by the `nullPredicate`
* Visit a parse tree produced by the `nullOrUnKnownOrBooleanPredicate`
* labeled alternative in `ImpalaSqlParser.predicate`.
* @param ctx the parse tree
* @return the visitor result
*/
visitNullPredicate?: (ctx: NullPredicateContext) => Result;
visitNullOrUnKnownOrBooleanPredicate?: (ctx: NullOrUnKnownOrBooleanPredicateContext) => Result;
/**
* Visit a parse tree produced by the `distinctFrom`
@ -864,6 +867,27 @@ export interface ImpalaSqlParserVisitor<Result> extends ParseTreeVisitor<Result>
*/
visitStatement?: (ctx: StatementContext) => Result;
/**
* Visit a parse tree produced by `ImpalaSqlParser.sqlStatements`.
* @param ctx the parse tree
* @return the visitor result
*/
visitSqlStatements?: (ctx: SqlStatementsContext) => Result;
/**
* Visit a parse tree produced by `ImpalaSqlParser.emptyStatement`.
* @param ctx the parse tree
* @return the visitor result
*/
visitEmptyStatement?: (ctx: EmptyStatementContext) => Result;
/**
* Visit a parse tree produced by `ImpalaSqlParser.sqlStatement`.
* @param ctx the parse tree
* @return the visitor result
*/
visitSqlStatement?: (ctx: SqlStatementContext) => Result;
/**
* Visit a parse tree produced by `ImpalaSqlParser.useStatement`.
* @param ctx the parse tree

View File

@ -1,7 +1,11 @@
import { Token } from 'antlr4ts';
import { CandidatesCollection } from 'antlr4-c3';
import { ImpalaSqlLexer } from '../lib/impala/ImpalaSqlLexer';
import { ImpalaSqlParser, ProgramContext, StatementContext } from '../lib/impala/ImpalaSqlParser';
import {
ImpalaSqlParser,
ProgramContext,
SqlStatementContext,
} from '../lib/impala/ImpalaSqlParser';
import BasicParser from './common/basicParser';
import { ImpalaSqlParserListener } from '../lib/impala/ImpalaSqlParserListener';
import { SyntaxContextType, Suggestions, SyntaxSuggestion } from './common/basic-parser-types';
@ -125,13 +129,13 @@ export default class ImpalaSQL extends BasicParser<
}
export class ImpalaSqlSplitListener implements ImpalaSqlParserListener {
private _statementContext: StatementContext[] = [];
private _statementContext: SqlStatementContext[] = [];
exitStatement = (ctx: StatementContext) => {
exitSqlStatement = (ctx: SqlStatementContext) => {
this._statementContext.push(ctx);
};
enterStatement = (ctx: StatementContext) => {};
enterSqlStatement = (ctx: SqlStatementContext) => {};
get statementsContext() {
return this._statementContext;

View File

@ -9,7 +9,7 @@ describe('impala SQL Listener Tests', () => {
const parseTree = parser.parse(sql);
test('Listener enterTableName', async () => {
test('Listener enterTableNamePath', async () => {
let result = '';
class MyListener implements ImpalaSqlParserListener {
enterTableNamePath = (ctx): void => {
@ -21,4 +21,24 @@ describe('impala SQL Listener Tests', () => {
await parser.listen(listenTableName as ParseTreeListener, parseTree);
expect(result).toBe(expectTableName);
});
test('Listener sql', async () => {
const sql = `SELECT id FROM games ORDER BY score DESC;\nSHOW SCHEMAS LIKE 'xxx';`;
const sqlSlices = parser.splitSQLByStatement(sql);
expect(sqlSlices.length).toBe(2);
expect(sqlSlices[0].text).toBe('SELECT id FROM games ORDER BY score DESC;');
expect(sql.slice(sqlSlices[0].startIndex, sqlSlices[0].endIndex + 1)).toBe(
sqlSlices[0].text
);
expect(sqlSlices[0].startLine).toBe(1);
expect(sqlSlices[0].endLine).toBe(1);
expect(sqlSlices[1].text).toBe(`SHOW SCHEMAS LIKE 'xxx';`);
expect(sql.slice(sqlSlices[1].startIndex, sqlSlices[1].endIndex + 1)).toBe(
sqlSlices[1].text
);
expect(sqlSlices[1].startLine).toBe(2);
expect(sqlSlices[1].endLine).toBe(2);
});
});

View File

@ -188,4 +188,29 @@ select appx_median(x) from million_numbers;
select count(x) as higher from million_numbers where x > (select appx_median(x) from million_numbers);
select avg(length(s)) from t1;
select avg(length(s)) from t1;
select 'fooBar' ilike 'FOOBAR';
select 'ABCXYZ' not ilike 'ab_xyz';
select 1 not in (1,null,2,3);
SELECT c1 AS "starts with vowel" FROM t2 WHERE upper(substr(c1,1,1)) IN ('A','E','I','O','U');
select 'abcABCaabbcc' iregexp '^[a-c]+$';
select null is distinct from null, null != null;
select
'x' is distinct from 'x ' as string_with_trailing_spaces,
cast('x' as char(5)) is distinct from cast('x ' as char(5)) as char_with_trailing_spaces;
select assertion, b, b is true, b is false, b is unknown
from boolean_test;
select true and null;
select c_first_name, c_last_name from customer where lower(trim(c_last_name)) regexp '^de.*';
select c_first_name, c_last_name from customer where lower(trim(c_last_name)) rlike '^de.*';

View File

@ -11,7 +11,7 @@ describe('impala SQL Visitor Tests', () => {
console.log('Parse error:', error);
});
test('Visitor visitTableName', () => {
test('Visitor visitTableNamePath', () => {
let result = '';
class MyVisitor
extends AbstractParseTreeVisitor<any>