feat(flink): add inset\drop\alter grammar

This commit is contained in:
Erindcl 2020-10-28 16:15:41 +08:00
parent 6082c2b151
commit 158e235b01
10 changed files with 3977 additions and 2438 deletions

View File

@ -267,9 +267,11 @@ BRACKETED_EMPTY_COMMENT: 'BRACKETED_EMPTY_COMMENT';
BRACKETED_COMMENT: 'BRACKETED_COMMENT'; BRACKETED_COMMENT: 'BRACKETED_COMMENT';
WS: 'WS'; WS: 'WS';
UNRECOGNIZED: 'UNRECOGNIZED'; UNRECOGNIZED: 'UNRECOGNIZED';
REVERSE_QUOTE_ID: '"' ~'"'+ '"'; REVERSE_QUOTE_ID: '`' ~'`'+ '`';
DOUBLE_QUOTE_ID: '"' ~'"'+ '"';
DOT_ID: '.' ID_LITERAL; DOT_ID: '.' ID_LITERAL;
ID: ID_LITERAL; ID: ID_LITERAL;
SYSTEM: 'SYSTEM';
// DATA TYPE Keywords // DATA TYPE Keywords
@ -332,4 +334,4 @@ REVERSE_QUOTE_SYMB: '`';
COLON_SYMB: ':'; COLON_SYMB: ':';
fragment ID_LITERAL: [A-Z_0-9a-z]*?[A-Z_a-z]+?[A-Z_0-9a-z]*; fragment ID_LITERAL: [A-Z_0-9a-z]*?[A-Z_a-z]+?[A-Z_0-9a-z]*;

View File

@ -30,20 +30,16 @@ dmlStatement
: selectStatement | insertStatement : selectStatement | insertStatement
; ;
// Create statements
createTable createTable
: CREATE TABLE tableName : CREATE TABLE uid
LR_BRACKET LR_BRACKET
columnOptionDefinition (COMMA columnOptionDefinition)* columnOptionDefinition (COMMA columnOptionDefinition)*
RR_BRACKET RR_BRACKET
partitionDefinition? partitionDefinition?
WITH LR_BRACKET withOption
withOptionDefinition (COMMA withOptionDefinition)*
RR_BRACKET
;
tableName
: ID (DOT_ID)*?
; ;
columnOptionDefinition columnOptionDefinition
@ -74,54 +70,118 @@ partitionColumnName
: ID : ID
; ;
withOptionDefinition
: REVERSE_QUOTE_ID EQUAL_SYMBOL REVERSE_QUOTE_ID
;
createDatabase createDatabase
: : CREATE DATABASE ifNotExists? uid withOption
; ;
createView createView
: : CREATE TEMPORARY? VIEW ifNotExists? uid AS selectStatement
; ;
createFunction createFunction
: :
; ;
// Alter statements
alterTable alterTable
: : ALTER TABLE uid (renameDefinition | setKeyValueDefinition)
;
renameDefinition
: RENAME TO uid
;
setKeyValueDefinition
: SET LR_BRACKET
keyValueDefinition (COMMA keyValueDefinition)*
RR_BRACKET
; ;
alterDatabase alterDatabase
: : ALTER DATABASE uid setKeyValueDefinition
; ;
alterFunction alterFunction
: :
; ;
// Drop statements
dropTable dropTable
: : DROP TABLE ifExists uid
; ;
dropDatabase dropDatabase
: : DROP DATABASE ifExists uid dropType=(RESTRICT | CASCADE)?
; ;
dropView dropView
: : DROP TEMPORARY? VIEW ifExists uid
; ;
dropFunction dropFunction
: : DROP (TEMPORARY|TEMPORARY SYSTEM)? FUNCTION ifExists uid
; ;
// Select statements
selectStatement selectStatement
: :
; ;
// Insert statements
insertStatement insertStatement
: : INSERT (INTO | OVERWRITE) uid
(
insertPartitionDefinition? selectStatement
| valuesDefinition
)
;
insertPartitionDefinition
: PARTITION LR_BRACKET
keyValueDefinition (COMMA keyValueDefinition)*
RR_BRACKET
;
valuesDefinition
: VALUES valuesRowDefinition (COMMA valuesRowDefinition)*
;
// TODO 匹配所有的值 任意value
valuesRowDefinition
: LR_BRACKET
.*?
RR_BRACKET
;
// base common
uidList
: uid (',' uid)*
;
uid
: ID (DOT_ID)*?
;
withOption
: WITH LR_BRACKET
keyValueDefinition (COMMA keyValueDefinition)*
RR_BRACKET
;
ifNotExists
: IF NOT EXISTS;
ifExists
: IF EXISTS;
keyValueDefinition
: DOUBLE_QUOTE_ID EQUAL_SYMBOL DOUBLE_QUOTE_ID
; ;

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -255,52 +255,54 @@ BRACKETED_COMMENT=254
WS=255 WS=255
UNRECOGNIZED=256 UNRECOGNIZED=256
REVERSE_QUOTE_ID=257 REVERSE_QUOTE_ID=257
DOT_ID=258 DOUBLE_QUOTE_ID=258
ID=259 DOT_ID=259
STRING=260 ID=260
ARRAY=261 SYSTEM=261
MAP=262 STRING=262
CHAR=263 ARRAY=263
VARCHAR=264 MAP=264
BINARY=265 CHAR=265
VARBINARY=266 VARCHAR=266
BYTES=267 BINARY=267
DECIMAL=268 VARBINARY=268
TINYINT=269 BYTES=269
SMALLINT=270 DECIMAL=270
INT=271 TINYINT=271
BIGINT=272 SMALLINT=272
FLOAT=273 INT=273
DOUBLE=274 BIGINT=274
DATE=275 FLOAT=275
TIME=276 DOUBLE=276
TIMESTAMP=277 DATE=277
MULTISET=278 TIME=278
BOOLEAN=279 TIMESTAMP=279
RAW=280 MULTISET=280
ROW=281 BOOLEAN=281
NULL=282 RAW=282
EQUAL_SYMBOL=283 ROW=283
GREATER_SYMBOL=284 NULL=284
LESS_SYMBOL=285 EQUAL_SYMBOL=285
EXCLAMATION_SYMBOL=286 GREATER_SYMBOL=286
BIT_NOT_OP=287 LESS_SYMBOL=287
BIT_OR_OP=288 EXCLAMATION_SYMBOL=288
BIT_AND_OP=289 BIT_NOT_OP=289
BIT_XOR_OP=290 BIT_OR_OP=290
DOT=291 BIT_AND_OP=291
LR_BRACKET=292 BIT_XOR_OP=292
RR_BRACKET=293 DOT=293
COMMA=294 LR_BRACKET=294
SEMICOLON=295 RR_BRACKET=295
AT_SIGN=296 COMMA=296
ZERO_DECIMAL=297 SEMICOLON=297
ONE_DECIMAL=298 AT_SIGN=298
TWO_DECIMAL=299 ZERO_DECIMAL=299
SINGLE_QUOTE_SYMB=300 ONE_DECIMAL=300
DOUBLE_QUOTE_SYMB=301 TWO_DECIMAL=301
REVERSE_QUOTE_SYMB=302 SINGLE_QUOTE_SYMB=302
COLON_SYMB=303 DOUBLE_QUOTE_SYMB=303
REVERSE_QUOTE_SYMB=304
COLON_SYMB=305
'SELECT'=5 'SELECT'=5
'FROM'=6 'FROM'=6
'ADD'=7 'ADD'=7
@ -553,47 +555,48 @@ COLON_SYMB=303
'BRACKETED_COMMENT'=254 'BRACKETED_COMMENT'=254
'WS'=255 'WS'=255
'UNRECOGNIZED'=256 'UNRECOGNIZED'=256
'STRING'=260 'SYSTEM'=261
'ARRAY'=261 'STRING'=262
'MAP'=262 'ARRAY'=263
'CHAR'=263 'MAP'=264
'VARCHAR'=264 'CHAR'=265
'BINARY'=265 'VARCHAR'=266
'VARBINARY'=266 'BINARY'=267
'BYTES'=267 'VARBINARY'=268
'DECIMAL'=268 'BYTES'=269
'TINYINT'=269 'DECIMAL'=270
'SMALLINT'=270 'TINYINT'=271
'INT'=271 'SMALLINT'=272
'BIGINT'=272 'INT'=273
'FLOAT'=273 'BIGINT'=274
'DOUBLE'=274 'FLOAT'=275
'DATE'=275 'DOUBLE'=276
'TIME'=276 'DATE'=277
'TIMESTAMP'=277 'TIME'=278
'MULTISET'=278 'TIMESTAMP'=279
'BOOLEAN'=279 'MULTISET'=280
'RAW'=280 'BOOLEAN'=281
'ROW'=281 'RAW'=282
'NULL'=282 'ROW'=283
'='=283 'NULL'=284
'>'=284 '='=285
'<'=285 '>'=286
'!'=286 '<'=287
'~'=287 '!'=288
'|'=288 '~'=289
'&'=289 '|'=290
'^'=290 '&'=291
'.'=291 '^'=292
'('=292 '.'=293
')'=293 '('=294
','=294 ')'=295
';'=295 ','=296
'@'=296 ';'=297
'0'=297 '@'=298
'1'=298 '0'=299
'2'=299 '1'=300
'\''=300 '2'=301
'"'=301 '\''=302
'`'=302 '"'=303
':'=303 '`'=304
':'=305

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -255,52 +255,54 @@ BRACKETED_COMMENT=254
WS=255 WS=255
UNRECOGNIZED=256 UNRECOGNIZED=256
REVERSE_QUOTE_ID=257 REVERSE_QUOTE_ID=257
DOT_ID=258 DOUBLE_QUOTE_ID=258
ID=259 DOT_ID=259
STRING=260 ID=260
ARRAY=261 SYSTEM=261
MAP=262 STRING=262
CHAR=263 ARRAY=263
VARCHAR=264 MAP=264
BINARY=265 CHAR=265
VARBINARY=266 VARCHAR=266
BYTES=267 BINARY=267
DECIMAL=268 VARBINARY=268
TINYINT=269 BYTES=269
SMALLINT=270 DECIMAL=270
INT=271 TINYINT=271
BIGINT=272 SMALLINT=272
FLOAT=273 INT=273
DOUBLE=274 BIGINT=274
DATE=275 FLOAT=275
TIME=276 DOUBLE=276
TIMESTAMP=277 DATE=277
MULTISET=278 TIME=278
BOOLEAN=279 TIMESTAMP=279
RAW=280 MULTISET=280
ROW=281 BOOLEAN=281
NULL=282 RAW=282
EQUAL_SYMBOL=283 ROW=283
GREATER_SYMBOL=284 NULL=284
LESS_SYMBOL=285 EQUAL_SYMBOL=285
EXCLAMATION_SYMBOL=286 GREATER_SYMBOL=286
BIT_NOT_OP=287 LESS_SYMBOL=287
BIT_OR_OP=288 EXCLAMATION_SYMBOL=288
BIT_AND_OP=289 BIT_NOT_OP=289
BIT_XOR_OP=290 BIT_OR_OP=290
DOT=291 BIT_AND_OP=291
LR_BRACKET=292 BIT_XOR_OP=292
RR_BRACKET=293 DOT=293
COMMA=294 LR_BRACKET=294
SEMICOLON=295 RR_BRACKET=295
AT_SIGN=296 COMMA=296
ZERO_DECIMAL=297 SEMICOLON=297
ONE_DECIMAL=298 AT_SIGN=298
TWO_DECIMAL=299 ZERO_DECIMAL=299
SINGLE_QUOTE_SYMB=300 ONE_DECIMAL=300
DOUBLE_QUOTE_SYMB=301 TWO_DECIMAL=301
REVERSE_QUOTE_SYMB=302 SINGLE_QUOTE_SYMB=302
COLON_SYMB=303 DOUBLE_QUOTE_SYMB=303
REVERSE_QUOTE_SYMB=304
COLON_SYMB=305
'SELECT'=5 'SELECT'=5
'FROM'=6 'FROM'=6
'ADD'=7 'ADD'=7
@ -553,47 +555,48 @@ COLON_SYMB=303
'BRACKETED_COMMENT'=254 'BRACKETED_COMMENT'=254
'WS'=255 'WS'=255
'UNRECOGNIZED'=256 'UNRECOGNIZED'=256
'STRING'=260 'SYSTEM'=261
'ARRAY'=261 'STRING'=262
'MAP'=262 'ARRAY'=263
'CHAR'=263 'MAP'=264
'VARCHAR'=264 'CHAR'=265
'BINARY'=265 'VARCHAR'=266
'VARBINARY'=266 'BINARY'=267
'BYTES'=267 'VARBINARY'=268
'DECIMAL'=268 'BYTES'=269
'TINYINT'=269 'DECIMAL'=270
'SMALLINT'=270 'TINYINT'=271
'INT'=271 'SMALLINT'=272
'BIGINT'=272 'INT'=273
'FLOAT'=273 'BIGINT'=274
'DOUBLE'=274 'FLOAT'=275
'DATE'=275 'DOUBLE'=276
'TIME'=276 'DATE'=277
'TIMESTAMP'=277 'TIME'=278
'MULTISET'=278 'TIMESTAMP'=279
'BOOLEAN'=279 'MULTISET'=280
'RAW'=280 'BOOLEAN'=281
'ROW'=281 'RAW'=282
'NULL'=282 'ROW'=283
'='=283 'NULL'=284
'>'=284 '='=285
'<'=285 '>'=286
'!'=286 '<'=287
'~'=287 '!'=288
'|'=288 '~'=289
'&'=289 '|'=290
'^'=290 '&'=291
'.'=291 '^'=292
'('=292 '.'=293
')'=293 '('=294
','=294 ')'=295
';'=295 ','=296
'@'=296 ';'=297
'0'=297 '@'=298
'1'=298 '0'=299
'2'=299 '1'=300
'\''=300 '2'=301
'"'=301 '\''=302
'`'=302 '"'=303
':'=303 '`'=304
':'=305

View File

@ -83,15 +83,6 @@ 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. // Enter a parse tree produced by FlinkSqlParser#columnOptionDefinition.
FlinkSqlParserListener.prototype.enterColumnOptionDefinition = function(ctx) { FlinkSqlParserListener.prototype.enterColumnOptionDefinition = function(ctx) {
}; };
@ -146,15 +137,6 @@ 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. // Enter a parse tree produced by FlinkSqlParser#createDatabase.
FlinkSqlParserListener.prototype.enterCreateDatabase = function(ctx) { FlinkSqlParserListener.prototype.enterCreateDatabase = function(ctx) {
}; };
@ -191,6 +173,24 @@ FlinkSqlParserListener.prototype.exitAlterTable = function(ctx) {
}; };
// Enter a parse tree produced by FlinkSqlParser#renameDefinition.
FlinkSqlParserListener.prototype.enterRenameDefinition = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#renameDefinition.
FlinkSqlParserListener.prototype.exitRenameDefinition = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#setKeyValueDefinition.
FlinkSqlParserListener.prototype.enterSetKeyValueDefinition = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#setKeyValueDefinition.
FlinkSqlParserListener.prototype.exitSetKeyValueDefinition = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#alterDatabase. // Enter a parse tree produced by FlinkSqlParser#alterDatabase.
FlinkSqlParserListener.prototype.enterAlterDatabase = function(ctx) { FlinkSqlParserListener.prototype.enterAlterDatabase = function(ctx) {
}; };
@ -263,5 +263,86 @@ FlinkSqlParserListener.prototype.exitInsertStatement = function(ctx) {
}; };
// Enter a parse tree produced by FlinkSqlParser#insertPartitionDefinition.
FlinkSqlParserListener.prototype.enterInsertPartitionDefinition = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#insertPartitionDefinition.
FlinkSqlParserListener.prototype.exitInsertPartitionDefinition = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#valuesDefinition.
FlinkSqlParserListener.prototype.enterValuesDefinition = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#valuesDefinition.
FlinkSqlParserListener.prototype.exitValuesDefinition = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#valuesRowDefinition.
FlinkSqlParserListener.prototype.enterValuesRowDefinition = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#valuesRowDefinition.
FlinkSqlParserListener.prototype.exitValuesRowDefinition = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#uidList.
FlinkSqlParserListener.prototype.enterUidList = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#uidList.
FlinkSqlParserListener.prototype.exitUidList = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#uid.
FlinkSqlParserListener.prototype.enterUid = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#uid.
FlinkSqlParserListener.prototype.exitUid = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#withOption.
FlinkSqlParserListener.prototype.enterWithOption = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#withOption.
FlinkSqlParserListener.prototype.exitWithOption = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#ifNotExists.
FlinkSqlParserListener.prototype.enterIfNotExists = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#ifNotExists.
FlinkSqlParserListener.prototype.exitIfNotExists = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#ifExists.
FlinkSqlParserListener.prototype.enterIfExists = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#ifExists.
FlinkSqlParserListener.prototype.exitIfExists = function(ctx) {
};
// Enter a parse tree produced by FlinkSqlParser#keyValueDefinition.
FlinkSqlParserListener.prototype.enterKeyValueDefinition = function(ctx) {
};
// Exit a parse tree produced by FlinkSqlParser#keyValueDefinition.
FlinkSqlParserListener.prototype.exitKeyValueDefinition = function(ctx) {
};
exports.FlinkSqlParserListener = FlinkSqlParserListener; exports.FlinkSqlParserListener = FlinkSqlParserListener;

View File

@ -60,12 +60,6 @@ FlinkSqlParserVisitor.prototype.visitCreateTable = function(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. // Visit a parse tree produced by FlinkSqlParser#columnOptionDefinition.
FlinkSqlParserVisitor.prototype.visitColumnOptionDefinition = function(ctx) { FlinkSqlParserVisitor.prototype.visitColumnOptionDefinition = function(ctx) {
return this.visitChildren(ctx); return this.visitChildren(ctx);
@ -102,12 +96,6 @@ FlinkSqlParserVisitor.prototype.visitPartitionColumnName = function(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. // Visit a parse tree produced by FlinkSqlParser#createDatabase.
FlinkSqlParserVisitor.prototype.visitCreateDatabase = function(ctx) { FlinkSqlParserVisitor.prototype.visitCreateDatabase = function(ctx) {
return this.visitChildren(ctx); return this.visitChildren(ctx);
@ -132,6 +120,18 @@ FlinkSqlParserVisitor.prototype.visitAlterTable = function(ctx) {
}; };
// Visit a parse tree produced by FlinkSqlParser#renameDefinition.
FlinkSqlParserVisitor.prototype.visitRenameDefinition = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#setKeyValueDefinition.
FlinkSqlParserVisitor.prototype.visitSetKeyValueDefinition = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#alterDatabase. // Visit a parse tree produced by FlinkSqlParser#alterDatabase.
FlinkSqlParserVisitor.prototype.visitAlterDatabase = function(ctx) { FlinkSqlParserVisitor.prototype.visitAlterDatabase = function(ctx) {
return this.visitChildren(ctx); return this.visitChildren(ctx);
@ -180,5 +180,59 @@ FlinkSqlParserVisitor.prototype.visitInsertStatement = function(ctx) {
}; };
// Visit a parse tree produced by FlinkSqlParser#insertPartitionDefinition.
FlinkSqlParserVisitor.prototype.visitInsertPartitionDefinition = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#valuesDefinition.
FlinkSqlParserVisitor.prototype.visitValuesDefinition = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#valuesRowDefinition.
FlinkSqlParserVisitor.prototype.visitValuesRowDefinition = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#uidList.
FlinkSqlParserVisitor.prototype.visitUidList = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#uid.
FlinkSqlParserVisitor.prototype.visitUid = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#withOption.
FlinkSqlParserVisitor.prototype.visitWithOption = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#ifNotExists.
FlinkSqlParserVisitor.prototype.visitIfNotExists = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#ifExists.
FlinkSqlParserVisitor.prototype.visitIfExists = function(ctx) {
return this.visitChildren(ctx);
};
// Visit a parse tree produced by FlinkSqlParser#keyValueDefinition.
FlinkSqlParserVisitor.prototype.visitKeyValueDefinition = function(ctx) {
return this.visitChildren(ctx);
};
exports.FlinkSqlParserVisitor = FlinkSqlParserVisitor; exports.FlinkSqlParserVisitor = FlinkSqlParserVisitor;