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_INTERMEDIATE : 'INTERMEDIATE';
KW_INTO : 'INTO'; KW_INTO : 'INTO';
KW_INIT_FN : 'INIT_FN'; KW_INIT_FN : 'INIT_FN';
KW_IREGEXP : 'IREGEXP';
KW_ILIKE : 'ILIKE';
KW_INVALIDATE : 'INVALIDATE'; KW_INVALIDATE : 'INVALIDATE';
KW_IS : 'IS'; KW_IS : 'IS';
KW_JOIN : 'JOIN'; KW_JOIN : 'JOIN';
@ -230,6 +232,7 @@ KW_USER : 'USER';
KW_USING : 'USING'; KW_USING : 'USING';
KW_UPDATE_FN : 'UPDATE_FN'; KW_UPDATE_FN : 'UPDATE_FN';
KW_UPSERT : 'UPSERT'; KW_UPSERT : 'UPSERT';
KW_UNKNOWN : 'UNKNOWN';
KW_URI : 'URI'; KW_URI : 'URI';
KW_VALUE : 'VALUE'; KW_VALUE : 'VALUE';
KW_VALUES : 'VALUES'; KW_VALUES : 'VALUES';

View File

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

View File

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

View File

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

View File

@ -9,7 +9,7 @@ describe('impala SQL Listener Tests', () => {
const parseTree = parser.parse(sql); const parseTree = parser.parse(sql);
test('Listener enterTableName', async () => { test('Listener enterTableNamePath', async () => {
let result = ''; let result = '';
class MyListener implements ImpalaSqlParserListener { class MyListener implements ImpalaSqlParserListener {
enterTableNamePath = (ctx): void => { enterTableNamePath = (ctx): void => {
@ -21,4 +21,24 @@ describe('impala SQL Listener Tests', () => {
await parser.listen(listenTableName as ParseTreeListener, parseTree); await parser.listen(listenTableName as ParseTreeListener, parseTree);
expect(result).toBe(expectTableName); 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 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); console.log('Parse error:', error);
}); });
test('Visitor visitTableName', () => { test('Visitor visitTableNamePath', () => {
let result = ''; let result = '';
class MyVisitor class MyVisitor
extends AbstractParseTreeVisitor<any> extends AbstractParseTreeVisitor<any>