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';
WS: 'WS';
UNRECOGNIZED: 'UNRECOGNIZED';
REVERSE_QUOTE_ID: '"' ~'"'+ '"';
REVERSE_QUOTE_ID: '`' ~'`'+ '`';
DOUBLE_QUOTE_ID: '"' ~'"'+ '"';
DOT_ID: '.' ID_LITERAL;
ID: ID_LITERAL;
SYSTEM: 'SYSTEM';
// DATA TYPE Keywords
@ -332,4 +334,4 @@ REVERSE_QUOTE_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
;
// Create statements
createTable
: CREATE TABLE tableName
: CREATE TABLE uid
LR_BRACKET
columnOptionDefinition (COMMA columnOptionDefinition)*
RR_BRACKET
partitionDefinition?
WITH LR_BRACKET
withOptionDefinition (COMMA withOptionDefinition)*
RR_BRACKET
;
tableName
: ID (DOT_ID)*?
withOption
;
columnOptionDefinition
@ -74,54 +70,118 @@ partitionColumnName
: ID
;
withOptionDefinition
: REVERSE_QUOTE_ID EQUAL_SYMBOL REVERSE_QUOTE_ID
;
createDatabase
:
: CREATE DATABASE ifNotExists? uid withOption
;
createView
:
: CREATE TEMPORARY? VIEW ifNotExists? uid AS selectStatement
;
createFunction
:
;
// Alter statements
alterTable
:
: ALTER TABLE uid (renameDefinition | setKeyValueDefinition)
;
renameDefinition
: RENAME TO uid
;
setKeyValueDefinition
: SET LR_BRACKET
keyValueDefinition (COMMA keyValueDefinition)*
RR_BRACKET
;
alterDatabase
:
: ALTER DATABASE uid setKeyValueDefinition
;
alterFunction
:
;
// Drop statements
dropTable
:
: DROP TABLE ifExists uid
;
dropDatabase
:
: DROP DATABASE ifExists uid dropType=(RESTRICT | CASCADE)?
;
dropView
:
: DROP TEMPORARY? VIEW ifExists uid
;
dropFunction
:
: DROP (TEMPORARY|TEMPORARY SYSTEM)? FUNCTION ifExists uid
;
// Select statements
selectStatement
:
;
// Insert statements
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
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_SYMBOL=283
GREATER_SYMBOL=284
LESS_SYMBOL=285
EXCLAMATION_SYMBOL=286
BIT_NOT_OP=287
BIT_OR_OP=288
BIT_AND_OP=289
BIT_XOR_OP=290
DOT=291
LR_BRACKET=292
RR_BRACKET=293
COMMA=294
SEMICOLON=295
AT_SIGN=296
ZERO_DECIMAL=297
ONE_DECIMAL=298
TWO_DECIMAL=299
SINGLE_QUOTE_SYMB=300
DOUBLE_QUOTE_SYMB=301
REVERSE_QUOTE_SYMB=302
COLON_SYMB=303
DOUBLE_QUOTE_ID=258
DOT_ID=259
ID=260
SYSTEM=261
STRING=262
ARRAY=263
MAP=264
CHAR=265
VARCHAR=266
BINARY=267
VARBINARY=268
BYTES=269
DECIMAL=270
TINYINT=271
SMALLINT=272
INT=273
BIGINT=274
FLOAT=275
DOUBLE=276
DATE=277
TIME=278
TIMESTAMP=279
MULTISET=280
BOOLEAN=281
RAW=282
ROW=283
NULL=284
EQUAL_SYMBOL=285
GREATER_SYMBOL=286
LESS_SYMBOL=287
EXCLAMATION_SYMBOL=288
BIT_NOT_OP=289
BIT_OR_OP=290
BIT_AND_OP=291
BIT_XOR_OP=292
DOT=293
LR_BRACKET=294
RR_BRACKET=295
COMMA=296
SEMICOLON=297
AT_SIGN=298
ZERO_DECIMAL=299
ONE_DECIMAL=300
TWO_DECIMAL=301
SINGLE_QUOTE_SYMB=302
DOUBLE_QUOTE_SYMB=303
REVERSE_QUOTE_SYMB=304
COLON_SYMB=305
'SELECT'=5
'FROM'=6
'ADD'=7
@ -553,47 +555,48 @@ COLON_SYMB=303
'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
'<'=285
'!'=286
'~'=287
'|'=288
'&'=289
'^'=290
'.'=291
'('=292
')'=293
','=294
';'=295
'@'=296
'0'=297
'1'=298
'2'=299
'\''=300
'"'=301
'`'=302
':'=303
'SYSTEM'=261
'STRING'=262
'ARRAY'=263
'MAP'=264
'CHAR'=265
'VARCHAR'=266
'BINARY'=267
'VARBINARY'=268
'BYTES'=269
'DECIMAL'=270
'TINYINT'=271
'SMALLINT'=272
'INT'=273
'BIGINT'=274
'FLOAT'=275
'DOUBLE'=276
'DATE'=277
'TIME'=278
'TIMESTAMP'=279
'MULTISET'=280
'BOOLEAN'=281
'RAW'=282
'ROW'=283
'NULL'=284
'='=285
'>'=286
'<'=287
'!'=288
'~'=289
'|'=290
'&'=291
'^'=292
'.'=293
'('=294
')'=295
','=296
';'=297
'@'=298
'0'=299
'1'=300
'2'=301
'\''=302
'"'=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
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_SYMBOL=283
GREATER_SYMBOL=284
LESS_SYMBOL=285
EXCLAMATION_SYMBOL=286
BIT_NOT_OP=287
BIT_OR_OP=288
BIT_AND_OP=289
BIT_XOR_OP=290
DOT=291
LR_BRACKET=292
RR_BRACKET=293
COMMA=294
SEMICOLON=295
AT_SIGN=296
ZERO_DECIMAL=297
ONE_DECIMAL=298
TWO_DECIMAL=299
SINGLE_QUOTE_SYMB=300
DOUBLE_QUOTE_SYMB=301
REVERSE_QUOTE_SYMB=302
COLON_SYMB=303
DOUBLE_QUOTE_ID=258
DOT_ID=259
ID=260
SYSTEM=261
STRING=262
ARRAY=263
MAP=264
CHAR=265
VARCHAR=266
BINARY=267
VARBINARY=268
BYTES=269
DECIMAL=270
TINYINT=271
SMALLINT=272
INT=273
BIGINT=274
FLOAT=275
DOUBLE=276
DATE=277
TIME=278
TIMESTAMP=279
MULTISET=280
BOOLEAN=281
RAW=282
ROW=283
NULL=284
EQUAL_SYMBOL=285
GREATER_SYMBOL=286
LESS_SYMBOL=287
EXCLAMATION_SYMBOL=288
BIT_NOT_OP=289
BIT_OR_OP=290
BIT_AND_OP=291
BIT_XOR_OP=292
DOT=293
LR_BRACKET=294
RR_BRACKET=295
COMMA=296
SEMICOLON=297
AT_SIGN=298
ZERO_DECIMAL=299
ONE_DECIMAL=300
TWO_DECIMAL=301
SINGLE_QUOTE_SYMB=302
DOUBLE_QUOTE_SYMB=303
REVERSE_QUOTE_SYMB=304
COLON_SYMB=305
'SELECT'=5
'FROM'=6
'ADD'=7
@ -553,47 +555,48 @@ COLON_SYMB=303
'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
'<'=285
'!'=286
'~'=287
'|'=288
'&'=289
'^'=290
'.'=291
'('=292
')'=293
','=294
';'=295
'@'=296
'0'=297
'1'=298
'2'=299
'\''=300
'"'=301
'`'=302
':'=303
'SYSTEM'=261
'STRING'=262
'ARRAY'=263
'MAP'=264
'CHAR'=265
'VARCHAR'=266
'BINARY'=267
'VARBINARY'=268
'BYTES'=269
'DECIMAL'=270
'TINYINT'=271
'SMALLINT'=272
'INT'=273
'BIGINT'=274
'FLOAT'=275
'DOUBLE'=276
'DATE'=277
'TIME'=278
'TIMESTAMP'=279
'MULTISET'=280
'BOOLEAN'=281
'RAW'=282
'ROW'=283
'NULL'=284
'='=285
'>'=286
'<'=287
'!'=288
'~'=289
'|'=290
'&'=291
'^'=292
'.'=293
'('=294
')'=295
','=296
';'=297
'@'=298
'0'=299
'1'=300
'2'=301
'\''=302
'"'=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.
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.
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.
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;

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.
FlinkSqlParserVisitor.prototype.visitColumnOptionDefinition = function(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.
FlinkSqlParserVisitor.prototype.visitCreateDatabase = function(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.
FlinkSqlParserVisitor.prototype.visitAlterDatabase = function(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;