Feat/flink grammar (#73)
* feat: complete flink sql insert statement * feat: complete flink sql drop statement * feat: complete flink sql alert statement * feat: complete flink sql create statement, remove console log * feat: complete flink sql describe, show, explain, use statement * feat(flinksql): add statement, such as set, load * fix(flinksql): fix insert, add temporary table
This commit is contained in:
parent
11915b155d
commit
4f02f9aca0
@ -51,6 +51,7 @@ CASE: 'CASE';
|
||||
WHEN: 'WHEN';
|
||||
THEN: 'THEN';
|
||||
ELSE: 'ELSE';
|
||||
BEGIN: 'BEGIN';
|
||||
END: 'END';
|
||||
JOIN: 'JOIN';
|
||||
CROSS: 'CROSS';
|
||||
@ -60,6 +61,7 @@ LEFT: 'LEFT';
|
||||
SEMI: 'SEMI';
|
||||
RIGHT: 'RIGHT';
|
||||
FULL: 'FULL';
|
||||
USER: 'USER';
|
||||
NATURAL: 'NATURAL';
|
||||
ON: 'ON';
|
||||
PIVOT: 'PIVOT';
|
||||
@ -83,11 +85,18 @@ TABLE: 'TABLE';
|
||||
DIRECTORY: 'DIRECTORY';
|
||||
VIEW: 'VIEW';
|
||||
REPLACE: 'REPLACE';
|
||||
EXECUTE: 'EXECUTE';
|
||||
STATEMENT: 'STATEMENT';
|
||||
INSERT: 'INSERT';
|
||||
DELETE: 'DELETE';
|
||||
REMOVE: 'REMOVE';
|
||||
INTO: 'INTO';
|
||||
DESCRIBE: 'DESCRIBE';
|
||||
EXPLAIN: 'EXPLAIN';
|
||||
PLAN: 'PLAN';
|
||||
CHANGELOG_MODE: 'CHANGELOG_MODE';
|
||||
JSON_EXECUTION_PLAN: 'JSON_EXECUTION_PLAN';
|
||||
ESTIMATED_COST: 'ESTIMATED_COST';
|
||||
FORMAT: 'FORMAT';
|
||||
LOGICAL: 'LOGICAL';
|
||||
CODEGEN: 'CODEGEN';
|
||||
@ -98,6 +107,8 @@ TABLES: 'TABLES';
|
||||
COLUMNS: 'COLUMNS';
|
||||
COLUMN: 'COLUMN';
|
||||
USE: 'USE';
|
||||
MODULE: 'MODULE';
|
||||
MODULES: 'MODULES';
|
||||
PARTITIONS: 'PARTITIONS';
|
||||
FUNCTIONS: 'FUNCTIONS';
|
||||
DROP: 'DROP';
|
||||
@ -209,6 +220,7 @@ RECOVER: 'RECOVER';
|
||||
EXPORT: 'EXPORT';
|
||||
IMPORT: 'IMPORT';
|
||||
LOAD: 'LOAD';
|
||||
UNLOAD: 'UNLOAD';
|
||||
ROLE: 'ROLE';
|
||||
ROLES: 'ROLES';
|
||||
COMPACTIONS: 'COMPACTIONS';
|
||||
@ -236,8 +248,13 @@ GENERATED: 'GENERATED';
|
||||
WATERMARKS: 'WATERMARKS';
|
||||
CATALOG: 'CATALOG';
|
||||
LANGUAGE: 'LANGUAGE';
|
||||
JAVA: 'JAVA';
|
||||
SCALA: 'SCALA';
|
||||
PYTHON: 'PYTHON';
|
||||
JAR: 'JAR';
|
||||
CATALOGS: 'CATALOGS';
|
||||
VIEWS: 'VIEWS';
|
||||
JARS: 'JARS';
|
||||
PRIMARY: 'PRIMARY';
|
||||
KEY: 'KEY';
|
||||
PERIOD: 'PERIOD';
|
||||
@ -329,6 +346,7 @@ BIT_STRING: BIT_STRING_L;
|
||||
ID_LITERAL: ID_LITERAL_FRAG;
|
||||
PLUS_ID_LITERAL: PLUS_ID_LITERAL_FRAG;
|
||||
|
||||
fragment JAR_FILE_PARTTARN: '`' ( '\\'. | '``' | ~('`'|'\\'))* '`';
|
||||
fragment EXPONENT_NUM_PART: 'E' [-+]? DEC_DIGIT+;
|
||||
fragment ID_LITERAL_FRAG: [A-Z_0-9a-z]*?[A-Z_a-z]+?[A-Z_0-9a-z]*;
|
||||
fragment PLUS_ID_LITERAL_FRAG: [A-Z_0-9a-z*@#^$%&{}]*?[A-Z_a-z*@#^$%&{}]+?[A-Z_0-9a-z*@#^$%&{}]*;
|
||||
|
@ -14,6 +14,7 @@ sqlStatements
|
||||
|
||||
sqlStatement
|
||||
: ddlStatement | dmlStatement | describeStatement | explainStatement | useStatement | showStatememt
|
||||
| loadStatement | unloadStatememt | setStatememt | resetStatememt | jarStatememt
|
||||
;
|
||||
|
||||
emptyStatement
|
||||
@ -22,35 +23,77 @@ emptyStatement
|
||||
|
||||
ddlStatement
|
||||
: createTable | createDatabase | createView | createFunction | createCatalog
|
||||
| alterTable | alterDatabase | alterFunction
|
||||
| dropTable | dropDatabase | dropView | dropFunction
|
||||
| alterTable | alertView | alterDatabase | alterFunction
|
||||
| dropCatalog | dropTable | dropDatabase | dropView | dropFunction
|
||||
;
|
||||
|
||||
dmlStatement
|
||||
: queryStatement | insertStatement
|
||||
;
|
||||
|
||||
// some statemen
|
||||
describeStatement
|
||||
: DESCRIBE uid
|
||||
: (DESCRIBE | DESC) uid
|
||||
;
|
||||
|
||||
explainStatement
|
||||
: EXPLAIN identifier FOR dmlStatement
|
||||
: EXPLAIN (explainDetails | PLAN FOR)? (dmlStatement | insertSimpleStatement | insertMulStatement)
|
||||
;
|
||||
|
||||
explainDetails
|
||||
: explainDetail (COMMA explainDetail)*
|
||||
;
|
||||
|
||||
explainDetail
|
||||
: CHANGELOG_MODE | JSON_EXECUTION_PLAN | ESTIMATED_COST
|
||||
;
|
||||
|
||||
useStatement
|
||||
: USE CATALOG? uid
|
||||
: USE CATALOG? uid | useModuleStatement
|
||||
;
|
||||
|
||||
useModuleStatement
|
||||
: USE MODULES uid (COMMA uid)*
|
||||
;
|
||||
|
||||
showStatememt
|
||||
: SHOW (CATALOGS | DATABASES | TABLES | FUNCTIONS | VIEWS)
|
||||
: SHOW (CATALOGS | DATABASES | VIEWS | JARS)
|
||||
| SHOW CURRENT (CATALOG | DATABASE)
|
||||
| SHOW TABLES (( FROM | IN ) uid)? likePredicate?
|
||||
| SHOW COLUMNS ( FROM | IN ) uid likePredicate?
|
||||
| SHOW CREATE (TABLE | VIEW) uid
|
||||
| SHOW USER? FUNCTIONS
|
||||
| SHOW FULL? MODULES
|
||||
;
|
||||
|
||||
loadStatement
|
||||
: LOAD MODULE uid (WITH tablePropertyList)?
|
||||
;
|
||||
|
||||
unloadStatememt
|
||||
: UNLOAD MODULE uid
|
||||
;
|
||||
|
||||
setStatememt
|
||||
: SET (tableProperty)?
|
||||
;
|
||||
|
||||
resetStatememt
|
||||
: RESET tablePropertyKey?
|
||||
;
|
||||
|
||||
jarStatememt
|
||||
: (ADD | REMOVE) JAR jarFileName
|
||||
;
|
||||
|
||||
// Create statements
|
||||
|
||||
createTable
|
||||
: CREATE TABLE ifNotExists? sourceTable
|
||||
: (simpleCreateTable | createTableAsSelect)
|
||||
;
|
||||
|
||||
simpleCreateTable
|
||||
: CREATE TEMPORARY? TABLE ifNotExists? sourceTable
|
||||
LR_BRACKET
|
||||
columnOptionDefinition (COMMA columnOptionDefinition)*
|
||||
(COMMA watermarkDefinition)?
|
||||
@ -63,6 +106,14 @@ createTable
|
||||
likeDefinition?
|
||||
;
|
||||
|
||||
/*
|
||||
* 详见 https://nightlies.apache.org/flink/flink-docs-release-1.16/docs/dev/table/sql/create/#as-select_statement
|
||||
* CTAS 不支持指定显示指定列,不支持创建分区表,临时表
|
||||
*/
|
||||
createTableAsSelect
|
||||
: CREATE TABLE ifNotExists? sourceTable withOption (AS queryStatement)?
|
||||
;
|
||||
|
||||
columnOptionDefinition
|
||||
: physicalColumnDefinition
|
||||
| metadataColumnDefinition
|
||||
@ -204,7 +255,15 @@ createView
|
||||
;
|
||||
|
||||
createFunction
|
||||
: CREATE (TEMPORARY|TEMPORARY SYSTEM) FUNCTION ifNotExists? uid AS identifier (LANGUAGE identifier)?
|
||||
: CREATE (TEMPORARY|TEMPORARY SYSTEM)? FUNCTION ifNotExists? uid AS identifier (LANGUAGE (JAVA|SCALA|PYTHON))? usingClause?
|
||||
;
|
||||
|
||||
usingClause
|
||||
: USING JAR jarFileName (COMMA JAR jarFileName)*
|
||||
;
|
||||
|
||||
jarFileName
|
||||
: STRING_LITERAL
|
||||
;
|
||||
|
||||
// Alter statements
|
||||
@ -221,19 +280,27 @@ setKeyValueDefinition
|
||||
: SET tablePropertyList
|
||||
;
|
||||
|
||||
alertView
|
||||
: ALTER VIEW uid (renameDefinition | AS queryStatement)
|
||||
;
|
||||
|
||||
alterDatabase
|
||||
: ALTER DATABASE uid setKeyValueDefinition
|
||||
;
|
||||
|
||||
alterFunction
|
||||
: ALTER (TEMPORARY|TEMPORARY SYSTEM) FUNCTION ifExists? uid AS identifier (LANGUAGE identifier)?
|
||||
: ALTER (TEMPORARY|TEMPORARY SYSTEM)? FUNCTION ifExists? uid AS identifier (LANGUAGE (JAVA|SCALA|PYTHON))?
|
||||
;
|
||||
|
||||
|
||||
// Drop statements
|
||||
|
||||
dropCatalog
|
||||
: DROP CATALOG ifExists? uid
|
||||
;
|
||||
|
||||
dropTable
|
||||
: DROP TABLE ifExists? uid
|
||||
: DROP TEMPORARY? TABLE ifExists? uid
|
||||
;
|
||||
|
||||
dropDatabase
|
||||
@ -252,9 +319,13 @@ dropFunction
|
||||
// Insert statements
|
||||
|
||||
insertStatement
|
||||
: (EXECUTE? insertSimpleStatement) | insertMulStatementCompatibility | (EXECUTE insertMulStatement)
|
||||
;
|
||||
|
||||
insertSimpleStatement
|
||||
: INSERT (INTO | OVERWRITE) uid
|
||||
(
|
||||
insertPartitionDefinition? queryStatement
|
||||
insertPartitionDefinition? insertColumnListDefinition? queryStatement
|
||||
| valuesDefinition
|
||||
)
|
||||
;
|
||||
@ -263,6 +334,10 @@ insertPartitionDefinition
|
||||
: PARTITION tablePropertyList
|
||||
;
|
||||
|
||||
insertColumnListDefinition
|
||||
: LR_BRACKET columnNameList RR_BRACKET
|
||||
;
|
||||
|
||||
valuesDefinition
|
||||
: VALUES valuesRowDefinition (COMMA valuesRowDefinition)*
|
||||
;
|
||||
@ -273,6 +348,14 @@ valuesRowDefinition
|
||||
RR_BRACKET
|
||||
;
|
||||
|
||||
insertMulStatementCompatibility
|
||||
: BEGIN STATEMENT SET SEMICOLON (insertSimpleStatement SEMICOLON)+ END
|
||||
;
|
||||
|
||||
insertMulStatement
|
||||
: STATEMENT SET BEGIN (insertSimpleStatement SEMICOLON)+ END
|
||||
;
|
||||
|
||||
|
||||
// Select statements
|
||||
|
||||
@ -438,6 +521,11 @@ predicate
|
||||
| IS NOT? kind=DISTINCT FROM right=valueExpression
|
||||
;
|
||||
|
||||
likePredicate
|
||||
: NOT? kind=LIKE quantifier=(ANY | ALL) ('('')' | '(' expression (',' expression)* ')')
|
||||
| NOT? kind=LIKE pattern=valueExpression
|
||||
;
|
||||
|
||||
valueExpression
|
||||
: primaryExpression #valueExpressionDefault
|
||||
| operator=('-' | '+' | '~') valueExpression #arithmeticUnary
|
||||
@ -1115,6 +1203,7 @@ nonReserved
|
||||
| UNSET
|
||||
| UNNEST
|
||||
| USE
|
||||
| USER
|
||||
| VALUES
|
||||
| VARBINARY
|
||||
| VARCHAR
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
// Generated from /Users/ziv/github.com/dt-sql-parser/src/grammar/flinksql/FlinkSqlParser.g4 by ANTLR 4.8
|
||||
// Generated from /Users/yuwan/Desktop/yuwan/dt-sql-parser/src/grammar/flinksql/FlinkSqlParser.g4 by ANTLR 4.8
|
||||
// jshint ignore: start
|
||||
var antlr4 = require('antlr4/index');
|
||||
|
||||
@ -92,6 +92,24 @@ FlinkSqlParserListener.prototype.exitExplainStatement = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#explainDetails.
|
||||
FlinkSqlParserListener.prototype.enterExplainDetails = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#explainDetails.
|
||||
FlinkSqlParserListener.prototype.exitExplainDetails = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#explainDetail.
|
||||
FlinkSqlParserListener.prototype.enterExplainDetail = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#explainDetail.
|
||||
FlinkSqlParserListener.prototype.exitExplainDetail = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#useStatement.
|
||||
FlinkSqlParserListener.prototype.enterUseStatement = function(ctx) {
|
||||
};
|
||||
@ -101,6 +119,15 @@ FlinkSqlParserListener.prototype.exitUseStatement = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#useModuleStatement.
|
||||
FlinkSqlParserListener.prototype.enterUseModuleStatement = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#useModuleStatement.
|
||||
FlinkSqlParserListener.prototype.exitUseModuleStatement = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#showStatememt.
|
||||
FlinkSqlParserListener.prototype.enterShowStatememt = function(ctx) {
|
||||
};
|
||||
@ -110,6 +137,51 @@ FlinkSqlParserListener.prototype.exitShowStatememt = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#loadStatement.
|
||||
FlinkSqlParserListener.prototype.enterLoadStatement = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#loadStatement.
|
||||
FlinkSqlParserListener.prototype.exitLoadStatement = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#unloadStatememt.
|
||||
FlinkSqlParserListener.prototype.enterUnloadStatememt = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#unloadStatememt.
|
||||
FlinkSqlParserListener.prototype.exitUnloadStatememt = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#setStatememt.
|
||||
FlinkSqlParserListener.prototype.enterSetStatememt = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#setStatememt.
|
||||
FlinkSqlParserListener.prototype.exitSetStatememt = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#resetStatememt.
|
||||
FlinkSqlParserListener.prototype.enterResetStatememt = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#resetStatememt.
|
||||
FlinkSqlParserListener.prototype.exitResetStatememt = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#jarStatememt.
|
||||
FlinkSqlParserListener.prototype.enterJarStatememt = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#jarStatememt.
|
||||
FlinkSqlParserListener.prototype.exitJarStatememt = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#createTable.
|
||||
FlinkSqlParserListener.prototype.enterCreateTable = function(ctx) {
|
||||
};
|
||||
@ -119,6 +191,24 @@ FlinkSqlParserListener.prototype.exitCreateTable = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#simpleCreateTable.
|
||||
FlinkSqlParserListener.prototype.enterSimpleCreateTable = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#simpleCreateTable.
|
||||
FlinkSqlParserListener.prototype.exitSimpleCreateTable = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#createTableAsSelect.
|
||||
FlinkSqlParserListener.prototype.enterCreateTableAsSelect = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#createTableAsSelect.
|
||||
FlinkSqlParserListener.prototype.exitCreateTableAsSelect = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#columnOptionDefinition.
|
||||
FlinkSqlParserListener.prototype.enterColumnOptionDefinition = function(ctx) {
|
||||
};
|
||||
@ -416,6 +506,24 @@ FlinkSqlParserListener.prototype.exitCreateFunction = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#usingClause.
|
||||
FlinkSqlParserListener.prototype.enterUsingClause = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#usingClause.
|
||||
FlinkSqlParserListener.prototype.exitUsingClause = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#jarFileName.
|
||||
FlinkSqlParserListener.prototype.enterJarFileName = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#jarFileName.
|
||||
FlinkSqlParserListener.prototype.exitJarFileName = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#alterTable.
|
||||
FlinkSqlParserListener.prototype.enterAlterTable = function(ctx) {
|
||||
};
|
||||
@ -443,6 +551,15 @@ FlinkSqlParserListener.prototype.exitSetKeyValueDefinition = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#alertView.
|
||||
FlinkSqlParserListener.prototype.enterAlertView = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#alertView.
|
||||
FlinkSqlParserListener.prototype.exitAlertView = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#alterDatabase.
|
||||
FlinkSqlParserListener.prototype.enterAlterDatabase = function(ctx) {
|
||||
};
|
||||
@ -461,6 +578,15 @@ FlinkSqlParserListener.prototype.exitAlterFunction = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#dropCatalog.
|
||||
FlinkSqlParserListener.prototype.enterDropCatalog = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#dropCatalog.
|
||||
FlinkSqlParserListener.prototype.exitDropCatalog = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#dropTable.
|
||||
FlinkSqlParserListener.prototype.enterDropTable = function(ctx) {
|
||||
};
|
||||
@ -506,6 +632,15 @@ FlinkSqlParserListener.prototype.exitInsertStatement = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#insertSimpleStatement.
|
||||
FlinkSqlParserListener.prototype.enterInsertSimpleStatement = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#insertSimpleStatement.
|
||||
FlinkSqlParserListener.prototype.exitInsertSimpleStatement = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#insertPartitionDefinition.
|
||||
FlinkSqlParserListener.prototype.enterInsertPartitionDefinition = function(ctx) {
|
||||
};
|
||||
@ -515,6 +650,15 @@ FlinkSqlParserListener.prototype.exitInsertPartitionDefinition = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#insertColumnListDefinition.
|
||||
FlinkSqlParserListener.prototype.enterInsertColumnListDefinition = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#insertColumnListDefinition.
|
||||
FlinkSqlParserListener.prototype.exitInsertColumnListDefinition = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#valuesDefinition.
|
||||
FlinkSqlParserListener.prototype.enterValuesDefinition = function(ctx) {
|
||||
};
|
||||
@ -533,6 +677,24 @@ FlinkSqlParserListener.prototype.exitValuesRowDefinition = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#insertMulStatementCompatibility.
|
||||
FlinkSqlParserListener.prototype.enterInsertMulStatementCompatibility = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#insertMulStatementCompatibility.
|
||||
FlinkSqlParserListener.prototype.exitInsertMulStatementCompatibility = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#insertMulStatement.
|
||||
FlinkSqlParserListener.prototype.enterInsertMulStatement = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#insertMulStatement.
|
||||
FlinkSqlParserListener.prototype.exitInsertMulStatement = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#queryStatement.
|
||||
FlinkSqlParserListener.prototype.enterQueryStatement = function(ctx) {
|
||||
};
|
||||
@ -839,6 +1001,15 @@ FlinkSqlParserListener.prototype.exitPredicate = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#likePredicate.
|
||||
FlinkSqlParserListener.prototype.enterLikePredicate = function(ctx) {
|
||||
};
|
||||
|
||||
// Exit a parse tree produced by FlinkSqlParser#likePredicate.
|
||||
FlinkSqlParserListener.prototype.exitLikePredicate = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Enter a parse tree produced by FlinkSqlParser#valueExpressionDefault.
|
||||
FlinkSqlParserListener.prototype.enterValueExpressionDefault = function(ctx) {
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Generated from /Users/ziv/github.com/dt-sql-parser/src/grammar/flinksql/FlinkSqlParser.g4 by ANTLR 4.8
|
||||
// Generated from /Users/yuwan/Desktop/yuwan/dt-sql-parser/src/grammar/flinksql/FlinkSqlParser.g4 by ANTLR 4.8
|
||||
// jshint ignore: start
|
||||
var antlr4 = require('antlr4/index');
|
||||
|
||||
@ -66,24 +66,84 @@ FlinkSqlParserVisitor.prototype.visitExplainStatement = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#explainDetails.
|
||||
FlinkSqlParserVisitor.prototype.visitExplainDetails = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#explainDetail.
|
||||
FlinkSqlParserVisitor.prototype.visitExplainDetail = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#useStatement.
|
||||
FlinkSqlParserVisitor.prototype.visitUseStatement = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#useModuleStatement.
|
||||
FlinkSqlParserVisitor.prototype.visitUseModuleStatement = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#showStatememt.
|
||||
FlinkSqlParserVisitor.prototype.visitShowStatememt = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#loadStatement.
|
||||
FlinkSqlParserVisitor.prototype.visitLoadStatement = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#unloadStatememt.
|
||||
FlinkSqlParserVisitor.prototype.visitUnloadStatememt = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#setStatememt.
|
||||
FlinkSqlParserVisitor.prototype.visitSetStatememt = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#resetStatememt.
|
||||
FlinkSqlParserVisitor.prototype.visitResetStatememt = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#jarStatememt.
|
||||
FlinkSqlParserVisitor.prototype.visitJarStatememt = 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#simpleCreateTable.
|
||||
FlinkSqlParserVisitor.prototype.visitSimpleCreateTable = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#createTableAsSelect.
|
||||
FlinkSqlParserVisitor.prototype.visitCreateTableAsSelect = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#columnOptionDefinition.
|
||||
FlinkSqlParserVisitor.prototype.visitColumnOptionDefinition = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
@ -282,6 +342,18 @@ FlinkSqlParserVisitor.prototype.visitCreateFunction = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#usingClause.
|
||||
FlinkSqlParserVisitor.prototype.visitUsingClause = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#jarFileName.
|
||||
FlinkSqlParserVisitor.prototype.visitJarFileName = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#alterTable.
|
||||
FlinkSqlParserVisitor.prototype.visitAlterTable = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
@ -300,6 +372,12 @@ FlinkSqlParserVisitor.prototype.visitSetKeyValueDefinition = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#alertView.
|
||||
FlinkSqlParserVisitor.prototype.visitAlertView = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#alterDatabase.
|
||||
FlinkSqlParserVisitor.prototype.visitAlterDatabase = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
@ -312,6 +390,12 @@ FlinkSqlParserVisitor.prototype.visitAlterFunction = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#dropCatalog.
|
||||
FlinkSqlParserVisitor.prototype.visitDropCatalog = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#dropTable.
|
||||
FlinkSqlParserVisitor.prototype.visitDropTable = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
@ -342,12 +426,24 @@ FlinkSqlParserVisitor.prototype.visitInsertStatement = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#insertSimpleStatement.
|
||||
FlinkSqlParserVisitor.prototype.visitInsertSimpleStatement = function(ctx) {
|
||||
return this.visitChildren(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#insertColumnListDefinition.
|
||||
FlinkSqlParserVisitor.prototype.visitInsertColumnListDefinition = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#valuesDefinition.
|
||||
FlinkSqlParserVisitor.prototype.visitValuesDefinition = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
@ -360,6 +456,18 @@ FlinkSqlParserVisitor.prototype.visitValuesRowDefinition = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#insertMulStatementCompatibility.
|
||||
FlinkSqlParserVisitor.prototype.visitInsertMulStatementCompatibility = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#insertMulStatement.
|
||||
FlinkSqlParserVisitor.prototype.visitInsertMulStatement = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#queryStatement.
|
||||
FlinkSqlParserVisitor.prototype.visitQueryStatement = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
@ -564,6 +672,12 @@ FlinkSqlParserVisitor.prototype.visitPredicate = function(ctx) {
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#likePredicate.
|
||||
FlinkSqlParserVisitor.prototype.visitLikePredicate = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
|
||||
|
||||
// Visit a parse tree produced by FlinkSqlParser#valueExpressionDefault.
|
||||
FlinkSqlParserVisitor.prototype.visitValueExpressionDefault = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Generated from /Users/ziv/github.com/dt-sql-parser/src/grammar/pgsql/PostgreSQLLexer.g4 by ANTLR 4.8
|
||||
// Generated from /Users/salvo/dt-sql-parser2/src/grammar/pgsql/PostgreSQLLexer.g4 by ANTLR 4.8
|
||||
// jshint ignore: start
|
||||
var antlr4 = require('antlr4/index');
|
||||
|
||||
@ -4737,7 +4737,7 @@ PostgreSQLLexer.prototype.Operator_action = function(localctx , actionIndex) {
|
||||
switch (actionIndex) {
|
||||
case 0:
|
||||
|
||||
HandleLessLessGreaterGreater();
|
||||
this.HandleLessLessGreaterGreater();
|
||||
|
||||
break;
|
||||
default:
|
||||
@ -4748,7 +4748,7 @@ PostgreSQLLexer.prototype.Operator_action = function(localctx , actionIndex) {
|
||||
PostgreSQLLexer.prototype.BeginDollarStringConstant_action = function(localctx , actionIndex) {
|
||||
switch (actionIndex) {
|
||||
case 1:
|
||||
pushTag();
|
||||
this.pushTag();
|
||||
break;
|
||||
default:
|
||||
throw "No registered action for:" + actionIndex;
|
||||
@ -4758,7 +4758,7 @@ PostgreSQLLexer.prototype.BeginDollarStringConstant_action = function(localctx ,
|
||||
PostgreSQLLexer.prototype.NumericFail_action = function(localctx , actionIndex) {
|
||||
switch (actionIndex) {
|
||||
case 2:
|
||||
HandleNumericFail();
|
||||
this.HandleNumericFail();
|
||||
break;
|
||||
default:
|
||||
throw "No registered action for:" + actionIndex;
|
||||
@ -4769,7 +4769,7 @@ PostgreSQLLexer.prototype.UnterminatedBlockComment_action = function(localctx ,
|
||||
switch (actionIndex) {
|
||||
case 3:
|
||||
|
||||
UnterminatedBlockCommentDebugAssert();
|
||||
this.UnterminatedBlockCommentDebugAssert();
|
||||
|
||||
break;
|
||||
default:
|
||||
@ -4798,7 +4798,7 @@ PostgreSQLLexer.prototype.AfterEscapeStringConstantWithNewlineMode_NotContinued_
|
||||
PostgreSQLLexer.prototype.EndDollarStringConstant_action = function(localctx , actionIndex) {
|
||||
switch (actionIndex) {
|
||||
case 6:
|
||||
popTag();
|
||||
this.popTag();
|
||||
break;
|
||||
default:
|
||||
throw "No registered action for:" + actionIndex;
|
||||
@ -4822,11 +4822,11 @@ PostgreSQLLexer.prototype.sempred = function(localctx, ruleIndex, predIndex) {
|
||||
PostgreSQLLexer.prototype.Operator_sempred = function(localctx, predIndex) {
|
||||
switch(predIndex) {
|
||||
case 0:
|
||||
return checkLA('-');
|
||||
return this.checkLA('-');
|
||||
case 1:
|
||||
return checkLA('*');
|
||||
return this.checkLA('*');
|
||||
case 2:
|
||||
return checkLA('*');
|
||||
return this.checkLA('*');
|
||||
default:
|
||||
throw "No predicate with index:" + predIndex;
|
||||
}
|
||||
@ -4835,11 +4835,11 @@ PostgreSQLLexer.prototype.Operator_sempred = function(localctx, predIndex) {
|
||||
PostgreSQLLexer.prototype.OperatorEndingWithPlusMinus_sempred = function(localctx, predIndex) {
|
||||
switch(predIndex) {
|
||||
case 3:
|
||||
return checkLA('-');
|
||||
return this.checkLA('-');
|
||||
case 4:
|
||||
return checkLA('*');
|
||||
return this.checkLA('*');
|
||||
case 5:
|
||||
return checkLA('-');
|
||||
return this.checkLA('-');
|
||||
default:
|
||||
throw "No predicate with index:" + predIndex;
|
||||
}
|
||||
@ -4848,10 +4848,10 @@ PostgreSQLLexer.prototype.OperatorEndingWithPlusMinus_sempred = function(localct
|
||||
PostgreSQLLexer.prototype.IdentifierStartChar_sempred = function(localctx, predIndex) {
|
||||
switch(predIndex) {
|
||||
case 6:
|
||||
return charIsLetter();
|
||||
return this.charIsLetter();
|
||||
case 7:
|
||||
return
|
||||
CheckIfUtf32Letter()
|
||||
this.CheckIfUtf32Letter()
|
||||
;
|
||||
default:
|
||||
throw "No predicate with index:" + predIndex;
|
||||
@ -4861,7 +4861,7 @@ PostgreSQLLexer.prototype.IdentifierStartChar_sempred = function(localctx, predI
|
||||
PostgreSQLLexer.prototype.EndDollarStringConstant_sempred = function(localctx, predIndex) {
|
||||
switch(predIndex) {
|
||||
case 8:
|
||||
return isTag();
|
||||
return this.isTag();
|
||||
default:
|
||||
throw "No predicate with index:" + predIndex;
|
||||
}
|
||||
|
@ -3,104 +3,6 @@ import { FlinkSQL } from '../../../src';
|
||||
describe('FlinkSQL Syntax Tests', () => {
|
||||
const parser = new FlinkSQL();
|
||||
|
||||
// Create statements
|
||||
test('Test simple CreateTable Statement', () => {
|
||||
const sql = `
|
||||
CREATE TABLE Orders (
|
||||
user BIGINT
|
||||
) WITH (
|
||||
"connector" = "kafka",
|
||||
"scan.startup.mode" = "earliest-offset"
|
||||
);
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple CreateDatabase Statement', () => {
|
||||
const sql = `
|
||||
CREATE DATABASE IF NOT EXISTS dataApi
|
||||
WITH (
|
||||
"owner" = "admin"
|
||||
);
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple CreateView Statement', () => {
|
||||
const sql = `
|
||||
CREATE TEMPORARY VIEW IF NOT EXISTS tempView
|
||||
AS SELECT product, amount FROM Orders;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple CreateFunction Statement', () => {
|
||||
const sql = `
|
||||
CREATE TEMPORARY FUNCTION IF NOT EXISTS tempFunction AS 'SimpleUdf';
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
// Alter statements
|
||||
test('Test simple AlterTable Statement', () => {
|
||||
const sql = `ALTER TABLE Orders RENAME TO NewOrders;`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple AlterDatabase Statement', () => {
|
||||
const sql = `ALTER DATABASE tempDB SET ("key1"="value1");`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple AlterFunction Statement', () => {
|
||||
const sql = `
|
||||
ALTER TEMPORARY FUNCTION IF EXISTS tempFunction AS 'SimpleUdf';
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
// Drop statements
|
||||
test('Test simple DropTable Statement', () => {
|
||||
const sql = `DROP TABLE IF EXISTS Orders;`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple DropDatabase Statement', () => {
|
||||
const sql = `DROP DATABASE IF EXISTS Orders RESTRICT;`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple DropView Statement', () => {
|
||||
const sql = `DROP TEMPORARY VIEW IF EXISTS Orders;`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple DropFunction Statement', () => {
|
||||
const sql = `DROP TEMPORARY FUNCTION IF EXISTS Orders;`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
// insert statements
|
||||
test('Test one simple Insert Statement', () => {
|
||||
const sql = `
|
||||
INSERT INTO students VALUES
|
||||
('Amy Smith', '123 Park Ave, San Jose', 111111);
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test two simple Insert Statement', () => {
|
||||
const sql = `
|
||||
INSERT INTO students PARTITION (student_id = 444444)
|
||||
SELECT name, address FROM persons WHERE name = "Dora Williams";
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
// query statements
|
||||
test('Test With clause', () => {
|
||||
const sql = `
|
||||
@ -195,32 +97,102 @@ describe('FlinkSQL Syntax Tests', () => {
|
||||
|
||||
// describe statements
|
||||
test('Test simple Describe Statement', () => {
|
||||
const sql = `DESCRIBE Orders;`;
|
||||
const sql = `
|
||||
DESCRIBE Orders;
|
||||
DESC Orders;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
// describe statements
|
||||
// explain statements
|
||||
test('Test simple Explain Statement', () => {
|
||||
const sql = `EXPLAIN tempTable FOR SELECT k, SUM(v) FROM oneTable;`;
|
||||
const sql = `
|
||||
EXPLAIN SELECT * FROM emps;
|
||||
EXPLAIN PLAN FOR SELECT * FROM emps;
|
||||
EXPLAIN PLAN FOR insert into emps1 SELECT * FROM emps2;
|
||||
EXPLAIN CHANGELOG_MODE SELECT * FROM emps;
|
||||
EXPLAIN ESTIMATED_COST SELECT * FROM emps;
|
||||
EXPLAIN JSON_EXECUTION_PLAN SELECT * FROM emps;
|
||||
EXPLAIN CHANGELOG_MODE, JSON_EXECUTION_PLAN, ESTIMATED_COST SELECT * FROM emps;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
// explain insert_statement
|
||||
test('Test Explain Insert Statement', () => {
|
||||
const sql = `EXPLAIN INSERT INTO EMPS1 SELECT * FROM EMPS2;`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
test('Test simple Explain statement_set', () => {
|
||||
// 按官网上写的,那应该是 explain execute statement set - begin,但实际执行时,携带 execute 会报错
|
||||
// 个人理解,explain 是解析该语法如何执行,而不能在解析的过程中,去执行语句
|
||||
const sql = `
|
||||
EXPLAIN STATEMENT SET
|
||||
BEGIN
|
||||
INSERT INTO t1 SELECT * FROM t2;
|
||||
INSERT INTO t2 SELECT * FROM t3;
|
||||
END;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
// use statements
|
||||
test('Test simple Use Statement', () => {
|
||||
const sql = `USE CATALOG orders;`;
|
||||
const sql = `
|
||||
USE CATALOG cat1;
|
||||
USE db1;
|
||||
USE MODULES hive;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
// show statements
|
||||
test('Test simple Show Statement', () => {
|
||||
const sql = `SHOW CATALOGS;`;
|
||||
const sql = `
|
||||
SHOW CATALOGS;
|
||||
SHOW CURRENT CATALOG;
|
||||
SHOW DATABASES;
|
||||
SHOW CURRENT DATABASE;
|
||||
SHOW TABLES;
|
||||
SHOW TABLES FROM catalog1.db1 NOT LIKE '%';
|
||||
SHOW CREATE TABLE my_table;
|
||||
SHOW COLUMNS FROM my_table LIKE '%f%';
|
||||
SHOW VIEWS;
|
||||
SHOW CREATE VIEW my_view;
|
||||
SHOW FUNCTIONS;
|
||||
SHOW USER FUNCTIONS;
|
||||
SHOW MODULES;
|
||||
SHOW FULL MODULES;
|
||||
SHOW JARS;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
// other statement
|
||||
test('Test other Statement', () => {
|
||||
const sql = `
|
||||
LOAD MODULE CORE;
|
||||
LOAD MODULE dummy WITH ('k1' = 'v1', 'k2' = 'v2');
|
||||
UNLOAD MODULE CORE;
|
||||
SET;
|
||||
SET 'test-key' = 'test-value';
|
||||
RESET;
|
||||
RESET 'test-key';
|
||||
ADD JAR '<path_to_filename>.jar'
|
||||
REMOVE JAR '<path_to_filename>.jar'
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
console.log(result);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
test('Test invalid Double Line Comment statement', () => {
|
||||
let sql = `-test comment\n`;
|
||||
let result = parser.validate(sql);
|
||||
|
38
test/parser/flinksql/syntax/alterStatement.test.ts
Normal file
38
test/parser/flinksql/syntax/alterStatement.test.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { FlinkSQL } from '../../../../src';
|
||||
|
||||
describe('FlinkSQL Create Table Syntax Tests', () => {
|
||||
const parser = new FlinkSQL();
|
||||
// Alter statements
|
||||
test('Test simple alter table Statement', () => {
|
||||
const sql = `
|
||||
ALTER TABLE Orders RENAME TO NewOrders;
|
||||
ALTER TABLE sample_table SET ('key1'='value2');
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple alter view Statement', () => {
|
||||
const sql = `
|
||||
ALTER VIEW v1 RENAME TO v2;
|
||||
ALTER VIEW v1 AS SELECT c1, c2 FROM tbl;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple alter database Statement', () => {
|
||||
const sql = `ALTER DATABASE tempDB SET ("key1"="value1");`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple alter function Statement', () => {
|
||||
const sql = `
|
||||
ALTER FUNCTION tempFunction AS 'SimpleUdf';
|
||||
ALTER TEMPORARY FUNCTION IF EXISTS tempFunction AS 'SimpleUdf';
|
||||
ALTER TEMPORARY SYSTEM FUNCTION IF EXISTS tempFunction AS 'SimpleUdf';
|
||||
ALTER FUNCTION myudf AS 'com.example.MyUdf' LANGUAGE PYTHON;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
43
test/parser/flinksql/syntax/createStatement.test.ts
Normal file
43
test/parser/flinksql/syntax/createStatement.test.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { FlinkSQL } from '../../../../src';
|
||||
|
||||
describe('FlinkSQL Create Table Syntax Tests', () => {
|
||||
const parser = new FlinkSQL();
|
||||
// Create statements
|
||||
test('Test Create Catalog Statement', () => {
|
||||
const sql = `
|
||||
CREATE CATALOG c1
|
||||
WITH (
|
||||
'key1'='value1',
|
||||
'key2'='value2'
|
||||
)
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple Create Database Statement', () => {
|
||||
const sql = `
|
||||
CREATE DATABASE IF NOT EXISTS dataApi
|
||||
WITH (
|
||||
"owner" = "admin"
|
||||
);
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple Create View Statement', () => {
|
||||
const sql = `
|
||||
CREATE TEMPORARY VIEW IF NOT EXISTS tempView
|
||||
AS SELECT product, amount FROM Orders;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test simple Create Function Statement', () => {
|
||||
const sql = `
|
||||
CREATE FUNCTION IF NOT EXISTS tempFunction AS 'SimpleUdf';
|
||||
CREATE TEMPORARY FUNCTION function1 AS 'org.apache.fink.function.function1' LANGUAGE JAVA USING JAR 'file:///path/to/test.jar', JAR 'hdfs:///path/to/test2.jar';
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
});
|
@ -4,7 +4,7 @@ describe('FlinkSQL Create Table Syntax Tests', () => {
|
||||
const parser = new FlinkSQL();
|
||||
|
||||
// simple create table statement
|
||||
test('Test simple CreateTable Statement', () => {
|
||||
test('Test simple Create Table Statement', () => {
|
||||
const sql = `
|
||||
CREATE TABLE MyTable (
|
||||
'user_id' BIGINT,
|
||||
@ -16,6 +16,19 @@ describe('FlinkSQL Create Table Syntax Tests', () => {
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
// create temporary table statement
|
||||
test('Test Temporary Create Table Statement', () => {
|
||||
const sql = `
|
||||
CREATE TEMPORARY TABLE MyTable (
|
||||
'user_id' BIGINT,
|
||||
'name' STRING
|
||||
) WITH (
|
||||
'connector'='oracle-x'
|
||||
);
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
// Metadata Columns statement
|
||||
test('Test Metadata Columns Statement', () => {
|
||||
const sql = `
|
||||
@ -114,6 +127,19 @@ describe('FlinkSQL Create Table Syntax Tests', () => {
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
// AS select_statement
|
||||
test('Test As Select Statement', () => {
|
||||
const sql = `
|
||||
CREATE TABLE my_ctas_table
|
||||
WITH (
|
||||
'connector' = 'kafka'
|
||||
)
|
||||
AS SELECT id, name, age FROM source_table WHERE mod(id, 10) = 0;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
// create catalog table
|
||||
test('Test Create Catalog Table Statement', () => {
|
||||
const sql = `
|
||||
|
49
test/parser/flinksql/syntax/dropStatement.test.ts
Normal file
49
test/parser/flinksql/syntax/dropStatement.test.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { FlinkSQL } from '../../../../src';
|
||||
|
||||
describe('FlinkSQL Create Table Syntax Tests', () => {
|
||||
const parser = new FlinkSQL();
|
||||
// Drop statements
|
||||
test('Test Simple Drop Catalog Statement', () => {
|
||||
const sql = `
|
||||
DROP CATALOG catalog1;
|
||||
DROP CATALOG IF EXISTS catalog2;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test Simple Drop Table Statement', () => {
|
||||
const sql = `
|
||||
DROP TABLE Orders;
|
||||
DROP TABLE IF EXISTS Orders;
|
||||
DROP TEMPORARY TABLE IF EXISTS Orders;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test Simple Drop Database Statement', () => {
|
||||
const sql = `
|
||||
DROP DATABASE Orders;
|
||||
DROP DATABASE IF EXISTS Orders RESTRICT;
|
||||
DROP DATABASE IF EXISTS Orders CASCADE;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test Simple Drop View Statement', () => {
|
||||
const sql = `
|
||||
DROP VIEW Orders;
|
||||
DROP TEMPORARY VIEW IF EXISTS Orders;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test Simple Drop Function Statement', () => {
|
||||
const sql = `
|
||||
DROP FUNCTION Orders;
|
||||
DROP TEMPORARY FUNCTION IF EXISTS Orders;
|
||||
DROP TEMPORARY SYSTEM FUNCTION IF EXISTS Orders;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
});
|
83
test/parser/flinksql/syntax/insertStatement.test.ts
Normal file
83
test/parser/flinksql/syntax/insertStatement.test.ts
Normal file
@ -0,0 +1,83 @@
|
||||
import { FlinkSQL } from '../../../../src';
|
||||
|
||||
describe('FlinkSQL Create Table Syntax Tests', () => {
|
||||
const parser = new FlinkSQL();
|
||||
// insert statements
|
||||
test('Test one simple Insert Statement', () => {
|
||||
const sql = `
|
||||
INSERT INTO country_page_view
|
||||
SELECT user, cnt FROM page_view_source;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test Insert Overwrite Statement', () => {
|
||||
const sql = `
|
||||
INSERT OVERWRITE country_page_view PARTITION (date='2019-8-30', country='China')
|
||||
SELECT user, cnt FROM page_view_source;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test execute Statement', () => {
|
||||
const sql = `
|
||||
EXECUTE INSERT INTO country_page_view PARTITION (date='2019-8-30', country='China')
|
||||
SELECT user, cnt FROM page_view_source;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test Partition Clause Statement', () => {
|
||||
const sql = `
|
||||
INSERT INTO country_page_view PARTITION (date='2019-8-30', country='China')
|
||||
SELECT user, cnt FROM page_view_source;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test Column List Statement', () => {
|
||||
const sql = `
|
||||
INSERT INTO emps PARTITION (x='ab', y='bc') (x, y) SELECT * FROM emps;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test Insert Values Statement', () => {
|
||||
const sql = `
|
||||
INSERT INTO students
|
||||
VALUES ('fred flintstone', 35, 1.28), ('barney rubble', 32, 2.32);
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test insert into multiple tables Statement for 1.14', () => {
|
||||
const sql = `
|
||||
BEGIN STATEMENT SET;
|
||||
|
||||
INSERT INTO pageviews
|
||||
SELECT page_id, count(1)
|
||||
FROM pageviews
|
||||
GROUP BY page_id;
|
||||
|
||||
INSERT INTO uniqueview
|
||||
SELECT page_id, count(distinct user_id)
|
||||
FROM pageviews
|
||||
GROUP BY page_id;
|
||||
|
||||
END;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test insert into multiple tables Statement for 1.15', () => {
|
||||
const sql = `
|
||||
EXECUTE STATEMENT SET
|
||||
BEGIN
|
||||
INSERT INTO students VALUES ('fred flintstone', 35, 1.28), ('barney rubble', 32, 2.32);
|
||||
INSERT INTO students VALUES ('fred flintstone', 35, 1.28), ('barney rubble', 32, 2.32);
|
||||
END;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user