feat(flink): add createTable grammar

This commit is contained in:
Erindcl 2020-10-22 19:57:13 +08:00
parent 654d96028c
commit b7df08f012
17 changed files with 8577 additions and 5 deletions

View File

@ -6,11 +6,12 @@ const grammars = path.resolve(__dirname, '../src/grammar');
const output = path.resolve(__dirname, '../src/lib'); const output = path.resolve(__dirname, '../src/lib');
const entry = [ const entry = [
'generic', // 'generic',
'hive', // 'hive',
'plsql', // 'plsql',
'spark', // 'spark',
'impala', // 'impala',
'flinksql',
]; ];
entry.forEach((language) => { entry.forEach((language) => {

View File

@ -0,0 +1,308 @@
lexer grammar FlinkSqlLexer;
channels { MYSQLCOMMENT }
// SKIP
SPACE: [ \t\r\n]+ -> channel(HIDDEN);
SPEC_MYSQL_COMMENT: '/*!' .+? '*/' -> channel(MYSQLCOMMENT);
COMMENT_INPUT: '/*' .*? '*/' -> channel(HIDDEN);
LINE_COMMENT: (
('-- ' | '#') ~[\r\n]* ('\r'? '\n' | EOF)
| '--' ('\r'? '\n' | EOF)
) -> channel(HIDDEN);
// Common Keywords
SELECT: 'SELECT';
FROM: 'FROM';
ADD: 'ADD';
AS: 'AS';
ALL: 'ALL';
ANY: 'ANY';
DISTINCT: 'DISTINCT';
WHERE: 'WHERE';
GROUP: 'GROUP';
BY: 'BY';
GROUPING: 'GROUPING';
SETS: 'SETS';
CUBE: 'CUBE';
ROLLUP: 'ROLLUP';
ORDER: 'ORDER';
HAVING: 'HAVING';
LIMIT: 'LIMIT';
AT: 'AT';
OR: 'OR';
AND: 'AND';
IN: 'IN';
NOT: 'NOT';
NO: 'NO';
EXISTS: 'EXISTS';
BETWEEN: 'BETWEEN';
LIKE: 'LIKE';
RLIKE: 'RLIKE';
IS: 'IS';
TRUE: 'TRUE';
FALSE: 'FALSE';
NULLS: 'NULLS';
ASC: 'ASC';
DESC: 'DESC';
FOR: 'FOR';
INTERVAL: 'INTERVAL';
CASE: 'CASE';
WHEN: 'WHEN';
THEN: 'THEN';
ELSE: 'ELSE';
END: 'END';
JOIN: 'JOIN';
CROSS: 'CROSS';
OUTER: 'OUTER';
INNER: 'INNER';
LEFT: 'LEFT';
SEMI: 'SEMI';
RIGHT: 'RIGHT';
FULL: 'FULL';
NATURAL: 'NATURAL';
ON: 'ON';
PIVOT: 'PIVOT';
LATERAL: 'LATERAL';
WINDOW: 'WINDOW';
OVER: 'OVER';
PARTITION: 'PARTITION';
RANGE: 'RANGE';
ROWS: 'ROWS';
UNBOUNDED: 'UNBOUNDED';
PRECEDING: 'PRECEDING';
FOLLOWING: 'FOLLOWING';
CURRENT: 'CURRENT';
FIRST: 'FIRST';
AFTER: 'AFTER';
LAST: 'LAST';
WITH: 'WITH';
VALUES: 'VALUES';
CREATE: 'CREATE';
TABLE: 'TABLE';
DIRECTORY: 'DIRECTORY';
VIEW: 'VIEW';
REPLACE: 'REPLACE';
INSERT: 'INSERT';
DELETE: 'DELETE';
INTO: 'INTO';
DESCRIBE: 'DESCRIBE';
EXPLAIN: 'EXPLAIN';
FORMAT: 'FORMAT';
LOGICAL: 'LOGICAL';
CODEGEN: 'CODEGEN';
COST: 'COST';
CAST: 'CAST';
SHOW: 'SHOW';
TABLES: 'TABLES';
COLUMNS: 'COLUMNS';
COLUMN: 'COLUMN';
USE: 'USE';
PARTITIONS: 'PARTITIONS';
FUNCTIONS: 'FUNCTIONS';
DROP: 'DROP';
UNION: 'UNION';
EXCEPT: 'EXCEPT';
SETMINUS: 'SETMINUS';
INTERSECT: 'INTERSECT';
TO: 'TO';
TABLESAMPLE: 'TABLESAMPLE';
STRATIFY: 'STRATIFY';
ALTER: 'ALTER';
RENAME: 'RENAME';
STRUCT: 'STRUCT';
COMMENT: 'COMMENT';
SET: 'SET';
RESET: 'RESET';
DATA: 'DATA';
START: 'START';
TRANSACTION: 'TRANSACTION';
COMMIT: 'COMMIT';
ROLLBACK: 'ROLLBACK';
MACRO: 'MACRO';
IGNORE: 'IGNORE';
BOTH: 'BOTH';
LEADING: 'LEADING';
TRAILING: 'TRAILING';
IF: 'IF';
POSITION: 'POSITION';
EXTRACT: 'EXTRACT';
EQ: 'EQ';
NSEQ: 'NSEQ';
NEQ: 'NEQ';
NEQJ: 'NEQJ';
LT: 'LT';
LTE: 'LTE';
GT: 'GT';
GTE: 'GTE';
PLUS: 'PLUS';
MINUS: 'MINUS';
ASTERISK: 'ASTERISK';
SLASH: 'SLASH';
PERCENT: 'PERCENT';
DIV: 'DIV';
TILDE: 'TILDE';
AMPERSAND: 'AMPERSAND';
PIPE: 'PIPE';
CONCAT_PIPE: 'CONCAT_PIPE';
HAT: 'HAT';
PERCENTLIT: 'PERCENTLIT';
BUCKET: 'BUCKET';
OUT: 'OUT';
OF: 'OF';
SORT: 'SORT';
CLUSTER: 'CLUSTER';
DISTRIBUTE: 'DISTRIBUTE';
OVERWRITE: 'OVERWRITE';
TRANSFORM: 'TRANSFORM';
REDUCE: 'REDUCE';
USING: 'USING';
SERDE: 'SERDE';
SERDEPROPERTIES: 'SERDEPROPERTIES';
RECORDREADER: 'RECORDREADER';
RECORDWRITER: 'RECORDWRITER';
DELIMITED: 'DELIMITED';
FIELDS: 'FIELDS';
TERMINATED: 'TERMINATED';
COLLECTION: 'COLLECTION';
ITEMS: 'ITEMS';
KEYS: 'KEYS';
ESCAPED: 'ESCAPED';
LINES: 'LINES';
SEPARATED: 'SEPARATED';
FUNCTION: 'FUNCTION';
EXTENDED: 'EXTENDED';
REFRESH: 'REFRESH';
CLEAR: 'CLEAR';
CACHE: 'CACHE';
UNCACHE: 'UNCACHE';
LAZY: 'LAZY';
FORMATTED: 'FORMATTED';
GLOBAL: 'GLOBAL';
TEMPORARY: 'TEMPORARY';
OPTIONS: 'OPTIONS';
UNSET: 'UNSET';
TBLPROPERTIES: 'TBLPROPERTIES';
DBPROPERTIES: 'DBPROPERTIES';
BUCKETS: 'BUCKETS';
SKEWED: 'SKEWED';
STORED: 'STORED';
DIRECTORIES: 'DIRECTORIES';
LOCATION: 'LOCATION';
EXCHANGE: 'EXCHANGE';
ARCHIVE: 'ARCHIVE';
UNARCHIVE: 'UNARCHIVE';
FILEFORMAT: 'FILEFORMAT';
TOUCH: 'TOUCH';
COMPACT: 'COMPACT';
CONCATENATE: 'CONCATENATE';
CHANGE: 'CHANGE';
CASCADE: 'CASCADE';
RESTRICT: 'RESTRICT';
CLUSTERED: 'CLUSTERED';
SORTED: 'SORTED';
PURGE: 'PURGE';
INPUTFORMAT: 'INPUTFORMAT';
OUTPUTFORMAT: 'OUTPUTFORMAT';
DATABASE: 'DATABASE';
DATABASES: 'DATABASES';
DFS: 'DFS';
TRUNCATE: 'TRUNCATE';
ANALYZE: 'ANALYZE';
COMPUTE: 'COMPUTE';
LIST: 'LIST';
STATISTICS: 'STATISTICS';
PARTITIONED: 'PARTITIONED';
EXTERNAL: 'EXTERNAL';
DEFINED: 'DEFINED';
REVOKE: 'REVOKE';
GRANT: 'GRANT';
LOCK: 'LOCK';
UNLOCK: 'UNLOCK';
MSCK: 'MSCK';
REPAIR: 'REPAIR';
RECOVER: 'RECOVER';
EXPORT: 'EXPORT';
IMPORT: 'IMPORT';
LOAD: 'LOAD';
ROLE: 'ROLE';
ROLES: 'ROLES';
COMPACTIONS: 'COMPACTIONS';
PRINCIPALS: 'PRINCIPALS';
TRANSACTIONS: 'TRANSACTIONS';
INDEX: 'INDEX';
INDEXES: 'INDEXES';
LOCKS: 'LOCKS';
OPTION: 'OPTION';
ANTI: 'ANTI';
LOCAL: 'LOCAL';
INPATH: 'INPATH';
WATERMARK: 'WATERMARK';
UNNEST: 'UNNEST';
MATCH_RECOGNIZE: 'MATCH_RECOGNIZE';
MEASURES: 'MEASURES';
ONE: 'ONE';
PER: 'PER';
MATCH: 'MATCH';
SKIP1: 'SKIP1';
NEXT: 'NEXT';
PAST: 'PAST';
PATTERN: 'PATTERN';
WITHIN: 'WITHIN';
DEFINE: 'DEFINE';
BIGINT_LITERAL: 'BIGINT_LITERAL';
SMALLINT_LITERAL: 'SMALLINT_LITERAL';
TINYINT_LITERAL: 'TINYINT_LITERAL';
INTEGER_VALUE: 'INTEGER_VALUE';
DECIMAL_VALUE: 'DECIMAL_VALUE';
DOUBLE_LITERAL: 'DOUBLE_LITERAL';
BIGDECIMAL_LITERAL: 'BIGDECIMAL_LITERAL';
IDENTIFIER: 'IDENTIFIER';
BACKQUOTED_IDENTIFIER: 'BACKQUOTED_IDENTIFIER';
SIMPLE_COMMENT: 'SIMPLE_COMMENT';
BRACKETED_EMPTY_COMMENT: 'BRACKETED_EMPTY_COMMENT';
BRACKETED_COMMENT: 'BRACKETED_COMMENT';
WS: 'WS';
UNRECOGNIZED: 'UNRECOGNIZED';
REVERSE_QUOTE_ID: '"' ~'"'+ '"';
DOT_ID: '.' ID_LITERAL;
ID: ID_LITERAL;
// DATA TYPE Keywords
STRING: 'STRING';
ARRAY: 'ARRAY';
MAP: 'MAP';
CHAR: 'CHAR';
VARCHAR: 'VARCHAR';
BINARY: 'BINARY';
VARBINARY: 'VARBINARY';
BYTES: 'BYTES';
DECIMAL: 'DECIMAL';
TINYINT: 'TINYINT';
SMALLINT: 'SMALLINT';
INT: 'INT';
BIGINT: 'BIGINT';
FLOAT: 'FLOAT';
DOUBLE: 'DOUBLE';
DATE: 'DATE';
TIME: 'TIME';
TIMESTAMP: 'TIMESTAMP';
MULTISET: 'MULTISET';
BOOLEAN: 'BOOLEAN';
RAW: 'RAW';
ROW: 'ROW';
NULL: 'NULL';
// single character Keywords
EQUAL: '=';
COMMA: ',';
fragment ID_LITERAL: [A-Z_0-9a-z]*?[A-Z_a-z]+?[A-Z_0-9a-z]*;

View File

@ -0,0 +1,119 @@
parser grammar FlinkSqlParser;
options { tokenVocab=FlinkSqlLexer; }
program: statement EOF;
statement
: sqlStatement EOF
;
sqlStatement
: ddlStatement | dmlStatement
;
ddlStatement
: createTable | createDatabase | createView | createFunction
| alterTable | alterDatabase | alterFunction
| dropTable | dropDatabase | dropView | dropFunction
;
dmlStatement
: selectStatement | insertStatement
;
createTable
: CREATE TABLE tableName
(
columnOptionDefinition (',' columnOptionDefinition)*
)
partitionDefinition?
WITH (
withOptionDefinition (',' withOptionDefinition)*
)
;
tableName
: ID (DOT_ID)*?
;
columnOptionDefinition
: columnName columnType
;
columnName
: ID
;
columnType
: CHAR | VARCHAR | STRING | BINARY | VARBINARY | BYTES
| DECIMAL | TINYINT | SMALLINT | INT | BIGINT | FLOAT | DOUBLE
| DATE | TIME | TIMESTAMP
| ARRAY | MAP | MULTISET | ROW
| BOOLEAN | RAW | NULL
;
partitionDefinition
: PARTITIONED BY partitionColumnDefinition
;
partitionColumnDefinition
: partitionColumnName (COMMA partitionColumnName)*
;
partitionColumnName
: ID
;
withOptionDefinition
: REVERSE_QUOTE_ID EQUAL REVERSE_QUOTE_ID
;
createDatabase
:
;
createView
:
;
createFunction
:
;
alterTable
:
;
alterDatabase
:
;
alterFunction
:
;
dropTable
:
;
dropDatabase
:
;
dropView
:
;
dropFunction
:
;
selectStatement
:
;
insertStatement
:
;

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,561 @@
SPACE=1
SPEC_MYSQL_COMMENT=2
COMMENT_INPUT=3
LINE_COMMENT=4
SELECT=5
FROM=6
ADD=7
AS=8
ALL=9
ANY=10
DISTINCT=11
WHERE=12
GROUP=13
BY=14
GROUPING=15
SETS=16
CUBE=17
ROLLUP=18
ORDER=19
HAVING=20
LIMIT=21
AT=22
OR=23
AND=24
IN=25
NOT=26
NO=27
EXISTS=28
BETWEEN=29
LIKE=30
RLIKE=31
IS=32
TRUE=33
FALSE=34
NULLS=35
ASC=36
DESC=37
FOR=38
INTERVAL=39
CASE=40
WHEN=41
THEN=42
ELSE=43
END=44
JOIN=45
CROSS=46
OUTER=47
INNER=48
LEFT=49
SEMI=50
RIGHT=51
FULL=52
NATURAL=53
ON=54
PIVOT=55
LATERAL=56
WINDOW=57
OVER=58
PARTITION=59
RANGE=60
ROWS=61
UNBOUNDED=62
PRECEDING=63
FOLLOWING=64
CURRENT=65
FIRST=66
AFTER=67
LAST=68
WITH=69
VALUES=70
CREATE=71
TABLE=72
DIRECTORY=73
VIEW=74
REPLACE=75
INSERT=76
DELETE=77
INTO=78
DESCRIBE=79
EXPLAIN=80
FORMAT=81
LOGICAL=82
CODEGEN=83
COST=84
CAST=85
SHOW=86
TABLES=87
COLUMNS=88
COLUMN=89
USE=90
PARTITIONS=91
FUNCTIONS=92
DROP=93
UNION=94
EXCEPT=95
SETMINUS=96
INTERSECT=97
TO=98
TABLESAMPLE=99
STRATIFY=100
ALTER=101
RENAME=102
STRUCT=103
COMMENT=104
SET=105
RESET=106
DATA=107
START=108
TRANSACTION=109
COMMIT=110
ROLLBACK=111
MACRO=112
IGNORE=113
BOTH=114
LEADING=115
TRAILING=116
IF=117
POSITION=118
EXTRACT=119
EQ=120
NSEQ=121
NEQ=122
NEQJ=123
LT=124
LTE=125
GT=126
GTE=127
PLUS=128
MINUS=129
ASTERISK=130
SLASH=131
PERCENT=132
DIV=133
TILDE=134
AMPERSAND=135
PIPE=136
CONCAT_PIPE=137
HAT=138
PERCENTLIT=139
BUCKET=140
OUT=141
OF=142
SORT=143
CLUSTER=144
DISTRIBUTE=145
OVERWRITE=146
TRANSFORM=147
REDUCE=148
USING=149
SERDE=150
SERDEPROPERTIES=151
RECORDREADER=152
RECORDWRITER=153
DELIMITED=154
FIELDS=155
TERMINATED=156
COLLECTION=157
ITEMS=158
KEYS=159
ESCAPED=160
LINES=161
SEPARATED=162
FUNCTION=163
EXTENDED=164
REFRESH=165
CLEAR=166
CACHE=167
UNCACHE=168
LAZY=169
FORMATTED=170
GLOBAL=171
TEMPORARY=172
OPTIONS=173
UNSET=174
TBLPROPERTIES=175
DBPROPERTIES=176
BUCKETS=177
SKEWED=178
STORED=179
DIRECTORIES=180
LOCATION=181
EXCHANGE=182
ARCHIVE=183
UNARCHIVE=184
FILEFORMAT=185
TOUCH=186
COMPACT=187
CONCATENATE=188
CHANGE=189
CASCADE=190
RESTRICT=191
CLUSTERED=192
SORTED=193
PURGE=194
INPUTFORMAT=195
OUTPUTFORMAT=196
DATABASE=197
DATABASES=198
DFS=199
TRUNCATE=200
ANALYZE=201
COMPUTE=202
LIST=203
STATISTICS=204
PARTITIONED=205
EXTERNAL=206
DEFINED=207
REVOKE=208
GRANT=209
LOCK=210
UNLOCK=211
MSCK=212
REPAIR=213
RECOVER=214
EXPORT=215
IMPORT=216
LOAD=217
ROLE=218
ROLES=219
COMPACTIONS=220
PRINCIPALS=221
TRANSACTIONS=222
INDEX=223
INDEXES=224
LOCKS=225
OPTION=226
ANTI=227
LOCAL=228
INPATH=229
WATERMARK=230
UNNEST=231
MATCH_RECOGNIZE=232
MEASURES=233
ONE=234
PER=235
MATCH=236
SKIP1=237
NEXT=238
PAST=239
PATTERN=240
WITHIN=241
DEFINE=242
BIGINT_LITERAL=243
SMALLINT_LITERAL=244
TINYINT_LITERAL=245
INTEGER_VALUE=246
DECIMAL_VALUE=247
DOUBLE_LITERAL=248
BIGDECIMAL_LITERAL=249
IDENTIFIER=250
BACKQUOTED_IDENTIFIER=251
SIMPLE_COMMENT=252
BRACKETED_EMPTY_COMMENT=253
BRACKETED_COMMENT=254
WS=255
UNRECOGNIZED=256
REVERSE_QUOTE_ID=257
DOT_ID=258
ID=259
STRING=260
ARRAY=261
MAP=262
CHAR=263
VARCHAR=264
BINARY=265
VARBINARY=266
BYTES=267
DECIMAL=268
TINYINT=269
SMALLINT=270
INT=271
BIGINT=272
FLOAT=273
DOUBLE=274
DATE=275
TIME=276
TIMESTAMP=277
MULTISET=278
BOOLEAN=279
RAW=280
ROW=281
NULL=282
EQUAL=283
COMMA=284
'SELECT'=5
'FROM'=6
'ADD'=7
'AS'=8
'ALL'=9
'ANY'=10
'DISTINCT'=11
'WHERE'=12
'GROUP'=13
'BY'=14
'GROUPING'=15
'SETS'=16
'CUBE'=17
'ROLLUP'=18
'ORDER'=19
'HAVING'=20
'LIMIT'=21
'AT'=22
'OR'=23
'AND'=24
'IN'=25
'NOT'=26
'NO'=27
'EXISTS'=28
'BETWEEN'=29
'LIKE'=30
'RLIKE'=31
'IS'=32
'TRUE'=33
'FALSE'=34
'NULLS'=35
'ASC'=36
'DESC'=37
'FOR'=38
'INTERVAL'=39
'CASE'=40
'WHEN'=41
'THEN'=42
'ELSE'=43
'END'=44
'JOIN'=45
'CROSS'=46
'OUTER'=47
'INNER'=48
'LEFT'=49
'SEMI'=50
'RIGHT'=51
'FULL'=52
'NATURAL'=53
'ON'=54
'PIVOT'=55
'LATERAL'=56
'WINDOW'=57
'OVER'=58
'PARTITION'=59
'RANGE'=60
'ROWS'=61
'UNBOUNDED'=62
'PRECEDING'=63
'FOLLOWING'=64
'CURRENT'=65
'FIRST'=66
'AFTER'=67
'LAST'=68
'WITH'=69
'VALUES'=70
'CREATE'=71
'TABLE'=72
'DIRECTORY'=73
'VIEW'=74
'REPLACE'=75
'INSERT'=76
'DELETE'=77
'INTO'=78
'DESCRIBE'=79
'EXPLAIN'=80
'FORMAT'=81
'LOGICAL'=82
'CODEGEN'=83
'COST'=84
'CAST'=85
'SHOW'=86
'TABLES'=87
'COLUMNS'=88
'COLUMN'=89
'USE'=90
'PARTITIONS'=91
'FUNCTIONS'=92
'DROP'=93
'UNION'=94
'EXCEPT'=95
'SETMINUS'=96
'INTERSECT'=97
'TO'=98
'TABLESAMPLE'=99
'STRATIFY'=100
'ALTER'=101
'RENAME'=102
'STRUCT'=103
'COMMENT'=104
'SET'=105
'RESET'=106
'DATA'=107
'START'=108
'TRANSACTION'=109
'COMMIT'=110
'ROLLBACK'=111
'MACRO'=112
'IGNORE'=113
'BOTH'=114
'LEADING'=115
'TRAILING'=116
'IF'=117
'POSITION'=118
'EXTRACT'=119
'EQ'=120
'NSEQ'=121
'NEQ'=122
'NEQJ'=123
'LT'=124
'LTE'=125
'GT'=126
'GTE'=127
'PLUS'=128
'MINUS'=129
'ASTERISK'=130
'SLASH'=131
'PERCENT'=132
'DIV'=133
'TILDE'=134
'AMPERSAND'=135
'PIPE'=136
'CONCAT_PIPE'=137
'HAT'=138
'PERCENTLIT'=139
'BUCKET'=140
'OUT'=141
'OF'=142
'SORT'=143
'CLUSTER'=144
'DISTRIBUTE'=145
'OVERWRITE'=146
'TRANSFORM'=147
'REDUCE'=148
'USING'=149
'SERDE'=150
'SERDEPROPERTIES'=151
'RECORDREADER'=152
'RECORDWRITER'=153
'DELIMITED'=154
'FIELDS'=155
'TERMINATED'=156
'COLLECTION'=157
'ITEMS'=158
'KEYS'=159
'ESCAPED'=160
'LINES'=161
'SEPARATED'=162
'FUNCTION'=163
'EXTENDED'=164
'REFRESH'=165
'CLEAR'=166
'CACHE'=167
'UNCACHE'=168
'LAZY'=169
'FORMATTED'=170
'GLOBAL'=171
'TEMPORARY'=172
'OPTIONS'=173
'UNSET'=174
'TBLPROPERTIES'=175
'DBPROPERTIES'=176
'BUCKETS'=177
'SKEWED'=178
'STORED'=179
'DIRECTORIES'=180
'LOCATION'=181
'EXCHANGE'=182
'ARCHIVE'=183
'UNARCHIVE'=184
'FILEFORMAT'=185
'TOUCH'=186
'COMPACT'=187
'CONCATENATE'=188
'CHANGE'=189
'CASCADE'=190
'RESTRICT'=191
'CLUSTERED'=192
'SORTED'=193
'PURGE'=194
'INPUTFORMAT'=195
'OUTPUTFORMAT'=196
'DATABASE'=197
'DATABASES'=198
'DFS'=199
'TRUNCATE'=200
'ANALYZE'=201
'COMPUTE'=202
'LIST'=203
'STATISTICS'=204
'PARTITIONED'=205
'EXTERNAL'=206
'DEFINED'=207
'REVOKE'=208
'GRANT'=209
'LOCK'=210
'UNLOCK'=211
'MSCK'=212
'REPAIR'=213
'RECOVER'=214
'EXPORT'=215
'IMPORT'=216
'LOAD'=217
'ROLE'=218
'ROLES'=219
'COMPACTIONS'=220
'PRINCIPALS'=221
'TRANSACTIONS'=222
'INDEX'=223
'INDEXES'=224
'LOCKS'=225
'OPTION'=226
'ANTI'=227
'LOCAL'=228
'INPATH'=229
'WATERMARK'=230
'UNNEST'=231
'MATCH_RECOGNIZE'=232
'MEASURES'=233
'ONE'=234
'PER'=235
'MATCH'=236
'SKIP1'=237
'NEXT'=238
'PAST'=239
'PATTERN'=240
'WITHIN'=241
'DEFINE'=242
'BIGINT_LITERAL'=243
'SMALLINT_LITERAL'=244
'TINYINT_LITERAL'=245
'INTEGER_VALUE'=246
'DECIMAL_VALUE'=247
'DOUBLE_LITERAL'=248
'BIGDECIMAL_LITERAL'=249
'IDENTIFIER'=250
'BACKQUOTED_IDENTIFIER'=251
'SIMPLE_COMMENT'=252
'BRACKETED_EMPTY_COMMENT'=253
'BRACKETED_COMMENT'=254
'WS'=255
'UNRECOGNIZED'=256
'STRING'=260
'ARRAY'=261
'MAP'=262
'CHAR'=263
'VARCHAR'=264
'BINARY'=265
'VARBINARY'=266
'BYTES'=267
'DECIMAL'=268
'TINYINT'=269
'SMALLINT'=270
'INT'=271
'BIGINT'=272
'FLOAT'=273
'DOUBLE'=274
'DATE'=275
'TIME'=276
'TIMESTAMP'=277
'MULTISET'=278
'BOOLEAN'=279
'RAW'=280
'ROW'=281
'NULL'=282
'='=283
','=284

View File

@ -0,0 +1,605 @@
token literal names:
null
null
null
null
null
'SELECT'
'FROM'
'ADD'
'AS'
'ALL'
'ANY'
'DISTINCT'
'WHERE'
'GROUP'
'BY'
'GROUPING'
'SETS'
'CUBE'
'ROLLUP'
'ORDER'
'HAVING'
'LIMIT'
'AT'
'OR'
'AND'
'IN'
'NOT'
'NO'
'EXISTS'
'BETWEEN'
'LIKE'
'RLIKE'
'IS'
'TRUE'
'FALSE'
'NULLS'
'ASC'
'DESC'
'FOR'
'INTERVAL'
'CASE'
'WHEN'
'THEN'
'ELSE'
'END'
'JOIN'
'CROSS'
'OUTER'
'INNER'
'LEFT'
'SEMI'
'RIGHT'
'FULL'
'NATURAL'
'ON'
'PIVOT'
'LATERAL'
'WINDOW'
'OVER'
'PARTITION'
'RANGE'
'ROWS'
'UNBOUNDED'
'PRECEDING'
'FOLLOWING'
'CURRENT'
'FIRST'
'AFTER'
'LAST'
'WITH'
'VALUES'
'CREATE'
'TABLE'
'DIRECTORY'
'VIEW'
'REPLACE'
'INSERT'
'DELETE'
'INTO'
'DESCRIBE'
'EXPLAIN'
'FORMAT'
'LOGICAL'
'CODEGEN'
'COST'
'CAST'
'SHOW'
'TABLES'
'COLUMNS'
'COLUMN'
'USE'
'PARTITIONS'
'FUNCTIONS'
'DROP'
'UNION'
'EXCEPT'
'SETMINUS'
'INTERSECT'
'TO'
'TABLESAMPLE'
'STRATIFY'
'ALTER'
'RENAME'
'STRUCT'
'COMMENT'
'SET'
'RESET'
'DATA'
'START'
'TRANSACTION'
'COMMIT'
'ROLLBACK'
'MACRO'
'IGNORE'
'BOTH'
'LEADING'
'TRAILING'
'IF'
'POSITION'
'EXTRACT'
'EQ'
'NSEQ'
'NEQ'
'NEQJ'
'LT'
'LTE'
'GT'
'GTE'
'PLUS'
'MINUS'
'ASTERISK'
'SLASH'
'PERCENT'
'DIV'
'TILDE'
'AMPERSAND'
'PIPE'
'CONCAT_PIPE'
'HAT'
'PERCENTLIT'
'BUCKET'
'OUT'
'OF'
'SORT'
'CLUSTER'
'DISTRIBUTE'
'OVERWRITE'
'TRANSFORM'
'REDUCE'
'USING'
'SERDE'
'SERDEPROPERTIES'
'RECORDREADER'
'RECORDWRITER'
'DELIMITED'
'FIELDS'
'TERMINATED'
'COLLECTION'
'ITEMS'
'KEYS'
'ESCAPED'
'LINES'
'SEPARATED'
'FUNCTION'
'EXTENDED'
'REFRESH'
'CLEAR'
'CACHE'
'UNCACHE'
'LAZY'
'FORMATTED'
'GLOBAL'
'TEMPORARY'
'OPTIONS'
'UNSET'
'TBLPROPERTIES'
'DBPROPERTIES'
'BUCKETS'
'SKEWED'
'STORED'
'DIRECTORIES'
'LOCATION'
'EXCHANGE'
'ARCHIVE'
'UNARCHIVE'
'FILEFORMAT'
'TOUCH'
'COMPACT'
'CONCATENATE'
'CHANGE'
'CASCADE'
'RESTRICT'
'CLUSTERED'
'SORTED'
'PURGE'
'INPUTFORMAT'
'OUTPUTFORMAT'
'DATABASE'
'DATABASES'
'DFS'
'TRUNCATE'
'ANALYZE'
'COMPUTE'
'LIST'
'STATISTICS'
'PARTITIONED'
'EXTERNAL'
'DEFINED'
'REVOKE'
'GRANT'
'LOCK'
'UNLOCK'
'MSCK'
'REPAIR'
'RECOVER'
'EXPORT'
'IMPORT'
'LOAD'
'ROLE'
'ROLES'
'COMPACTIONS'
'PRINCIPALS'
'TRANSACTIONS'
'INDEX'
'INDEXES'
'LOCKS'
'OPTION'
'ANTI'
'LOCAL'
'INPATH'
'WATERMARK'
'UNNEST'
'MATCH_RECOGNIZE'
'MEASURES'
'ONE'
'PER'
'MATCH'
'SKIP1'
'NEXT'
'PAST'
'PATTERN'
'WITHIN'
'DEFINE'
'BIGINT_LITERAL'
'SMALLINT_LITERAL'
'TINYINT_LITERAL'
'INTEGER_VALUE'
'DECIMAL_VALUE'
'DOUBLE_LITERAL'
'BIGDECIMAL_LITERAL'
'IDENTIFIER'
'BACKQUOTED_IDENTIFIER'
'SIMPLE_COMMENT'
'BRACKETED_EMPTY_COMMENT'
'BRACKETED_COMMENT'
'WS'
'UNRECOGNIZED'
null
null
null
'STRING'
'ARRAY'
'MAP'
'CHAR'
'VARCHAR'
'BINARY'
'VARBINARY'
'BYTES'
'DECIMAL'
'TINYINT'
'SMALLINT'
'INT'
'BIGINT'
'FLOAT'
'DOUBLE'
'DATE'
'TIME'
'TIMESTAMP'
'MULTISET'
'BOOLEAN'
'RAW'
'ROW'
'NULL'
'='
','
token symbolic names:
null
SPACE
SPEC_MYSQL_COMMENT
COMMENT_INPUT
LINE_COMMENT
SELECT
FROM
ADD
AS
ALL
ANY
DISTINCT
WHERE
GROUP
BY
GROUPING
SETS
CUBE
ROLLUP
ORDER
HAVING
LIMIT
AT
OR
AND
IN
NOT
NO
EXISTS
BETWEEN
LIKE
RLIKE
IS
TRUE
FALSE
NULLS
ASC
DESC
FOR
INTERVAL
CASE
WHEN
THEN
ELSE
END
JOIN
CROSS
OUTER
INNER
LEFT
SEMI
RIGHT
FULL
NATURAL
ON
PIVOT
LATERAL
WINDOW
OVER
PARTITION
RANGE
ROWS
UNBOUNDED
PRECEDING
FOLLOWING
CURRENT
FIRST
AFTER
LAST
WITH
VALUES
CREATE
TABLE
DIRECTORY
VIEW
REPLACE
INSERT
DELETE
INTO
DESCRIBE
EXPLAIN
FORMAT
LOGICAL
CODEGEN
COST
CAST
SHOW
TABLES
COLUMNS
COLUMN
USE
PARTITIONS
FUNCTIONS
DROP
UNION
EXCEPT
SETMINUS
INTERSECT
TO
TABLESAMPLE
STRATIFY
ALTER
RENAME
STRUCT
COMMENT
SET
RESET
DATA
START
TRANSACTION
COMMIT
ROLLBACK
MACRO
IGNORE
BOTH
LEADING
TRAILING
IF
POSITION
EXTRACT
EQ
NSEQ
NEQ
NEQJ
LT
LTE
GT
GTE
PLUS
MINUS
ASTERISK
SLASH
PERCENT
DIV
TILDE
AMPERSAND
PIPE
CONCAT_PIPE
HAT
PERCENTLIT
BUCKET
OUT
OF
SORT
CLUSTER
DISTRIBUTE
OVERWRITE
TRANSFORM
REDUCE
USING
SERDE
SERDEPROPERTIES
RECORDREADER
RECORDWRITER
DELIMITED
FIELDS
TERMINATED
COLLECTION
ITEMS
KEYS
ESCAPED
LINES
SEPARATED
FUNCTION
EXTENDED
REFRESH
CLEAR
CACHE
UNCACHE
LAZY
FORMATTED
GLOBAL
TEMPORARY
OPTIONS
UNSET
TBLPROPERTIES
DBPROPERTIES
BUCKETS
SKEWED
STORED
DIRECTORIES
LOCATION
EXCHANGE
ARCHIVE
UNARCHIVE
FILEFORMAT
TOUCH
COMPACT
CONCATENATE
CHANGE
CASCADE
RESTRICT
CLUSTERED
SORTED
PURGE
INPUTFORMAT
OUTPUTFORMAT
DATABASE
DATABASES
DFS
TRUNCATE
ANALYZE
COMPUTE
LIST
STATISTICS
PARTITIONED
EXTERNAL
DEFINED
REVOKE
GRANT
LOCK
UNLOCK
MSCK
REPAIR
RECOVER
EXPORT
IMPORT
LOAD
ROLE
ROLES
COMPACTIONS
PRINCIPALS
TRANSACTIONS
INDEX
INDEXES
LOCKS
OPTION
ANTI
LOCAL
INPATH
WATERMARK
UNNEST
MATCH_RECOGNIZE
MEASURES
ONE
PER
MATCH
SKIP1
NEXT
PAST
PATTERN
WITHIN
DEFINE
BIGINT_LITERAL
SMALLINT_LITERAL
TINYINT_LITERAL
INTEGER_VALUE
DECIMAL_VALUE
DOUBLE_LITERAL
BIGDECIMAL_LITERAL
IDENTIFIER
BACKQUOTED_IDENTIFIER
SIMPLE_COMMENT
BRACKETED_EMPTY_COMMENT
BRACKETED_COMMENT
WS
UNRECOGNIZED
REVERSE_QUOTE_ID
DOT_ID
ID
STRING
ARRAY
MAP
CHAR
VARCHAR
BINARY
VARBINARY
BYTES
DECIMAL
TINYINT
SMALLINT
INT
BIGINT
FLOAT
DOUBLE
DATE
TIME
TIMESTAMP
MULTISET
BOOLEAN
RAW
ROW
NULL
EQUAL
COMMA
rule names:
program
statement
sqlStatement
ddlStatement
dmlStatement
createTable
tableName
columnOptionDefinition
columnName
columnType
partitionDefinition
partitionColumnDefinition
partitionColumnName
withOptionDefinition
createDatabase
createView
createFunction
alterTable
alterDatabase
alterFunction
dropTable
dropDatabase
dropView
dropFunction
selectStatement
insertStatement
atn:
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 286, 161, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 4, 27, 9, 27, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 5, 4, 63, 10, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 5, 5, 76, 10, 5, 3, 6, 3, 6, 5, 6, 80, 10, 6, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 7, 7, 88, 10, 7, 12, 7, 14, 7, 91, 11, 7, 3, 7, 5, 7, 94, 10, 7, 3, 7, 3, 7, 3, 7, 3, 7, 7, 7, 100, 10, 7, 12, 7, 14, 7, 103, 11, 7, 3, 8, 3, 8, 7, 8, 107, 10, 8, 12, 8, 14, 8, 110, 11, 8, 3, 9, 3, 9, 3, 9, 3, 10, 3, 10, 3, 11, 3, 11, 3, 12, 3, 12, 3, 12, 3, 12, 3, 13, 3, 13, 3, 13, 7, 13, 126, 10, 13, 12, 13, 14, 13, 129, 11, 13, 3, 14, 3, 14, 3, 15, 3, 15, 3, 15, 3, 15, 3, 16, 3, 16, 3, 17, 3, 17, 3, 18, 3, 18, 3, 19, 3, 19, 3, 20, 3, 20, 3, 21, 3, 21, 3, 22, 3, 22, 3, 23, 3, 23, 3, 24, 3, 24, 3, 25, 3, 25, 3, 26, 3, 26, 3, 27, 3, 27, 3, 27, 3, 108, 2, 28, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 2, 3, 3, 2, 262, 284, 2, 151, 2, 54, 3, 2, 2, 2, 4, 57, 3, 2, 2, 2, 6, 62, 3, 2, 2, 2, 8, 75, 3, 2, 2, 2, 10, 79, 3, 2, 2, 2, 12, 81, 3, 2, 2, 2, 14, 104, 3, 2, 2, 2, 16, 111, 3, 2, 2, 2, 18, 114, 3, 2, 2, 2, 20, 116, 3, 2, 2, 2, 22, 118, 3, 2, 2, 2, 24, 122, 3, 2, 2, 2, 26, 130, 3, 2, 2, 2, 28, 132, 3, 2, 2, 2, 30, 136, 3, 2, 2, 2, 32, 138, 3, 2, 2, 2, 34, 140, 3, 2, 2, 2, 36, 142, 3, 2, 2, 2, 38, 144, 3, 2, 2, 2, 40, 146, 3, 2, 2, 2, 42, 148, 3, 2, 2, 2, 44, 150, 3, 2, 2, 2, 46, 152, 3, 2, 2, 2, 48, 154, 3, 2, 2, 2, 50, 156, 3, 2, 2, 2, 52, 158, 3, 2, 2, 2, 54, 55, 5, 4, 3, 2, 55, 56, 7, 2, 2, 3, 56, 3, 3, 2, 2, 2, 57, 58, 5, 6, 4, 2, 58, 59, 7, 2, 2, 3, 59, 5, 3, 2, 2, 2, 60, 63, 5, 8, 5, 2, 61, 63, 5, 10, 6, 2, 62, 60, 3, 2, 2, 2, 62, 61, 3, 2, 2, 2, 63, 7, 3, 2, 2, 2, 64, 76, 5, 12, 7, 2, 65, 76, 5, 30, 16, 2, 66, 76, 5, 32, 17, 2, 67, 76, 5, 34, 18, 2, 68, 76, 5, 36, 19, 2, 69, 76, 5, 38, 20, 2, 70, 76, 5, 40, 21, 2, 71, 76, 5, 42, 22, 2, 72, 76, 5, 44, 23, 2, 73, 76, 5, 46, 24, 2, 74, 76, 5, 48, 25, 2, 75, 64, 3, 2, 2, 2, 75, 65, 3, 2, 2, 2, 75, 66, 3, 2, 2, 2, 75, 67, 3, 2, 2, 2, 75, 68, 3, 2, 2, 2, 75, 69, 3, 2, 2, 2, 75, 70, 3, 2, 2, 2, 75, 71, 3, 2, 2, 2, 75, 72, 3, 2, 2, 2, 75, 73, 3, 2, 2, 2, 75, 74, 3, 2, 2, 2, 76, 9, 3, 2, 2, 2, 77, 80, 5, 50, 26, 2, 78, 80, 5, 52, 27, 2, 79, 77, 3, 2, 2, 2, 79, 78, 3, 2, 2, 2, 80, 11, 3, 2, 2, 2, 81, 82, 7, 73, 2, 2, 82, 83, 7, 74, 2, 2, 83, 84, 5, 14, 8, 2, 84, 89, 5, 16, 9, 2, 85, 86, 7, 286, 2, 2, 86, 88, 5, 16, 9, 2, 87, 85, 3, 2, 2, 2, 88, 91, 3, 2, 2, 2, 89, 87, 3, 2, 2, 2, 89, 90, 3, 2, 2, 2, 90, 93, 3, 2, 2, 2, 91, 89, 3, 2, 2, 2, 92, 94, 5, 22, 12, 2, 93, 92, 3, 2, 2, 2, 93, 94, 3, 2, 2, 2, 94, 95, 3, 2, 2, 2, 95, 96, 7, 71, 2, 2, 96, 101, 5, 28, 15, 2, 97, 98, 7, 286, 2, 2, 98, 100, 5, 28, 15, 2, 99, 97, 3, 2, 2, 2, 100, 103, 3, 2, 2, 2, 101, 99, 3, 2, 2, 2, 101, 102, 3, 2, 2, 2, 102, 13, 3, 2, 2, 2, 103, 101, 3, 2, 2, 2, 104, 108, 7, 261, 2, 2, 105, 107, 7, 260, 2, 2, 106, 105, 3, 2, 2, 2, 107, 110, 3, 2, 2, 2, 108, 109, 3, 2, 2, 2, 108, 106, 3, 2, 2, 2, 109, 15, 3, 2, 2, 2, 110, 108, 3, 2, 2, 2, 111, 112, 5, 18, 10, 2, 112, 113, 5, 20, 11, 2, 113, 17, 3, 2, 2, 2, 114, 115, 7, 261, 2, 2, 115, 19, 3, 2, 2, 2, 116, 117, 9, 2, 2, 2, 117, 21, 3, 2, 2, 2, 118, 119, 7, 207, 2, 2, 119, 120, 7, 16, 2, 2, 120, 121, 5, 24, 13, 2, 121, 23, 3, 2, 2, 2, 122, 127, 5, 26, 14, 2, 123, 124, 7, 286, 2, 2, 124, 126, 5, 26, 14, 2, 125, 123, 3, 2, 2, 2, 126, 129, 3, 2, 2, 2, 127, 125, 3, 2, 2, 2, 127, 128, 3, 2, 2, 2, 128, 25, 3, 2, 2, 2, 129, 127, 3, 2, 2, 2, 130, 131, 7, 261, 2, 2, 131, 27, 3, 2, 2, 2, 132, 133, 7, 259, 2, 2, 133, 134, 7, 285, 2, 2, 134, 135, 7, 259, 2, 2, 135, 29, 3, 2, 2, 2, 136, 137, 3, 2, 2, 2, 137, 31, 3, 2, 2, 2, 138, 139, 3, 2, 2, 2, 139, 33, 3, 2, 2, 2, 140, 141, 3, 2, 2, 2, 141, 35, 3, 2, 2, 2, 142, 143, 3, 2, 2, 2, 143, 37, 3, 2, 2, 2, 144, 145, 3, 2, 2, 2, 145, 39, 3, 2, 2, 2, 146, 147, 3, 2, 2, 2, 147, 41, 3, 2, 2, 2, 148, 149, 3, 2, 2, 2, 149, 43, 3, 2, 2, 2, 150, 151, 3, 2, 2, 2, 151, 45, 3, 2, 2, 2, 152, 153, 3, 2, 2, 2, 153, 47, 3, 2, 2, 2, 154, 155, 3, 2, 2, 2, 155, 49, 3, 2, 2, 2, 156, 157, 3, 2, 2, 2, 157, 51, 3, 2, 2, 2, 158, 159, 3, 2, 2, 2, 159, 53, 3, 2, 2, 2, 10, 62, 75, 79, 89, 93, 101, 108, 127]

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,561 @@
SPACE=1
SPEC_MYSQL_COMMENT=2
COMMENT_INPUT=3
LINE_COMMENT=4
SELECT=5
FROM=6
ADD=7
AS=8
ALL=9
ANY=10
DISTINCT=11
WHERE=12
GROUP=13
BY=14
GROUPING=15
SETS=16
CUBE=17
ROLLUP=18
ORDER=19
HAVING=20
LIMIT=21
AT=22
OR=23
AND=24
IN=25
NOT=26
NO=27
EXISTS=28
BETWEEN=29
LIKE=30
RLIKE=31
IS=32
TRUE=33
FALSE=34
NULLS=35
ASC=36
DESC=37
FOR=38
INTERVAL=39
CASE=40
WHEN=41
THEN=42
ELSE=43
END=44
JOIN=45
CROSS=46
OUTER=47
INNER=48
LEFT=49
SEMI=50
RIGHT=51
FULL=52
NATURAL=53
ON=54
PIVOT=55
LATERAL=56
WINDOW=57
OVER=58
PARTITION=59
RANGE=60
ROWS=61
UNBOUNDED=62
PRECEDING=63
FOLLOWING=64
CURRENT=65
FIRST=66
AFTER=67
LAST=68
WITH=69
VALUES=70
CREATE=71
TABLE=72
DIRECTORY=73
VIEW=74
REPLACE=75
INSERT=76
DELETE=77
INTO=78
DESCRIBE=79
EXPLAIN=80
FORMAT=81
LOGICAL=82
CODEGEN=83
COST=84
CAST=85
SHOW=86
TABLES=87
COLUMNS=88
COLUMN=89
USE=90
PARTITIONS=91
FUNCTIONS=92
DROP=93
UNION=94
EXCEPT=95
SETMINUS=96
INTERSECT=97
TO=98
TABLESAMPLE=99
STRATIFY=100
ALTER=101
RENAME=102
STRUCT=103
COMMENT=104
SET=105
RESET=106
DATA=107
START=108
TRANSACTION=109
COMMIT=110
ROLLBACK=111
MACRO=112
IGNORE=113
BOTH=114
LEADING=115
TRAILING=116
IF=117
POSITION=118
EXTRACT=119
EQ=120
NSEQ=121
NEQ=122
NEQJ=123
LT=124
LTE=125
GT=126
GTE=127
PLUS=128
MINUS=129
ASTERISK=130
SLASH=131
PERCENT=132
DIV=133
TILDE=134
AMPERSAND=135
PIPE=136
CONCAT_PIPE=137
HAT=138
PERCENTLIT=139
BUCKET=140
OUT=141
OF=142
SORT=143
CLUSTER=144
DISTRIBUTE=145
OVERWRITE=146
TRANSFORM=147
REDUCE=148
USING=149
SERDE=150
SERDEPROPERTIES=151
RECORDREADER=152
RECORDWRITER=153
DELIMITED=154
FIELDS=155
TERMINATED=156
COLLECTION=157
ITEMS=158
KEYS=159
ESCAPED=160
LINES=161
SEPARATED=162
FUNCTION=163
EXTENDED=164
REFRESH=165
CLEAR=166
CACHE=167
UNCACHE=168
LAZY=169
FORMATTED=170
GLOBAL=171
TEMPORARY=172
OPTIONS=173
UNSET=174
TBLPROPERTIES=175
DBPROPERTIES=176
BUCKETS=177
SKEWED=178
STORED=179
DIRECTORIES=180
LOCATION=181
EXCHANGE=182
ARCHIVE=183
UNARCHIVE=184
FILEFORMAT=185
TOUCH=186
COMPACT=187
CONCATENATE=188
CHANGE=189
CASCADE=190
RESTRICT=191
CLUSTERED=192
SORTED=193
PURGE=194
INPUTFORMAT=195
OUTPUTFORMAT=196
DATABASE=197
DATABASES=198
DFS=199
TRUNCATE=200
ANALYZE=201
COMPUTE=202
LIST=203
STATISTICS=204
PARTITIONED=205
EXTERNAL=206
DEFINED=207
REVOKE=208
GRANT=209
LOCK=210
UNLOCK=211
MSCK=212
REPAIR=213
RECOVER=214
EXPORT=215
IMPORT=216
LOAD=217
ROLE=218
ROLES=219
COMPACTIONS=220
PRINCIPALS=221
TRANSACTIONS=222
INDEX=223
INDEXES=224
LOCKS=225
OPTION=226
ANTI=227
LOCAL=228
INPATH=229
WATERMARK=230
UNNEST=231
MATCH_RECOGNIZE=232
MEASURES=233
ONE=234
PER=235
MATCH=236
SKIP1=237
NEXT=238
PAST=239
PATTERN=240
WITHIN=241
DEFINE=242
BIGINT_LITERAL=243
SMALLINT_LITERAL=244
TINYINT_LITERAL=245
INTEGER_VALUE=246
DECIMAL_VALUE=247
DOUBLE_LITERAL=248
BIGDECIMAL_LITERAL=249
IDENTIFIER=250
BACKQUOTED_IDENTIFIER=251
SIMPLE_COMMENT=252
BRACKETED_EMPTY_COMMENT=253
BRACKETED_COMMENT=254
WS=255
UNRECOGNIZED=256
REVERSE_QUOTE_ID=257
DOT_ID=258
ID=259
STRING=260
ARRAY=261
MAP=262
CHAR=263
VARCHAR=264
BINARY=265
VARBINARY=266
BYTES=267
DECIMAL=268
TINYINT=269
SMALLINT=270
INT=271
BIGINT=272
FLOAT=273
DOUBLE=274
DATE=275
TIME=276
TIMESTAMP=277
MULTISET=278
BOOLEAN=279
RAW=280
ROW=281
NULL=282
EQUAL=283
COMMA=284
'SELECT'=5
'FROM'=6
'ADD'=7
'AS'=8
'ALL'=9
'ANY'=10
'DISTINCT'=11
'WHERE'=12
'GROUP'=13
'BY'=14
'GROUPING'=15
'SETS'=16
'CUBE'=17
'ROLLUP'=18
'ORDER'=19
'HAVING'=20
'LIMIT'=21
'AT'=22
'OR'=23
'AND'=24
'IN'=25
'NOT'=26
'NO'=27
'EXISTS'=28
'BETWEEN'=29
'LIKE'=30
'RLIKE'=31
'IS'=32
'TRUE'=33
'FALSE'=34
'NULLS'=35
'ASC'=36
'DESC'=37
'FOR'=38
'INTERVAL'=39
'CASE'=40
'WHEN'=41
'THEN'=42
'ELSE'=43
'END'=44
'JOIN'=45
'CROSS'=46
'OUTER'=47
'INNER'=48
'LEFT'=49
'SEMI'=50
'RIGHT'=51
'FULL'=52
'NATURAL'=53
'ON'=54
'PIVOT'=55
'LATERAL'=56
'WINDOW'=57
'OVER'=58
'PARTITION'=59
'RANGE'=60
'ROWS'=61
'UNBOUNDED'=62
'PRECEDING'=63
'FOLLOWING'=64
'CURRENT'=65
'FIRST'=66
'AFTER'=67
'LAST'=68
'WITH'=69
'VALUES'=70
'CREATE'=71
'TABLE'=72
'DIRECTORY'=73
'VIEW'=74
'REPLACE'=75
'INSERT'=76
'DELETE'=77
'INTO'=78
'DESCRIBE'=79
'EXPLAIN'=80
'FORMAT'=81
'LOGICAL'=82
'CODEGEN'=83
'COST'=84
'CAST'=85
'SHOW'=86
'TABLES'=87
'COLUMNS'=88
'COLUMN'=89
'USE'=90
'PARTITIONS'=91
'FUNCTIONS'=92
'DROP'=93
'UNION'=94
'EXCEPT'=95
'SETMINUS'=96
'INTERSECT'=97
'TO'=98
'TABLESAMPLE'=99
'STRATIFY'=100
'ALTER'=101
'RENAME'=102
'STRUCT'=103
'COMMENT'=104
'SET'=105
'RESET'=106
'DATA'=107
'START'=108
'TRANSACTION'=109
'COMMIT'=110
'ROLLBACK'=111
'MACRO'=112
'IGNORE'=113
'BOTH'=114
'LEADING'=115
'TRAILING'=116
'IF'=117
'POSITION'=118
'EXTRACT'=119
'EQ'=120
'NSEQ'=121
'NEQ'=122
'NEQJ'=123
'LT'=124
'LTE'=125
'GT'=126
'GTE'=127
'PLUS'=128
'MINUS'=129
'ASTERISK'=130
'SLASH'=131
'PERCENT'=132
'DIV'=133
'TILDE'=134
'AMPERSAND'=135
'PIPE'=136
'CONCAT_PIPE'=137
'HAT'=138
'PERCENTLIT'=139
'BUCKET'=140
'OUT'=141
'OF'=142
'SORT'=143
'CLUSTER'=144
'DISTRIBUTE'=145
'OVERWRITE'=146
'TRANSFORM'=147
'REDUCE'=148
'USING'=149
'SERDE'=150
'SERDEPROPERTIES'=151
'RECORDREADER'=152
'RECORDWRITER'=153
'DELIMITED'=154
'FIELDS'=155
'TERMINATED'=156
'COLLECTION'=157
'ITEMS'=158
'KEYS'=159
'ESCAPED'=160
'LINES'=161
'SEPARATED'=162
'FUNCTION'=163
'EXTENDED'=164
'REFRESH'=165
'CLEAR'=166
'CACHE'=167
'UNCACHE'=168
'LAZY'=169
'FORMATTED'=170
'GLOBAL'=171
'TEMPORARY'=172
'OPTIONS'=173
'UNSET'=174
'TBLPROPERTIES'=175
'DBPROPERTIES'=176
'BUCKETS'=177
'SKEWED'=178
'STORED'=179
'DIRECTORIES'=180
'LOCATION'=181
'EXCHANGE'=182
'ARCHIVE'=183
'UNARCHIVE'=184
'FILEFORMAT'=185
'TOUCH'=186
'COMPACT'=187
'CONCATENATE'=188
'CHANGE'=189
'CASCADE'=190
'RESTRICT'=191
'CLUSTERED'=192
'SORTED'=193
'PURGE'=194
'INPUTFORMAT'=195
'OUTPUTFORMAT'=196
'DATABASE'=197
'DATABASES'=198
'DFS'=199
'TRUNCATE'=200
'ANALYZE'=201
'COMPUTE'=202
'LIST'=203
'STATISTICS'=204
'PARTITIONED'=205
'EXTERNAL'=206
'DEFINED'=207
'REVOKE'=208
'GRANT'=209
'LOCK'=210
'UNLOCK'=211
'MSCK'=212
'REPAIR'=213
'RECOVER'=214
'EXPORT'=215
'IMPORT'=216
'LOAD'=217
'ROLE'=218
'ROLES'=219
'COMPACTIONS'=220
'PRINCIPALS'=221
'TRANSACTIONS'=222
'INDEX'=223
'INDEXES'=224
'LOCKS'=225
'OPTION'=226
'ANTI'=227
'LOCAL'=228
'INPATH'=229
'WATERMARK'=230
'UNNEST'=231
'MATCH_RECOGNIZE'=232
'MEASURES'=233
'ONE'=234
'PER'=235
'MATCH'=236
'SKIP1'=237
'NEXT'=238
'PAST'=239
'PATTERN'=240
'WITHIN'=241
'DEFINE'=242
'BIGINT_LITERAL'=243
'SMALLINT_LITERAL'=244
'TINYINT_LITERAL'=245
'INTEGER_VALUE'=246
'DECIMAL_VALUE'=247
'DOUBLE_LITERAL'=248
'BIGDECIMAL_LITERAL'=249
'IDENTIFIER'=250
'BACKQUOTED_IDENTIFIER'=251
'SIMPLE_COMMENT'=252
'BRACKETED_EMPTY_COMMENT'=253
'BRACKETED_COMMENT'=254
'WS'=255
'UNRECOGNIZED'=256
'STRING'=260
'ARRAY'=261
'MAP'=262
'CHAR'=263
'VARCHAR'=264
'BINARY'=265
'VARBINARY'=266
'BYTES'=267
'DECIMAL'=268
'TINYINT'=269
'SMALLINT'=270
'INT'=271
'BIGINT'=272
'FLOAT'=273
'DOUBLE'=274
'DATE'=275
'TIME'=276
'TIMESTAMP'=277
'MULTISET'=278
'BOOLEAN'=279
'RAW'=280
'ROW'=281
'NULL'=282
'='=283
','=284

View File

@ -0,0 +1,249 @@
// Generated from /Users/erindeng/Desktop/dt-sql-parser/src/grammar/flinksql/FlinkSqlParser.g4 by ANTLR 4.8
// jshint ignore: start
var antlr4 = require('antlr4/index');
// This class defines a complete listener for a parse tree produced by FlinkSqlParser.
function FlinkSqlParserListener() {
antlr4.tree.ParseTreeListener.call(this);
return this;
}
FlinkSqlParserListener.prototype = Object.create(antlr4.tree.ParseTreeListener.prototype);
FlinkSqlParserListener.prototype.constructor = FlinkSqlParserListener;
// Enter a parse tree produced by FlinkSqlParser#program.
FlinkSqlParserListener.prototype.enterProgram = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#program.
FlinkSqlParserListener.prototype.exitProgram = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#statement.
FlinkSqlParserListener.prototype.enterStatement = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#statement.
FlinkSqlParserListener.prototype.exitStatement = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#sqlStatement.
FlinkSqlParserListener.prototype.enterSqlStatement = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#sqlStatement.
FlinkSqlParserListener.prototype.exitSqlStatement = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#ddlStatement.
FlinkSqlParserListener.prototype.enterDdlStatement = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#ddlStatement.
FlinkSqlParserListener.prototype.exitDdlStatement = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#dmlStatement.
FlinkSqlParserListener.prototype.enterDmlStatement = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#dmlStatement.
FlinkSqlParserListener.prototype.exitDmlStatement = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#createTable.
FlinkSqlParserListener.prototype.enterCreateTable = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#createTable.
FlinkSqlParserListener.prototype.exitCreateTable = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#tableName.
FlinkSqlParserListener.prototype.enterTableName = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#tableName.
FlinkSqlParserListener.prototype.exitTableName = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#columnOptionDefinition.
FlinkSqlParserListener.prototype.enterColumnOptionDefinition = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#columnOptionDefinition.
FlinkSqlParserListener.prototype.exitColumnOptionDefinition = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#columnName.
FlinkSqlParserListener.prototype.enterColumnName = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#columnName.
FlinkSqlParserListener.prototype.exitColumnName = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#columnType.
FlinkSqlParserListener.prototype.enterColumnType = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#columnType.
FlinkSqlParserListener.prototype.exitColumnType = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#partitionDefinition.
FlinkSqlParserListener.prototype.enterPartitionDefinition = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#partitionDefinition.
FlinkSqlParserListener.prototype.exitPartitionDefinition = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#partitionColumnDefinition.
FlinkSqlParserListener.prototype.enterPartitionColumnDefinition = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#partitionColumnDefinition.
FlinkSqlParserListener.prototype.exitPartitionColumnDefinition = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#partitionColumnName.
FlinkSqlParserListener.prototype.enterPartitionColumnName = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#partitionColumnName.
FlinkSqlParserListener.prototype.exitPartitionColumnName = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#withOptionDefinition.
FlinkSqlParserListener.prototype.enterWithOptionDefinition = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#withOptionDefinition.
FlinkSqlParserListener.prototype.exitWithOptionDefinition = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#createDatabase.
FlinkSqlParserListener.prototype.enterCreateDatabase = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#createDatabase.
FlinkSqlParserListener.prototype.exitCreateDatabase = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#createView.
FlinkSqlParserListener.prototype.enterCreateView = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#createView.
FlinkSqlParserListener.prototype.exitCreateView = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#createFunction.
FlinkSqlParserListener.prototype.enterCreateFunction = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#createFunction.
FlinkSqlParserListener.prototype.exitCreateFunction = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#alterTable.
FlinkSqlParserListener.prototype.enterAlterTable = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#alterTable.
FlinkSqlParserListener.prototype.exitAlterTable = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#alterDatabase.
FlinkSqlParserListener.prototype.enterAlterDatabase = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#alterDatabase.
FlinkSqlParserListener.prototype.exitAlterDatabase = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#alterFunction.
FlinkSqlParserListener.prototype.enterAlterFunction = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#alterFunction.
FlinkSqlParserListener.prototype.exitAlterFunction = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#dropTable.
FlinkSqlParserListener.prototype.enterDropTable = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#dropTable.
FlinkSqlParserListener.prototype.exitDropTable = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#dropDatabase.
FlinkSqlParserListener.prototype.enterDropDatabase = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#dropDatabase.
FlinkSqlParserListener.prototype.exitDropDatabase = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#dropView.
FlinkSqlParserListener.prototype.enterDropView = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#dropView.
FlinkSqlParserListener.prototype.exitDropView = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#dropFunction.
FlinkSqlParserListener.prototype.enterDropFunction = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#dropFunction.
FlinkSqlParserListener.prototype.exitDropFunction = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#selectStatement.
FlinkSqlParserListener.prototype.enterSelectStatement = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#selectStatement.
FlinkSqlParserListener.prototype.exitSelectStatement = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#insertStatement.
FlinkSqlParserListener.prototype.enterInsertStatement = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#insertStatement.
FlinkSqlParserListener.prototype.exitInsertStatement = function(ctx) {
};
exports.FlinkSqlParserListener = FlinkSqlParserListener;

View File

@ -0,0 +1,172 @@
// Generated from /Users/erindeng/Desktop/dt-sql-parser/src/grammar/flinksql/FlinkSqlParser.g4 by ANTLR 4.8
// jshint ignore: start
var antlr4 = require('antlr4/index');
// This class defines a complete generic visitor for a parse tree produced by FlinkSqlParser.
function FlinkSqlParserVisitor() {
antlr4.tree.ParseTreeVisitor.call(this);
return this;
}
FlinkSqlParserVisitor.prototype = Object.create(antlr4.tree.ParseTreeVisitor.prototype);
FlinkSqlParserVisitor.prototype.constructor = FlinkSqlParserVisitor;
// Visit a parse tree produced by FlinkSqlParser#program.
FlinkSqlParserVisitor.prototype.visitProgram = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#statement.
FlinkSqlParserVisitor.prototype.visitStatement = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#sqlStatement.
FlinkSqlParserVisitor.prototype.visitSqlStatement = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#ddlStatement.
FlinkSqlParserVisitor.prototype.visitDdlStatement = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#dmlStatement.
FlinkSqlParserVisitor.prototype.visitDmlStatement = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#createTable.
FlinkSqlParserVisitor.prototype.visitCreateTable = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#tableName.
FlinkSqlParserVisitor.prototype.visitTableName = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#columnOptionDefinition.
FlinkSqlParserVisitor.prototype.visitColumnOptionDefinition = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#columnName.
FlinkSqlParserVisitor.prototype.visitColumnName = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#columnType.
FlinkSqlParserVisitor.prototype.visitColumnType = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#partitionDefinition.
FlinkSqlParserVisitor.prototype.visitPartitionDefinition = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#partitionColumnDefinition.
FlinkSqlParserVisitor.prototype.visitPartitionColumnDefinition = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#partitionColumnName.
FlinkSqlParserVisitor.prototype.visitPartitionColumnName = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#withOptionDefinition.
FlinkSqlParserVisitor.prototype.visitWithOptionDefinition = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#createDatabase.
FlinkSqlParserVisitor.prototype.visitCreateDatabase = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#createView.
FlinkSqlParserVisitor.prototype.visitCreateView = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#createFunction.
FlinkSqlParserVisitor.prototype.visitCreateFunction = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#alterTable.
FlinkSqlParserVisitor.prototype.visitAlterTable = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#alterDatabase.
FlinkSqlParserVisitor.prototype.visitAlterDatabase = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#alterFunction.
FlinkSqlParserVisitor.prototype.visitAlterFunction = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#dropTable.
FlinkSqlParserVisitor.prototype.visitDropTable = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#dropDatabase.
FlinkSqlParserVisitor.prototype.visitDropDatabase = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#dropView.
FlinkSqlParserVisitor.prototype.visitDropView = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#dropFunction.
FlinkSqlParserVisitor.prototype.visitDropFunction = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#selectStatement.
FlinkSqlParserVisitor.prototype.visitSelectStatement = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#insertStatement.
FlinkSqlParserVisitor.prototype.visitInsertStatement = function(ctx) {
return this.visitChildren(ctx);
};
exports.FlinkSqlParserVisitor = FlinkSqlParserVisitor;

20
src/parser/flinksql.ts Normal file
View File

@ -0,0 +1,20 @@
import { InputStream, CommonTokenStream, Lexer } from 'antlr4';
import { FlinkSqlLexer } from '../lib/flinksql/FlinkSqlLexer';
import { FlinkSqlParser } from '../lib/flinksql/FlinkSqlParser';
export * from '../lib/flinksql/FlinkSqlParserListener';
export * from '../lib/flinksql/FlinkSqlParserVisitor';
import BasicParser from './common/BasicParser';
export default class FlinkSQL extends BasicParser {
public createLexer(input: string): Lexer {
const chars = new InputStream(input);
const lexer = <unknown> new FlinkSqlLexer(chars) as Lexer;
return lexer;
}
public createParserFromLexer(lexer: Lexer) {
const tokenStream = new CommonTokenStream(lexer);
return new FlinkSqlParser(tokenStream);
}
}

View File

@ -1,3 +1,4 @@
export * from './generic'; export * from './generic';
export * from './plsql'; export * from './plsql';
export * from './hive'; export * from './hive';
export * from './flinksql';

View File

@ -0,0 +1,12 @@
import SQLParser from '../../../src/parser/flinksql';
// todo 校验 token 解析
describe('FlinkSQL Lexer tests', () => {
const parser = new SQLParser();
const sql = 'SELECT * FROM table1';
const tokens = parser.getAllTokens(sql);
test('token counts', () => {
expect(tokens.length).toBe(7);
});
});

View File

@ -0,0 +1,22 @@
import SQLParser, { PlSqlParserListener } from '../../../src/parser/plsql';
// todo 校验关键字提取
describe('PLSQL Listener Tests', () => {
const expectTableName = 'user1';
const sql = `select id,name,sex from ${expectTableName};`;
const parser = new SQLParser();
const parserTree = parser.parse(sql);
test('Listener enterTableName', async () => {
let result = '';
class MyListener extends PlSqlParserListener {
enterTable_ref_list(ctx): void {
result = ctx.getText().toLowerCase();
}
}
const listenTableName: any = new MyListener();
await parser.listen(listenTableName, parserTree);
expect(result).toBe(expectTableName);
});
});

View File

@ -0,0 +1,20 @@
import SQLParser from '../../../src/parser/flinksql';
describe('FlinkSQL Syntax Tests', () => {
const parser = new SQLParser();
test('Test simple CreateTable Statement', () => {
const sql = `
CREATE TABLE Orders (
user BIGINT,
product STRING
) WITH (
"connector" = "kafka",
"scan.startup.mode" = "earliest-offset"
);
`;
const result = parser.validate(sql);
expect(result.length).toBe(0);
});
});

View File

@ -0,0 +1,23 @@
import SQLParser, { PlSqlParserVisitor } from '../../../src/parser/plsql';
// todo 校验关键字提取
describe('PLSQL Visitor Tests', () => {
const expectTableName = 'user1';
const sql = `select id,name,sex from ${expectTableName};`;
const parser = new SQLParser();
const parserTree = parser.parse(sql);
test('Visitor visitTable_ref_list', () => {
let result = '';
class MyVisitor extends PlSqlParserVisitor {
visitTable_ref_list(ctx): void {
result = ctx.getText().toLowerCase();
super.visitTable_ref_list(ctx);
}
}
const visitor: any = new MyVisitor();
visitor.visit(parserTree);
expect(result).toBe(expectTableName);
});
});