add flinksql
This commit is contained in:
parent
e79a5a3d07
commit
8d7040d04b
@ -164,7 +164,9 @@ module.exports = {
|
||||
// timers: "real",
|
||||
|
||||
// A map from regular expressions to paths to transformers
|
||||
// transform: null,
|
||||
transform: {
|
||||
'^.+\\.tsx?$': 'ts-jest'
|
||||
},
|
||||
|
||||
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
||||
transformIgnorePatterns: [
|
||||
|
2025
lib/antlr4/flinksql/sqlLexer.js
Normal file
2025
lib/antlr4/flinksql/sqlLexer.js
Normal file
File diff suppressed because it is too large
Load Diff
1253
lib/antlr4/flinksql/sqlListener.js
Normal file
1253
lib/antlr4/flinksql/sqlListener.js
Normal file
File diff suppressed because it is too large
Load Diff
22894
lib/antlr4/flinksql/sqlParser.js
Normal file
22894
lib/antlr4/flinksql/sqlParser.js
Normal file
File diff suppressed because one or more lines are too long
839
lib/antlr4/flinksql/sqlVisitor.js
Normal file
839
lib/antlr4/flinksql/sqlVisitor.js
Normal file
@ -0,0 +1,839 @@
|
||||
// Generated from ./grammar/sql.g4 by ANTLR 4.7.1
|
||||
// jshint ignore: start
|
||||
var antlr4 = require('antlr4/index');
|
||||
// This class defines a complete generic visitor for a parse tree produced by sqlParser.
|
||||
function sqlVisitor() {
|
||||
antlr4.tree.ParseTreeVisitor.call(this);
|
||||
return this;
|
||||
}
|
||||
sqlVisitor.prototype = Object.create(antlr4.tree.ParseTreeVisitor.prototype);
|
||||
sqlVisitor.prototype.constructor = sqlVisitor;
|
||||
// Visit a parse tree produced by sqlParser#singleStatement.
|
||||
sqlVisitor.prototype.visitSingleStatement = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#singleExpression.
|
||||
sqlVisitor.prototype.visitSingleExpression = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#singleTableIdentifier.
|
||||
sqlVisitor.prototype.visitSingleTableIdentifier = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#singleFunctionIdentifier.
|
||||
sqlVisitor.prototype.visitSingleFunctionIdentifier = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#singleDataType.
|
||||
sqlVisitor.prototype.visitSingleDataType = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#singleTableSchema.
|
||||
sqlVisitor.prototype.visitSingleTableSchema = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#statementDefault.
|
||||
sqlVisitor.prototype.visitStatementDefault = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#use.
|
||||
sqlVisitor.prototype.visitUse = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#createDatabase.
|
||||
sqlVisitor.prototype.visitCreateDatabase = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#setDatabaseProperties.
|
||||
sqlVisitor.prototype.visitSetDatabaseProperties = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#dropDatabase.
|
||||
sqlVisitor.prototype.visitDropDatabase = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#createTable.
|
||||
sqlVisitor.prototype.visitCreateTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#createHiveTable.
|
||||
sqlVisitor.prototype.visitCreateHiveTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#createFlinkTable.
|
||||
sqlVisitor.prototype.visitCreateFlinkTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#createTableLike.
|
||||
sqlVisitor.prototype.visitCreateTableLike = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#analyze.
|
||||
sqlVisitor.prototype.visitAnalyze = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#addTableColumns.
|
||||
sqlVisitor.prototype.visitAddTableColumns = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#renameTable.
|
||||
sqlVisitor.prototype.visitRenameTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#setTableProperties.
|
||||
sqlVisitor.prototype.visitSetTableProperties = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#unsetTableProperties.
|
||||
sqlVisitor.prototype.visitUnsetTableProperties = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#changeColumn.
|
||||
sqlVisitor.prototype.visitChangeColumn = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#setTableSerDe.
|
||||
sqlVisitor.prototype.visitSetTableSerDe = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#addTablePartition.
|
||||
sqlVisitor.prototype.visitAddTablePartition = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#renameTablePartition.
|
||||
sqlVisitor.prototype.visitRenameTablePartition = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#dropTablePartitions.
|
||||
sqlVisitor.prototype.visitDropTablePartitions = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#setTableLocation.
|
||||
sqlVisitor.prototype.visitSetTableLocation = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#recoverPartitions.
|
||||
sqlVisitor.prototype.visitRecoverPartitions = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#dropTable.
|
||||
sqlVisitor.prototype.visitDropTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#createView.
|
||||
sqlVisitor.prototype.visitCreateView = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#createTempViewUsing.
|
||||
sqlVisitor.prototype.visitCreateTempViewUsing = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#alterViewQuery.
|
||||
sqlVisitor.prototype.visitAlterViewQuery = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#createFunction.
|
||||
sqlVisitor.prototype.visitCreateFunction = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#dropFunction.
|
||||
sqlVisitor.prototype.visitDropFunction = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#explain.
|
||||
sqlVisitor.prototype.visitExplain = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#showTables.
|
||||
sqlVisitor.prototype.visitShowTables = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#showTable.
|
||||
sqlVisitor.prototype.visitShowTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#showDatabases.
|
||||
sqlVisitor.prototype.visitShowDatabases = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#showTblProperties.
|
||||
sqlVisitor.prototype.visitShowTblProperties = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#showColumns.
|
||||
sqlVisitor.prototype.visitShowColumns = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#showPartitions.
|
||||
sqlVisitor.prototype.visitShowPartitions = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#showFunctions.
|
||||
sqlVisitor.prototype.visitShowFunctions = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#showCreateTable.
|
||||
sqlVisitor.prototype.visitShowCreateTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#describeFunction.
|
||||
sqlVisitor.prototype.visitDescribeFunction = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#describeDatabase.
|
||||
sqlVisitor.prototype.visitDescribeDatabase = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#describeTable.
|
||||
sqlVisitor.prototype.visitDescribeTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#refreshTable.
|
||||
sqlVisitor.prototype.visitRefreshTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#refreshResource.
|
||||
sqlVisitor.prototype.visitRefreshResource = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#cacheTable.
|
||||
sqlVisitor.prototype.visitCacheTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#uncacheTable.
|
||||
sqlVisitor.prototype.visitUncacheTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#clearCache.
|
||||
sqlVisitor.prototype.visitClearCache = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#loadData.
|
||||
sqlVisitor.prototype.visitLoadData = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#truncateTable.
|
||||
sqlVisitor.prototype.visitTruncateTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#repairTable.
|
||||
sqlVisitor.prototype.visitRepairTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#manageResource.
|
||||
sqlVisitor.prototype.visitManageResource = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#failNativeCommand.
|
||||
sqlVisitor.prototype.visitFailNativeCommand = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#setConfiguration.
|
||||
sqlVisitor.prototype.visitSetConfiguration = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#resetConfiguration.
|
||||
sqlVisitor.prototype.visitResetConfiguration = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#unsupportedHiveNativeCommands.
|
||||
sqlVisitor.prototype.visitUnsupportedHiveNativeCommands = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#createTableHeader.
|
||||
sqlVisitor.prototype.visitCreateTableHeader = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#bucketSpec.
|
||||
sqlVisitor.prototype.visitBucketSpec = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#skewSpec.
|
||||
sqlVisitor.prototype.visitSkewSpec = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#locationSpec.
|
||||
sqlVisitor.prototype.visitLocationSpec = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#query.
|
||||
sqlVisitor.prototype.visitQuery = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#insertOverwriteTable.
|
||||
sqlVisitor.prototype.visitInsertOverwriteTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#insertIntoTable.
|
||||
sqlVisitor.prototype.visitInsertIntoTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#insertOverwriteHiveDir.
|
||||
sqlVisitor.prototype.visitInsertOverwriteHiveDir = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#insertOverwriteDir.
|
||||
sqlVisitor.prototype.visitInsertOverwriteDir = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#partitionSpecLocation.
|
||||
sqlVisitor.prototype.visitPartitionSpecLocation = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#partitionSpec.
|
||||
sqlVisitor.prototype.visitPartitionSpec = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#partitionVal.
|
||||
sqlVisitor.prototype.visitPartitionVal = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#describeFuncName.
|
||||
sqlVisitor.prototype.visitDescribeFuncName = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#describeColName.
|
||||
sqlVisitor.prototype.visitDescribeColName = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#ctes.
|
||||
sqlVisitor.prototype.visitCtes = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#namedQuery.
|
||||
sqlVisitor.prototype.visitNamedQuery = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#tableProvider.
|
||||
sqlVisitor.prototype.visitTableProvider = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#tablePropertyList.
|
||||
sqlVisitor.prototype.visitTablePropertyList = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#tableProperty.
|
||||
sqlVisitor.prototype.visitTableProperty = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#tablePropertyKey.
|
||||
sqlVisitor.prototype.visitTablePropertyKey = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#tablePropertyValue.
|
||||
sqlVisitor.prototype.visitTablePropertyValue = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#constantList.
|
||||
sqlVisitor.prototype.visitConstantList = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#nestedConstantList.
|
||||
sqlVisitor.prototype.visitNestedConstantList = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#createFileFormat.
|
||||
sqlVisitor.prototype.visitCreateFileFormat = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#tableFileFormat.
|
||||
sqlVisitor.prototype.visitTableFileFormat = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#genericFileFormat.
|
||||
sqlVisitor.prototype.visitGenericFileFormat = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#storageHandler.
|
||||
sqlVisitor.prototype.visitStorageHandler = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#resource.
|
||||
sqlVisitor.prototype.visitResource = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#singleInsertQuery.
|
||||
sqlVisitor.prototype.visitSingleInsertQuery = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#multiInsertQuery.
|
||||
sqlVisitor.prototype.visitMultiInsertQuery = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#queryOrganization.
|
||||
sqlVisitor.prototype.visitQueryOrganization = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#multiInsertQueryBody.
|
||||
sqlVisitor.prototype.visitMultiInsertQueryBody = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#queryTermDefault.
|
||||
sqlVisitor.prototype.visitQueryTermDefault = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#setOperation.
|
||||
sqlVisitor.prototype.visitSetOperation = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#queryPrimaryDefault.
|
||||
sqlVisitor.prototype.visitQueryPrimaryDefault = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#table.
|
||||
sqlVisitor.prototype.visitTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#inlineTableDefault1.
|
||||
sqlVisitor.prototype.visitInlineTableDefault1 = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#subquery.
|
||||
sqlVisitor.prototype.visitSubquery = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#sortItem.
|
||||
sqlVisitor.prototype.visitSortItem = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#querySpecification.
|
||||
sqlVisitor.prototype.visitQuerySpecification = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#hint.
|
||||
sqlVisitor.prototype.visitHint = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#hintStatement.
|
||||
sqlVisitor.prototype.visitHintStatement = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#fromClause.
|
||||
sqlVisitor.prototype.visitFromClause = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#aggregation.
|
||||
sqlVisitor.prototype.visitAggregation = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#groupingSet.
|
||||
sqlVisitor.prototype.visitGroupingSet = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#pivotClause.
|
||||
sqlVisitor.prototype.visitPivotClause = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#pivotColumn.
|
||||
sqlVisitor.prototype.visitPivotColumn = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#pivotValue.
|
||||
sqlVisitor.prototype.visitPivotValue = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#lateralView.
|
||||
sqlVisitor.prototype.visitLateralView = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#setQuantifier.
|
||||
sqlVisitor.prototype.visitSetQuantifier = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#relation.
|
||||
sqlVisitor.prototype.visitRelation = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#joinRelation.
|
||||
sqlVisitor.prototype.visitJoinRelation = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#joinType.
|
||||
sqlVisitor.prototype.visitJoinType = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#joinCriteria.
|
||||
sqlVisitor.prototype.visitJoinCriteria = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#sample.
|
||||
sqlVisitor.prototype.visitSample = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#sampleByPercentile.
|
||||
sqlVisitor.prototype.visitSampleByPercentile = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#sampleByRows.
|
||||
sqlVisitor.prototype.visitSampleByRows = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#sampleByBucket.
|
||||
sqlVisitor.prototype.visitSampleByBucket = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#sampleByBytes.
|
||||
sqlVisitor.prototype.visitSampleByBytes = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#identifierList.
|
||||
sqlVisitor.prototype.visitIdentifierList = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#identifierSeq.
|
||||
sqlVisitor.prototype.visitIdentifierSeq = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#orderedIdentifierList.
|
||||
sqlVisitor.prototype.visitOrderedIdentifierList = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#orderedIdentifier.
|
||||
sqlVisitor.prototype.visitOrderedIdentifier = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#identifierCommentList.
|
||||
sqlVisitor.prototype.visitIdentifierCommentList = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#identifierComment.
|
||||
sqlVisitor.prototype.visitIdentifierComment = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#tableName.
|
||||
sqlVisitor.prototype.visitTableName = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#aliasedQuery.
|
||||
sqlVisitor.prototype.visitAliasedQuery = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#aliasedRelation.
|
||||
sqlVisitor.prototype.visitAliasedRelation = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#inlineTableDefault2.
|
||||
sqlVisitor.prototype.visitInlineTableDefault2 = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#tableValuedFunction.
|
||||
sqlVisitor.prototype.visitTableValuedFunction = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#inlineTable.
|
||||
sqlVisitor.prototype.visitInlineTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#functionTable.
|
||||
sqlVisitor.prototype.visitFunctionTable = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#tableAlias.
|
||||
sqlVisitor.prototype.visitTableAlias = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#rowFormatSerde.
|
||||
sqlVisitor.prototype.visitRowFormatSerde = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#rowFormatDelimited.
|
||||
sqlVisitor.prototype.visitRowFormatDelimited = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#tableIdentifier.
|
||||
sqlVisitor.prototype.visitTableIdentifier = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#functionIdentifier.
|
||||
sqlVisitor.prototype.visitFunctionIdentifier = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#namedExpression.
|
||||
sqlVisitor.prototype.visitNamedExpression = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#namedExpressionSeq.
|
||||
sqlVisitor.prototype.visitNamedExpressionSeq = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#expression.
|
||||
sqlVisitor.prototype.visitExpression = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#logicalNot.
|
||||
sqlVisitor.prototype.visitLogicalNot = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#predicated.
|
||||
sqlVisitor.prototype.visitPredicated = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#exists.
|
||||
sqlVisitor.prototype.visitExists = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#logicalBinary.
|
||||
sqlVisitor.prototype.visitLogicalBinary = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#predicate.
|
||||
sqlVisitor.prototype.visitPredicate = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#valueExpressionDefault.
|
||||
sqlVisitor.prototype.visitValueExpressionDefault = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#comparison.
|
||||
sqlVisitor.prototype.visitComparison = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#arithmeticBinary.
|
||||
sqlVisitor.prototype.visitArithmeticBinary = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#arithmeticUnary.
|
||||
sqlVisitor.prototype.visitArithmeticUnary = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#struct.
|
||||
sqlVisitor.prototype.visitStruct = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#dereference.
|
||||
sqlVisitor.prototype.visitDereference = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#simpleCase.
|
||||
sqlVisitor.prototype.visitSimpleCase = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#columnReference.
|
||||
sqlVisitor.prototype.visitColumnReference = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#rowConstructor.
|
||||
sqlVisitor.prototype.visitRowConstructor = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#last.
|
||||
sqlVisitor.prototype.visitLast = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#star.
|
||||
sqlVisitor.prototype.visitStar = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#subscript.
|
||||
sqlVisitor.prototype.visitSubscript = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#subqueryExpression.
|
||||
sqlVisitor.prototype.visitSubqueryExpression = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#cast.
|
||||
sqlVisitor.prototype.visitCast = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#constantDefault.
|
||||
sqlVisitor.prototype.visitConstantDefault = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#lambda.
|
||||
sqlVisitor.prototype.visitLambda = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#parenthesizedExpression.
|
||||
sqlVisitor.prototype.visitParenthesizedExpression = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#extract.
|
||||
sqlVisitor.prototype.visitExtract = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#functionCall.
|
||||
sqlVisitor.prototype.visitFunctionCall = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#searchedCase.
|
||||
sqlVisitor.prototype.visitSearchedCase = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#position.
|
||||
sqlVisitor.prototype.visitPosition = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#first.
|
||||
sqlVisitor.prototype.visitFirst = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#nullLiteral.
|
||||
sqlVisitor.prototype.visitNullLiteral = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#intervalLiteral.
|
||||
sqlVisitor.prototype.visitIntervalLiteral = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#typeConstructor.
|
||||
sqlVisitor.prototype.visitTypeConstructor = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#numericLiteral.
|
||||
sqlVisitor.prototype.visitNumericLiteral = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#booleanLiteral.
|
||||
sqlVisitor.prototype.visitBooleanLiteral = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#stringLiteral.
|
||||
sqlVisitor.prototype.visitStringLiteral = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#comparisonOperator.
|
||||
sqlVisitor.prototype.visitComparisonOperator = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#arithmeticOperator.
|
||||
sqlVisitor.prototype.visitArithmeticOperator = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#predicateOperator.
|
||||
sqlVisitor.prototype.visitPredicateOperator = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#booleanValue.
|
||||
sqlVisitor.prototype.visitBooleanValue = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#interval.
|
||||
sqlVisitor.prototype.visitInterval = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#intervalField.
|
||||
sqlVisitor.prototype.visitIntervalField = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#intervalValue.
|
||||
sqlVisitor.prototype.visitIntervalValue = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#colPosition.
|
||||
sqlVisitor.prototype.visitColPosition = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#complexDataType.
|
||||
sqlVisitor.prototype.visitComplexDataType = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#primitiveDataType.
|
||||
sqlVisitor.prototype.visitPrimitiveDataType = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#colTypeList.
|
||||
sqlVisitor.prototype.visitColTypeList = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#colType.
|
||||
sqlVisitor.prototype.visitColType = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#dtColTypeList.
|
||||
sqlVisitor.prototype.visitDtColTypeList = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#dtColType.
|
||||
sqlVisitor.prototype.visitDtColType = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#complexColTypeList.
|
||||
sqlVisitor.prototype.visitComplexColTypeList = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#complexColType.
|
||||
sqlVisitor.prototype.visitComplexColType = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#whenClause.
|
||||
sqlVisitor.prototype.visitWhenClause = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#windows.
|
||||
sqlVisitor.prototype.visitWindows = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#namedWindow.
|
||||
sqlVisitor.prototype.visitNamedWindow = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#windowRef.
|
||||
sqlVisitor.prototype.visitWindowRef = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#windowDef.
|
||||
sqlVisitor.prototype.visitWindowDef = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#windowFrame.
|
||||
sqlVisitor.prototype.visitWindowFrame = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#frameBound.
|
||||
sqlVisitor.prototype.visitFrameBound = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#qualifiedName.
|
||||
sqlVisitor.prototype.visitQualifiedName = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#identifier.
|
||||
sqlVisitor.prototype.visitIdentifier = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#unquotedIdentifier.
|
||||
sqlVisitor.prototype.visitUnquotedIdentifier = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#quotedIdentifierAlternative.
|
||||
sqlVisitor.prototype.visitQuotedIdentifierAlternative = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#quotedIdentifier.
|
||||
sqlVisitor.prototype.visitQuotedIdentifier = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#decimalLiteral.
|
||||
sqlVisitor.prototype.visitDecimalLiteral = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#integerLiteral.
|
||||
sqlVisitor.prototype.visitIntegerLiteral = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#bigIntLiteral.
|
||||
sqlVisitor.prototype.visitBigIntLiteral = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#smallIntLiteral.
|
||||
sqlVisitor.prototype.visitSmallIntLiteral = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#tinyIntLiteral.
|
||||
sqlVisitor.prototype.visitTinyIntLiteral = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#doubleLiteral.
|
||||
sqlVisitor.prototype.visitDoubleLiteral = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#bigDecimalLiteral.
|
||||
sqlVisitor.prototype.visitBigDecimalLiteral = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
// Visit a parse tree produced by sqlParser#nonReserved.
|
||||
sqlVisitor.prototype.visitNonReserved = function (ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
};
|
||||
exports.sqlVisitor = sqlVisitor;
|
@ -4,3 +4,5 @@ const parser = require("./lib/parser");
|
||||
exports.parser = parser;
|
||||
const filter = require("./lib/filter");
|
||||
exports.filter = filter;
|
||||
const flinkParser_1 = require("./lib/flinkParser");
|
||||
exports.flinksqlParser = flinkParser_1.default;
|
||||
|
49
lib/lib/flinkParser.js
Normal file
49
lib/lib/flinkParser.js
Normal file
@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const antlr4 = require("antlr4");
|
||||
const error_1 = require("antlr4/error");
|
||||
const sqlLexer_1 = require("../antlr4/flinksql/sqlLexer");
|
||||
const sqlParser_1 = require("../antlr4/flinksql/sqlParser");
|
||||
const utils_1 = require("../utils");
|
||||
class SqlErrorListener extends error_1.ErrorListener {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.error = null;
|
||||
}
|
||||
syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e) {
|
||||
this.error = {
|
||||
line,
|
||||
column: charPositionInLine,
|
||||
token: offendingSymbol,
|
||||
errorMsg: msg
|
||||
};
|
||||
}
|
||||
}
|
||||
function parserSingle(sql) {
|
||||
const inputStream = new antlr4.InputStream(sql.toUpperCase());
|
||||
const lexer = new sqlLexer_1.sqlLexer(inputStream);
|
||||
const tokenStream = new antlr4.CommonTokenStream(lexer);
|
||||
const parser = new sqlParser_1.sqlParser(tokenStream);
|
||||
parser.buildParseTrees = true;
|
||||
let listener = new SqlErrorListener();
|
||||
parser.addErrorListener(listener);
|
||||
parser.singleStatement();
|
||||
return listener.error;
|
||||
}
|
||||
function parserSyntax(sql) {
|
||||
let runSql = typeof sql == 'string' ? sql : sql.join('');
|
||||
const sqls = utils_1.splitSql(runSql);
|
||||
for (let i = 0, index = 0; i < sqls.length; i++) {
|
||||
/**
|
||||
* 这边不取分号
|
||||
*/
|
||||
let sql = new Array(index).fill(' ').join('') + runSql.substring(index, sqls[i]);
|
||||
let err = parserSingle(sql);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
index = sqls[i] + 1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
exports.default = parserSyntax;
|
@ -19,3 +19,94 @@ function replaceStrFormIndexArr(str, replaceStr, indexArr) {
|
||||
return result;
|
||||
}
|
||||
exports.replaceStrFormIndexArr = replaceStrFormIndexArr;
|
||||
function splitSql(sql) {
|
||||
let haveEnd = true;
|
||||
if (!sql.endsWith(';')) {
|
||||
sql += ';';
|
||||
haveEnd = false;
|
||||
}
|
||||
// 处理引号
|
||||
function quoteToken(parser, sql) {
|
||||
let queue = parser.queue;
|
||||
let endsWith = queue[queue.length - 1];
|
||||
if (endsWith == '\'' || endsWith == '"') {
|
||||
let nextToken = sql.indexOf(endsWith, parser.index + 1);
|
||||
if (nextToken != -1) {
|
||||
parser.index = nextToken;
|
||||
parser.queue = '';
|
||||
}
|
||||
else {
|
||||
parser.index = sql.length - 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 处理单行注释
|
||||
function singleLineCommentToken(parser, sql) {
|
||||
let queue = parser.queue;
|
||||
if (queue.endsWith('--')) {
|
||||
let nextToken = sql.indexOf('\n', parser.index + 1);
|
||||
if (nextToken != -1) {
|
||||
parser.index = nextToken;
|
||||
queue = '';
|
||||
}
|
||||
else {
|
||||
parser.index = sql.length - 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 处理多行注释
|
||||
function multipleLineCommentToken(parser, sql) {
|
||||
let queue = parser.queue;
|
||||
if (queue.endsWith('/*')) {
|
||||
let nextToken = sql.indexOf('*/', parser.index + 1);
|
||||
if (nextToken != -1) {
|
||||
parser.index = nextToken + 1;
|
||||
parser.queue = '';
|
||||
}
|
||||
else {
|
||||
parser.index = sql.length - 1;
|
||||
parser.queue = '';
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function splitToken(parser, sql) {
|
||||
let queue = parser.queue;
|
||||
if (queue.endsWith(';')) {
|
||||
if (!haveEnd && parser.index == sql.length - 1) {
|
||||
parser.sqls.push(parser.index - 1);
|
||||
queue = '';
|
||||
}
|
||||
else {
|
||||
parser.sqls.push(parser.index);
|
||||
queue = '';
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
let parser = {
|
||||
index: 0,
|
||||
queue: '',
|
||||
sqls: []
|
||||
};
|
||||
for (parser.index = 0; parser.index < sql.length; parser.index++) {
|
||||
let char = sql[parser.index];
|
||||
parser.queue += char;
|
||||
let tokenFuncs = [quoteToken, singleLineCommentToken, multipleLineCommentToken, splitToken];
|
||||
for (let i = 0; i < tokenFuncs.length; i++) {
|
||||
tokenFuncs[i](parser, sql);
|
||||
}
|
||||
}
|
||||
return parser.sqls;
|
||||
}
|
||||
exports.splitSql = splitSql;
|
||||
|
@ -22,8 +22,13 @@
|
||||
"@types/jest": "^24.0.13",
|
||||
"jest": "^24.8.0",
|
||||
"node-query": "^0.3.3",
|
||||
"pegjs": "^0.10.0"
|
||||
"pegjs": "^0.10.0",
|
||||
"ts-jest": "^24.1.0",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"git repository": "https://github.com/HSunboy/dt-sql-parser",
|
||||
"dependencies": {}
|
||||
"dependencies": {
|
||||
"@types/antlr4": "^4.7.0",
|
||||
"antlr4": "^4.7.2"
|
||||
}
|
||||
}
|
||||
|
624
src/antlr4/flinksql/sql.interp
Normal file
624
src/antlr4/flinksql/sql.interp
Normal file
File diff suppressed because one or more lines are too long
488
src/antlr4/flinksql/sql.tokens
Normal file
488
src/antlr4/flinksql/sql.tokens
Normal file
@ -0,0 +1,488 @@
|
||||
T__0=1
|
||||
T__1=2
|
||||
T__2=3
|
||||
T__3=4
|
||||
T__4=5
|
||||
T__5=6
|
||||
T__6=7
|
||||
T__7=8
|
||||
T__8=9
|
||||
T__9=10
|
||||
SELECT=11
|
||||
FROM=12
|
||||
ADD=13
|
||||
AS=14
|
||||
ALL=15
|
||||
ANY=16
|
||||
DISTINCT=17
|
||||
WHERE=18
|
||||
GROUP=19
|
||||
BY=20
|
||||
GROUPING=21
|
||||
SETS=22
|
||||
CUBE=23
|
||||
ROLLUP=24
|
||||
ORDER=25
|
||||
HAVING=26
|
||||
LIMIT=27
|
||||
AT=28
|
||||
OR=29
|
||||
AND=30
|
||||
IN=31
|
||||
NOT=32
|
||||
NO=33
|
||||
EXISTS=34
|
||||
BETWEEN=35
|
||||
LIKE=36
|
||||
RLIKE=37
|
||||
IS=38
|
||||
NULL=39
|
||||
TRUE=40
|
||||
FALSE=41
|
||||
NULLS=42
|
||||
ASC=43
|
||||
DESC=44
|
||||
FOR=45
|
||||
INTERVAL=46
|
||||
CASE=47
|
||||
WHEN=48
|
||||
THEN=49
|
||||
ELSE=50
|
||||
END=51
|
||||
JOIN=52
|
||||
CROSS=53
|
||||
OUTER=54
|
||||
INNER=55
|
||||
LEFT=56
|
||||
SEMI=57
|
||||
RIGHT=58
|
||||
FULL=59
|
||||
NATURAL=60
|
||||
ON=61
|
||||
PIVOT=62
|
||||
LATERAL=63
|
||||
WINDOW=64
|
||||
OVER=65
|
||||
PARTITION=66
|
||||
RANGE=67
|
||||
ROWS=68
|
||||
UNBOUNDED=69
|
||||
PRECEDING=70
|
||||
FOLLOWING=71
|
||||
CURRENT=72
|
||||
FIRST=73
|
||||
AFTER=74
|
||||
LAST=75
|
||||
ROW=76
|
||||
WITH=77
|
||||
VALUES=78
|
||||
CREATE=79
|
||||
TABLE=80
|
||||
DIRECTORY=81
|
||||
VIEW=82
|
||||
REPLACE=83
|
||||
INSERT=84
|
||||
DELETE=85
|
||||
INTO=86
|
||||
DESCRIBE=87
|
||||
EXPLAIN=88
|
||||
FORMAT=89
|
||||
LOGICAL=90
|
||||
CODEGEN=91
|
||||
COST=92
|
||||
CAST=93
|
||||
SHOW=94
|
||||
TABLES=95
|
||||
COLUMNS=96
|
||||
COLUMN=97
|
||||
USE=98
|
||||
PARTITIONS=99
|
||||
FUNCTIONS=100
|
||||
DROP=101
|
||||
UNION=102
|
||||
EXCEPT=103
|
||||
SETMINUS=104
|
||||
INTERSECT=105
|
||||
TO=106
|
||||
TABLESAMPLE=107
|
||||
STRATIFY=108
|
||||
ALTER=109
|
||||
RENAME=110
|
||||
ARRAY=111
|
||||
MAP=112
|
||||
STRUCT=113
|
||||
COMMENT=114
|
||||
SET=115
|
||||
RESET=116
|
||||
DATA=117
|
||||
START=118
|
||||
TRANSACTION=119
|
||||
COMMIT=120
|
||||
ROLLBACK=121
|
||||
MACRO=122
|
||||
IGNORE=123
|
||||
BOTH=124
|
||||
LEADING=125
|
||||
TRAILING=126
|
||||
IF=127
|
||||
POSITION=128
|
||||
EXTRACT=129
|
||||
EQ=130
|
||||
NSEQ=131
|
||||
NEQ=132
|
||||
NEQJ=133
|
||||
LT=134
|
||||
LTE=135
|
||||
GT=136
|
||||
GTE=137
|
||||
PLUS=138
|
||||
MINUS=139
|
||||
ASTERISK=140
|
||||
SLASH=141
|
||||
PERCENT=142
|
||||
DIV=143
|
||||
TILDE=144
|
||||
AMPERSAND=145
|
||||
PIPE=146
|
||||
CONCAT_PIPE=147
|
||||
HAT=148
|
||||
PERCENTLIT=149
|
||||
BUCKET=150
|
||||
OUT=151
|
||||
OF=152
|
||||
SORT=153
|
||||
CLUSTER=154
|
||||
DISTRIBUTE=155
|
||||
OVERWRITE=156
|
||||
TRANSFORM=157
|
||||
REDUCE=158
|
||||
USING=159
|
||||
SERDE=160
|
||||
SERDEPROPERTIES=161
|
||||
RECORDREADER=162
|
||||
RECORDWRITER=163
|
||||
DELIMITED=164
|
||||
FIELDS=165
|
||||
TERMINATED=166
|
||||
COLLECTION=167
|
||||
ITEMS=168
|
||||
KEYS=169
|
||||
ESCAPED=170
|
||||
LINES=171
|
||||
SEPARATED=172
|
||||
FUNCTION=173
|
||||
EXTENDED=174
|
||||
REFRESH=175
|
||||
CLEAR=176
|
||||
CACHE=177
|
||||
UNCACHE=178
|
||||
LAZY=179
|
||||
FORMATTED=180
|
||||
GLOBAL=181
|
||||
TEMPORARY=182
|
||||
OPTIONS=183
|
||||
UNSET=184
|
||||
TBLPROPERTIES=185
|
||||
DBPROPERTIES=186
|
||||
BUCKETS=187
|
||||
SKEWED=188
|
||||
STORED=189
|
||||
DIRECTORIES=190
|
||||
LOCATION=191
|
||||
EXCHANGE=192
|
||||
ARCHIVE=193
|
||||
UNARCHIVE=194
|
||||
FILEFORMAT=195
|
||||
TOUCH=196
|
||||
COMPACT=197
|
||||
CONCATENATE=198
|
||||
CHANGE=199
|
||||
CASCADE=200
|
||||
RESTRICT=201
|
||||
CLUSTERED=202
|
||||
SORTED=203
|
||||
PURGE=204
|
||||
INPUTFORMAT=205
|
||||
OUTPUTFORMAT=206
|
||||
DATABASE=207
|
||||
DATABASES=208
|
||||
DFS=209
|
||||
TRUNCATE=210
|
||||
ANALYZE=211
|
||||
COMPUTE=212
|
||||
LIST=213
|
||||
STATISTICS=214
|
||||
PARTITIONED=215
|
||||
EXTERNAL=216
|
||||
DEFINED=217
|
||||
REVOKE=218
|
||||
GRANT=219
|
||||
LOCK=220
|
||||
UNLOCK=221
|
||||
MSCK=222
|
||||
REPAIR=223
|
||||
RECOVER=224
|
||||
EXPORT=225
|
||||
IMPORT=226
|
||||
LOAD=227
|
||||
ROLE=228
|
||||
ROLES=229
|
||||
COMPACTIONS=230
|
||||
PRINCIPALS=231
|
||||
TRANSACTIONS=232
|
||||
INDEX=233
|
||||
INDEXES=234
|
||||
LOCKS=235
|
||||
OPTION=236
|
||||
ANTI=237
|
||||
LOCAL=238
|
||||
INPATH=239
|
||||
WATERMARK=240
|
||||
STRING=241
|
||||
BIGINT_LITERAL=242
|
||||
SMALLINT_LITERAL=243
|
||||
TINYINT_LITERAL=244
|
||||
INTEGER_VALUE=245
|
||||
DECIMAL_VALUE=246
|
||||
DOUBLE_LITERAL=247
|
||||
BIGDECIMAL_LITERAL=248
|
||||
IDENTIFIER=249
|
||||
BACKQUOTED_IDENTIFIER=250
|
||||
SIMPLE_COMMENT=251
|
||||
BRACKETED_EMPTY_COMMENT=252
|
||||
BRACKETED_COMMENT=253
|
||||
WS=254
|
||||
UNRECOGNIZED=255
|
||||
'('=1
|
||||
')'=2
|
||||
'.'=3
|
||||
','=4
|
||||
'/*+'=5
|
||||
'*/'=6
|
||||
'->'=7
|
||||
'['=8
|
||||
']'=9
|
||||
':'=10
|
||||
'SELECT'=11
|
||||
'FROM'=12
|
||||
'ADD'=13
|
||||
'AS'=14
|
||||
'ALL'=15
|
||||
'ANY'=16
|
||||
'DISTINCT'=17
|
||||
'WHERE'=18
|
||||
'GROUP'=19
|
||||
'BY'=20
|
||||
'GROUPING'=21
|
||||
'SETS'=22
|
||||
'CUBE'=23
|
||||
'ROLLUP'=24
|
||||
'ORDER'=25
|
||||
'HAVING'=26
|
||||
'LIMIT'=27
|
||||
'AT'=28
|
||||
'OR'=29
|
||||
'AND'=30
|
||||
'IN'=31
|
||||
'NO'=33
|
||||
'EXISTS'=34
|
||||
'BETWEEN'=35
|
||||
'LIKE'=36
|
||||
'IS'=38
|
||||
'NULL'=39
|
||||
'TRUE'=40
|
||||
'FALSE'=41
|
||||
'NULLS'=42
|
||||
'ASC'=43
|
||||
'DESC'=44
|
||||
'FOR'=45
|
||||
'INTERVAL'=46
|
||||
'CASE'=47
|
||||
'WHEN'=48
|
||||
'THEN'=49
|
||||
'ELSE'=50
|
||||
'END'=51
|
||||
'JOIN'=52
|
||||
'CROSS'=53
|
||||
'OUTER'=54
|
||||
'INNER'=55
|
||||
'LEFT'=56
|
||||
'SEMI'=57
|
||||
'RIGHT'=58
|
||||
'FULL'=59
|
||||
'NATURAL'=60
|
||||
'ON'=61
|
||||
'PIVOT'=62
|
||||
'LATERAL'=63
|
||||
'WINDOW'=64
|
||||
'OVER'=65
|
||||
'PARTITION'=66
|
||||
'RANGE'=67
|
||||
'ROWS'=68
|
||||
'UNBOUNDED'=69
|
||||
'PRECEDING'=70
|
||||
'FOLLOWING'=71
|
||||
'CURRENT'=72
|
||||
'FIRST'=73
|
||||
'AFTER'=74
|
||||
'LAST'=75
|
||||
'ROW'=76
|
||||
'WITH'=77
|
||||
'VALUES'=78
|
||||
'CREATE'=79
|
||||
'TABLE'=80
|
||||
'DIRECTORY'=81
|
||||
'VIEW'=82
|
||||
'REPLACE'=83
|
||||
'INSERT'=84
|
||||
'DELETE'=85
|
||||
'INTO'=86
|
||||
'DESCRIBE'=87
|
||||
'EXPLAIN'=88
|
||||
'FORMAT'=89
|
||||
'LOGICAL'=90
|
||||
'CODEGEN'=91
|
||||
'COST'=92
|
||||
'CAST'=93
|
||||
'SHOW'=94
|
||||
'TABLES'=95
|
||||
'COLUMNS'=96
|
||||
'COLUMN'=97
|
||||
'USE'=98
|
||||
'PARTITIONS'=99
|
||||
'FUNCTIONS'=100
|
||||
'DROP'=101
|
||||
'UNION'=102
|
||||
'EXCEPT'=103
|
||||
'MINUS'=104
|
||||
'INTERSECT'=105
|
||||
'TO'=106
|
||||
'TABLESAMPLE'=107
|
||||
'STRATIFY'=108
|
||||
'ALTER'=109
|
||||
'RENAME'=110
|
||||
'ARRAY'=111
|
||||
'MAP'=112
|
||||
'STRUCT'=113
|
||||
'COMMENT'=114
|
||||
'SET'=115
|
||||
'RESET'=116
|
||||
'DATA'=117
|
||||
'START'=118
|
||||
'TRANSACTION'=119
|
||||
'COMMIT'=120
|
||||
'ROLLBACK'=121
|
||||
'MACRO'=122
|
||||
'IGNORE'=123
|
||||
'BOTH'=124
|
||||
'LEADING'=125
|
||||
'TRAILING'=126
|
||||
'IF'=127
|
||||
'POSITION'=128
|
||||
'EXTRACT'=129
|
||||
'<=>'=131
|
||||
'<>'=132
|
||||
'!='=133
|
||||
'<'=134
|
||||
'>'=136
|
||||
'+'=138
|
||||
'-'=139
|
||||
'*'=140
|
||||
'/'=141
|
||||
'%'=142
|
||||
'DIV'=143
|
||||
'~'=144
|
||||
'&'=145
|
||||
'|'=146
|
||||
'||'=147
|
||||
'^'=148
|
||||
'PERCENT'=149
|
||||
'BUCKET'=150
|
||||
'OUT'=151
|
||||
'OF'=152
|
||||
'SORT'=153
|
||||
'CLUSTER'=154
|
||||
'DISTRIBUTE'=155
|
||||
'OVERWRITE'=156
|
||||
'TRANSFORM'=157
|
||||
'REDUCE'=158
|
||||
'USING'=159
|
||||
'SERDE'=160
|
||||
'SERDEPROPERTIES'=161
|
||||
'RECORDREADER'=162
|
||||
'RECORDWRITER'=163
|
||||
'DELIMITED'=164
|
||||
'FIELDS'=165
|
||||
'TERMINATED'=166
|
||||
'COLLECTION'=167
|
||||
'ITEMS'=168
|
||||
'KEYS'=169
|
||||
'ESCAPED'=170
|
||||
'LINES'=171
|
||||
'SEPARATED'=172
|
||||
'FUNCTION'=173
|
||||
'EXTENDED'=174
|
||||
'REFRESH'=175
|
||||
'CLEAR'=176
|
||||
'CACHE'=177
|
||||
'UNCACHE'=178
|
||||
'LAZY'=179
|
||||
'FORMATTED'=180
|
||||
'GLOBAL'=181
|
||||
'OPTIONS'=183
|
||||
'UNSET'=184
|
||||
'TBLPROPERTIES'=185
|
||||
'DBPROPERTIES'=186
|
||||
'BUCKETS'=187
|
||||
'SKEWED'=188
|
||||
'STORED'=189
|
||||
'DIRECTORIES'=190
|
||||
'LOCATION'=191
|
||||
'EXCHANGE'=192
|
||||
'ARCHIVE'=193
|
||||
'UNARCHIVE'=194
|
||||
'FILEFORMAT'=195
|
||||
'TOUCH'=196
|
||||
'COMPACT'=197
|
||||
'CONCATENATE'=198
|
||||
'CHANGE'=199
|
||||
'CASCADE'=200
|
||||
'RESTRICT'=201
|
||||
'CLUSTERED'=202
|
||||
'SORTED'=203
|
||||
'PURGE'=204
|
||||
'INPUTFORMAT'=205
|
||||
'OUTPUTFORMAT'=206
|
||||
'DFS'=209
|
||||
'TRUNCATE'=210
|
||||
'ANALYZE'=211
|
||||
'COMPUTE'=212
|
||||
'LIST'=213
|
||||
'STATISTICS'=214
|
||||
'PARTITIONED'=215
|
||||
'EXTERNAL'=216
|
||||
'DEFINED'=217
|
||||
'REVOKE'=218
|
||||
'GRANT'=219
|
||||
'LOCK'=220
|
||||
'UNLOCK'=221
|
||||
'MSCK'=222
|
||||
'REPAIR'=223
|
||||
'RECOVER'=224
|
||||
'EXPORT'=225
|
||||
'IMPORT'=226
|
||||
'LOAD'=227
|
||||
'ROLE'=228
|
||||
'ROLES'=229
|
||||
'COMPACTIONS'=230
|
||||
'PRINCIPALS'=231
|
||||
'TRANSACTIONS'=232
|
||||
'INDEX'=233
|
||||
'INDEXES'=234
|
||||
'LOCKS'=235
|
||||
'OPTION'=236
|
||||
'ANTI'=237
|
||||
'LOCAL'=238
|
||||
'INPATH'=239
|
||||
'WATERMARK'=240
|
||||
'/**/'=252
|
786
src/antlr4/flinksql/sqlLexer.interp
Normal file
786
src/antlr4/flinksql/sqlLexer.interp
Normal file
File diff suppressed because one or more lines are too long
2051
src/antlr4/flinksql/sqlLexer.js
Normal file
2051
src/antlr4/flinksql/sqlLexer.js
Normal file
File diff suppressed because it is too large
Load Diff
488
src/antlr4/flinksql/sqlLexer.tokens
Normal file
488
src/antlr4/flinksql/sqlLexer.tokens
Normal file
@ -0,0 +1,488 @@
|
||||
T__0=1
|
||||
T__1=2
|
||||
T__2=3
|
||||
T__3=4
|
||||
T__4=5
|
||||
T__5=6
|
||||
T__6=7
|
||||
T__7=8
|
||||
T__8=9
|
||||
T__9=10
|
||||
SELECT=11
|
||||
FROM=12
|
||||
ADD=13
|
||||
AS=14
|
||||
ALL=15
|
||||
ANY=16
|
||||
DISTINCT=17
|
||||
WHERE=18
|
||||
GROUP=19
|
||||
BY=20
|
||||
GROUPING=21
|
||||
SETS=22
|
||||
CUBE=23
|
||||
ROLLUP=24
|
||||
ORDER=25
|
||||
HAVING=26
|
||||
LIMIT=27
|
||||
AT=28
|
||||
OR=29
|
||||
AND=30
|
||||
IN=31
|
||||
NOT=32
|
||||
NO=33
|
||||
EXISTS=34
|
||||
BETWEEN=35
|
||||
LIKE=36
|
||||
RLIKE=37
|
||||
IS=38
|
||||
NULL=39
|
||||
TRUE=40
|
||||
FALSE=41
|
||||
NULLS=42
|
||||
ASC=43
|
||||
DESC=44
|
||||
FOR=45
|
||||
INTERVAL=46
|
||||
CASE=47
|
||||
WHEN=48
|
||||
THEN=49
|
||||
ELSE=50
|
||||
END=51
|
||||
JOIN=52
|
||||
CROSS=53
|
||||
OUTER=54
|
||||
INNER=55
|
||||
LEFT=56
|
||||
SEMI=57
|
||||
RIGHT=58
|
||||
FULL=59
|
||||
NATURAL=60
|
||||
ON=61
|
||||
PIVOT=62
|
||||
LATERAL=63
|
||||
WINDOW=64
|
||||
OVER=65
|
||||
PARTITION=66
|
||||
RANGE=67
|
||||
ROWS=68
|
||||
UNBOUNDED=69
|
||||
PRECEDING=70
|
||||
FOLLOWING=71
|
||||
CURRENT=72
|
||||
FIRST=73
|
||||
AFTER=74
|
||||
LAST=75
|
||||
ROW=76
|
||||
WITH=77
|
||||
VALUES=78
|
||||
CREATE=79
|
||||
TABLE=80
|
||||
DIRECTORY=81
|
||||
VIEW=82
|
||||
REPLACE=83
|
||||
INSERT=84
|
||||
DELETE=85
|
||||
INTO=86
|
||||
DESCRIBE=87
|
||||
EXPLAIN=88
|
||||
FORMAT=89
|
||||
LOGICAL=90
|
||||
CODEGEN=91
|
||||
COST=92
|
||||
CAST=93
|
||||
SHOW=94
|
||||
TABLES=95
|
||||
COLUMNS=96
|
||||
COLUMN=97
|
||||
USE=98
|
||||
PARTITIONS=99
|
||||
FUNCTIONS=100
|
||||
DROP=101
|
||||
UNION=102
|
||||
EXCEPT=103
|
||||
SETMINUS=104
|
||||
INTERSECT=105
|
||||
TO=106
|
||||
TABLESAMPLE=107
|
||||
STRATIFY=108
|
||||
ALTER=109
|
||||
RENAME=110
|
||||
ARRAY=111
|
||||
MAP=112
|
||||
STRUCT=113
|
||||
COMMENT=114
|
||||
SET=115
|
||||
RESET=116
|
||||
DATA=117
|
||||
START=118
|
||||
TRANSACTION=119
|
||||
COMMIT=120
|
||||
ROLLBACK=121
|
||||
MACRO=122
|
||||
IGNORE=123
|
||||
BOTH=124
|
||||
LEADING=125
|
||||
TRAILING=126
|
||||
IF=127
|
||||
POSITION=128
|
||||
EXTRACT=129
|
||||
EQ=130
|
||||
NSEQ=131
|
||||
NEQ=132
|
||||
NEQJ=133
|
||||
LT=134
|
||||
LTE=135
|
||||
GT=136
|
||||
GTE=137
|
||||
PLUS=138
|
||||
MINUS=139
|
||||
ASTERISK=140
|
||||
SLASH=141
|
||||
PERCENT=142
|
||||
DIV=143
|
||||
TILDE=144
|
||||
AMPERSAND=145
|
||||
PIPE=146
|
||||
CONCAT_PIPE=147
|
||||
HAT=148
|
||||
PERCENTLIT=149
|
||||
BUCKET=150
|
||||
OUT=151
|
||||
OF=152
|
||||
SORT=153
|
||||
CLUSTER=154
|
||||
DISTRIBUTE=155
|
||||
OVERWRITE=156
|
||||
TRANSFORM=157
|
||||
REDUCE=158
|
||||
USING=159
|
||||
SERDE=160
|
||||
SERDEPROPERTIES=161
|
||||
RECORDREADER=162
|
||||
RECORDWRITER=163
|
||||
DELIMITED=164
|
||||
FIELDS=165
|
||||
TERMINATED=166
|
||||
COLLECTION=167
|
||||
ITEMS=168
|
||||
KEYS=169
|
||||
ESCAPED=170
|
||||
LINES=171
|
||||
SEPARATED=172
|
||||
FUNCTION=173
|
||||
EXTENDED=174
|
||||
REFRESH=175
|
||||
CLEAR=176
|
||||
CACHE=177
|
||||
UNCACHE=178
|
||||
LAZY=179
|
||||
FORMATTED=180
|
||||
GLOBAL=181
|
||||
TEMPORARY=182
|
||||
OPTIONS=183
|
||||
UNSET=184
|
||||
TBLPROPERTIES=185
|
||||
DBPROPERTIES=186
|
||||
BUCKETS=187
|
||||
SKEWED=188
|
||||
STORED=189
|
||||
DIRECTORIES=190
|
||||
LOCATION=191
|
||||
EXCHANGE=192
|
||||
ARCHIVE=193
|
||||
UNARCHIVE=194
|
||||
FILEFORMAT=195
|
||||
TOUCH=196
|
||||
COMPACT=197
|
||||
CONCATENATE=198
|
||||
CHANGE=199
|
||||
CASCADE=200
|
||||
RESTRICT=201
|
||||
CLUSTERED=202
|
||||
SORTED=203
|
||||
PURGE=204
|
||||
INPUTFORMAT=205
|
||||
OUTPUTFORMAT=206
|
||||
DATABASE=207
|
||||
DATABASES=208
|
||||
DFS=209
|
||||
TRUNCATE=210
|
||||
ANALYZE=211
|
||||
COMPUTE=212
|
||||
LIST=213
|
||||
STATISTICS=214
|
||||
PARTITIONED=215
|
||||
EXTERNAL=216
|
||||
DEFINED=217
|
||||
REVOKE=218
|
||||
GRANT=219
|
||||
LOCK=220
|
||||
UNLOCK=221
|
||||
MSCK=222
|
||||
REPAIR=223
|
||||
RECOVER=224
|
||||
EXPORT=225
|
||||
IMPORT=226
|
||||
LOAD=227
|
||||
ROLE=228
|
||||
ROLES=229
|
||||
COMPACTIONS=230
|
||||
PRINCIPALS=231
|
||||
TRANSACTIONS=232
|
||||
INDEX=233
|
||||
INDEXES=234
|
||||
LOCKS=235
|
||||
OPTION=236
|
||||
ANTI=237
|
||||
LOCAL=238
|
||||
INPATH=239
|
||||
WATERMARK=240
|
||||
STRING=241
|
||||
BIGINT_LITERAL=242
|
||||
SMALLINT_LITERAL=243
|
||||
TINYINT_LITERAL=244
|
||||
INTEGER_VALUE=245
|
||||
DECIMAL_VALUE=246
|
||||
DOUBLE_LITERAL=247
|
||||
BIGDECIMAL_LITERAL=248
|
||||
IDENTIFIER=249
|
||||
BACKQUOTED_IDENTIFIER=250
|
||||
SIMPLE_COMMENT=251
|
||||
BRACKETED_EMPTY_COMMENT=252
|
||||
BRACKETED_COMMENT=253
|
||||
WS=254
|
||||
UNRECOGNIZED=255
|
||||
'('=1
|
||||
')'=2
|
||||
'.'=3
|
||||
','=4
|
||||
'/*+'=5
|
||||
'*/'=6
|
||||
'->'=7
|
||||
'['=8
|
||||
']'=9
|
||||
':'=10
|
||||
'SELECT'=11
|
||||
'FROM'=12
|
||||
'ADD'=13
|
||||
'AS'=14
|
||||
'ALL'=15
|
||||
'ANY'=16
|
||||
'DISTINCT'=17
|
||||
'WHERE'=18
|
||||
'GROUP'=19
|
||||
'BY'=20
|
||||
'GROUPING'=21
|
||||
'SETS'=22
|
||||
'CUBE'=23
|
||||
'ROLLUP'=24
|
||||
'ORDER'=25
|
||||
'HAVING'=26
|
||||
'LIMIT'=27
|
||||
'AT'=28
|
||||
'OR'=29
|
||||
'AND'=30
|
||||
'IN'=31
|
||||
'NO'=33
|
||||
'EXISTS'=34
|
||||
'BETWEEN'=35
|
||||
'LIKE'=36
|
||||
'IS'=38
|
||||
'NULL'=39
|
||||
'TRUE'=40
|
||||
'FALSE'=41
|
||||
'NULLS'=42
|
||||
'ASC'=43
|
||||
'DESC'=44
|
||||
'FOR'=45
|
||||
'INTERVAL'=46
|
||||
'CASE'=47
|
||||
'WHEN'=48
|
||||
'THEN'=49
|
||||
'ELSE'=50
|
||||
'END'=51
|
||||
'JOIN'=52
|
||||
'CROSS'=53
|
||||
'OUTER'=54
|
||||
'INNER'=55
|
||||
'LEFT'=56
|
||||
'SEMI'=57
|
||||
'RIGHT'=58
|
||||
'FULL'=59
|
||||
'NATURAL'=60
|
||||
'ON'=61
|
||||
'PIVOT'=62
|
||||
'LATERAL'=63
|
||||
'WINDOW'=64
|
||||
'OVER'=65
|
||||
'PARTITION'=66
|
||||
'RANGE'=67
|
||||
'ROWS'=68
|
||||
'UNBOUNDED'=69
|
||||
'PRECEDING'=70
|
||||
'FOLLOWING'=71
|
||||
'CURRENT'=72
|
||||
'FIRST'=73
|
||||
'AFTER'=74
|
||||
'LAST'=75
|
||||
'ROW'=76
|
||||
'WITH'=77
|
||||
'VALUES'=78
|
||||
'CREATE'=79
|
||||
'TABLE'=80
|
||||
'DIRECTORY'=81
|
||||
'VIEW'=82
|
||||
'REPLACE'=83
|
||||
'INSERT'=84
|
||||
'DELETE'=85
|
||||
'INTO'=86
|
||||
'DESCRIBE'=87
|
||||
'EXPLAIN'=88
|
||||
'FORMAT'=89
|
||||
'LOGICAL'=90
|
||||
'CODEGEN'=91
|
||||
'COST'=92
|
||||
'CAST'=93
|
||||
'SHOW'=94
|
||||
'TABLES'=95
|
||||
'COLUMNS'=96
|
||||
'COLUMN'=97
|
||||
'USE'=98
|
||||
'PARTITIONS'=99
|
||||
'FUNCTIONS'=100
|
||||
'DROP'=101
|
||||
'UNION'=102
|
||||
'EXCEPT'=103
|
||||
'MINUS'=104
|
||||
'INTERSECT'=105
|
||||
'TO'=106
|
||||
'TABLESAMPLE'=107
|
||||
'STRATIFY'=108
|
||||
'ALTER'=109
|
||||
'RENAME'=110
|
||||
'ARRAY'=111
|
||||
'MAP'=112
|
||||
'STRUCT'=113
|
||||
'COMMENT'=114
|
||||
'SET'=115
|
||||
'RESET'=116
|
||||
'DATA'=117
|
||||
'START'=118
|
||||
'TRANSACTION'=119
|
||||
'COMMIT'=120
|
||||
'ROLLBACK'=121
|
||||
'MACRO'=122
|
||||
'IGNORE'=123
|
||||
'BOTH'=124
|
||||
'LEADING'=125
|
||||
'TRAILING'=126
|
||||
'IF'=127
|
||||
'POSITION'=128
|
||||
'EXTRACT'=129
|
||||
'<=>'=131
|
||||
'<>'=132
|
||||
'!='=133
|
||||
'<'=134
|
||||
'>'=136
|
||||
'+'=138
|
||||
'-'=139
|
||||
'*'=140
|
||||
'/'=141
|
||||
'%'=142
|
||||
'DIV'=143
|
||||
'~'=144
|
||||
'&'=145
|
||||
'|'=146
|
||||
'||'=147
|
||||
'^'=148
|
||||
'PERCENT'=149
|
||||
'BUCKET'=150
|
||||
'OUT'=151
|
||||
'OF'=152
|
||||
'SORT'=153
|
||||
'CLUSTER'=154
|
||||
'DISTRIBUTE'=155
|
||||
'OVERWRITE'=156
|
||||
'TRANSFORM'=157
|
||||
'REDUCE'=158
|
||||
'USING'=159
|
||||
'SERDE'=160
|
||||
'SERDEPROPERTIES'=161
|
||||
'RECORDREADER'=162
|
||||
'RECORDWRITER'=163
|
||||
'DELIMITED'=164
|
||||
'FIELDS'=165
|
||||
'TERMINATED'=166
|
||||
'COLLECTION'=167
|
||||
'ITEMS'=168
|
||||
'KEYS'=169
|
||||
'ESCAPED'=170
|
||||
'LINES'=171
|
||||
'SEPARATED'=172
|
||||
'FUNCTION'=173
|
||||
'EXTENDED'=174
|
||||
'REFRESH'=175
|
||||
'CLEAR'=176
|
||||
'CACHE'=177
|
||||
'UNCACHE'=178
|
||||
'LAZY'=179
|
||||
'FORMATTED'=180
|
||||
'GLOBAL'=181
|
||||
'OPTIONS'=183
|
||||
'UNSET'=184
|
||||
'TBLPROPERTIES'=185
|
||||
'DBPROPERTIES'=186
|
||||
'BUCKETS'=187
|
||||
'SKEWED'=188
|
||||
'STORED'=189
|
||||
'DIRECTORIES'=190
|
||||
'LOCATION'=191
|
||||
'EXCHANGE'=192
|
||||
'ARCHIVE'=193
|
||||
'UNARCHIVE'=194
|
||||
'FILEFORMAT'=195
|
||||
'TOUCH'=196
|
||||
'COMPACT'=197
|
||||
'CONCATENATE'=198
|
||||
'CHANGE'=199
|
||||
'CASCADE'=200
|
||||
'RESTRICT'=201
|
||||
'CLUSTERED'=202
|
||||
'SORTED'=203
|
||||
'PURGE'=204
|
||||
'INPUTFORMAT'=205
|
||||
'OUTPUTFORMAT'=206
|
||||
'DFS'=209
|
||||
'TRUNCATE'=210
|
||||
'ANALYZE'=211
|
||||
'COMPUTE'=212
|
||||
'LIST'=213
|
||||
'STATISTICS'=214
|
||||
'PARTITIONED'=215
|
||||
'EXTERNAL'=216
|
||||
'DEFINED'=217
|
||||
'REVOKE'=218
|
||||
'GRANT'=219
|
||||
'LOCK'=220
|
||||
'UNLOCK'=221
|
||||
'MSCK'=222
|
||||
'REPAIR'=223
|
||||
'RECOVER'=224
|
||||
'EXPORT'=225
|
||||
'IMPORT'=226
|
||||
'LOAD'=227
|
||||
'ROLE'=228
|
||||
'ROLES'=229
|
||||
'COMPACTIONS'=230
|
||||
'PRINCIPALS'=231
|
||||
'TRANSACTIONS'=232
|
||||
'INDEX'=233
|
||||
'INDEXES'=234
|
||||
'LOCKS'=235
|
||||
'OPTION'=236
|
||||
'ANTI'=237
|
||||
'LOCAL'=238
|
||||
'INPATH'=239
|
||||
'WATERMARK'=240
|
||||
'/**/'=252
|
1878
src/antlr4/flinksql/sqlListener.js
Normal file
1878
src/antlr4/flinksql/sqlListener.js
Normal file
File diff suppressed because it is too large
Load Diff
25744
src/antlr4/flinksql/sqlParser.js
Normal file
25744
src/antlr4/flinksql/sqlParser.js
Normal file
File diff suppressed because one or more lines are too long
1258
src/antlr4/flinksql/sqlVisitor.js
Normal file
1258
src/antlr4/flinksql/sqlVisitor.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,9 @@
|
||||
import * as parser from "./lib/parser";
|
||||
import * as filter from "./lib/filter";
|
||||
import flinksqlParser from './lib/flinkParser';
|
||||
|
||||
export {
|
||||
parser,
|
||||
filter
|
||||
filter,
|
||||
flinksqlParser
|
||||
};
|
57
src/lib/flinkParser.ts
Normal file
57
src/lib/flinkParser.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import * as antlr4 from 'antlr4'
|
||||
import { ErrorListener } from 'antlr4/error';
|
||||
import { sqlLexer } from '../antlr4/flinksql/sqlLexer';
|
||||
import { sqlParser } from '../antlr4/flinksql/sqlParser';
|
||||
import { sqlVisitor } from '../antlr4/flinksql/sqlVisitor';
|
||||
|
||||
import { splitSql } from '../utils'
|
||||
|
||||
interface SyntaxError {
|
||||
line: number;
|
||||
column: number;
|
||||
token: antlr4.Token;
|
||||
errorMsg: string;
|
||||
}
|
||||
|
||||
class SqlErrorListener extends ErrorListener {
|
||||
error: SyntaxError = null;
|
||||
syntaxError (recognizer: antlr4.Recognizer, offendingSymbol: antlr4.Token, line: number, charPositionInLine: number, msg: string, e: any) {
|
||||
this.error = {
|
||||
line,
|
||||
column: charPositionInLine,
|
||||
token: offendingSymbol,
|
||||
errorMsg: msg
|
||||
};
|
||||
}
|
||||
}
|
||||
function parserSingle (sql: string,) {
|
||||
if (!sql || !sql.trim()) {
|
||||
return null;
|
||||
}
|
||||
const inputStream = new antlr4.InputStream(sql.toUpperCase());
|
||||
const lexer = <unknown>new sqlLexer(inputStream) as antlr4.Lexer;
|
||||
const tokenStream = new antlr4.CommonTokenStream(lexer);
|
||||
const parser: any = new sqlParser(tokenStream);
|
||||
parser.buildParseTrees = true;
|
||||
let listener = new SqlErrorListener();
|
||||
parser.addErrorListener(listener)
|
||||
parser.singleStatement();
|
||||
return listener.error;
|
||||
}
|
||||
function parserSyntax (sql: sql): SyntaxError {
|
||||
let runSql = typeof sql == 'string' ? sql : sql.join('');
|
||||
const sqls = splitSql(runSql);
|
||||
for (let i = 0, index = 0; i < sqls.length; i++) {
|
||||
/**
|
||||
* 这边不取分号
|
||||
*/
|
||||
let sql = new Array(index).fill(' ').join('') + runSql.substring(index, sqls[i]);
|
||||
let err = parserSingle(sql);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
index = sqls[i] + 1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
export default parserSyntax;
|
@ -2,7 +2,6 @@
|
||||
import * as sqlSyntaxParser from '../core/sqlSyntaxParser';
|
||||
import * as sqlAutoCompleteParser from '../core/sqlAutoCompleteParser';
|
||||
|
||||
type sql = string | string [];
|
||||
enum sqlType {
|
||||
Hive = 'hive',
|
||||
None = 'sql',
|
||||
@ -29,12 +28,13 @@ function parseSyntax(sql: sql, type:sqlType = sqlType.Hive): sqlSyntaxParser.Syn
|
||||
/**
|
||||
* 自动补全提示
|
||||
*/
|
||||
function parserSql(sql: sql, type:sqlType = sqlType.Hive): sqlAutoCompleteParser.CompleteResult {
|
||||
function parserSql(sql: sql, type: sqlType = sqlType.Hive): sqlAutoCompleteParser.CompleteResult {
|
||||
const parserArgs = sqlToParserArgs(sql);
|
||||
return sqlAutoCompleteParser.parser.parseSql(parserArgs[0], parserArgs[1], type, false)
|
||||
}
|
||||
|
||||
export {
|
||||
parseSyntax,
|
||||
parserSql
|
||||
parserSql,
|
||||
sqlType
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
1
src/typing/base.d.ts
vendored
Normal file
1
src/typing/base.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
declare type sql = string | string[]
|
@ -20,7 +20,95 @@ function replaceStrFormIndexArr(str, replaceStr, indexArr) {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function splitSql (sql: string) {
|
||||
let haveEnd = true;
|
||||
if (!sql.endsWith(';')) {
|
||||
sql += ';';
|
||||
haveEnd = false;
|
||||
}
|
||||
interface splitParser {
|
||||
index: number;
|
||||
queue: string;
|
||||
sqls: number[];
|
||||
}
|
||||
// 处理引号
|
||||
function quoteToken (parser: splitParser, sql: string): string {
|
||||
let queue = parser.queue;
|
||||
let endsWith = queue[queue.length - 1];
|
||||
if (endsWith == '\'' || endsWith == '"') {
|
||||
let nextToken = sql.indexOf(endsWith, parser.index + 1);
|
||||
if (nextToken != -1) {
|
||||
parser.index = nextToken;
|
||||
parser.queue = '';
|
||||
} else {
|
||||
parser.index = sql.length - 1;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 处理单行注释
|
||||
function singleLineCommentToken (parser: splitParser, sql: string): string {
|
||||
let queue = parser.queue;
|
||||
if (queue.endsWith('--')) {
|
||||
let nextToken = sql.indexOf('\n', parser.index + 1);
|
||||
if (nextToken != -1) {
|
||||
parser.index = nextToken;
|
||||
queue = '';
|
||||
} else {
|
||||
parser.index = sql.length - 1;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 处理多行注释
|
||||
function multipleLineCommentToken (parser: splitParser, sql: string): string {
|
||||
let queue = parser.queue;
|
||||
if (queue.endsWith('/*')) {
|
||||
let nextToken = sql.indexOf('*/', parser.index + 1);
|
||||
if (nextToken != -1) {
|
||||
parser.index = nextToken + 1;
|
||||
parser.queue = '';
|
||||
} else {
|
||||
parser.index = sql.length - 1;
|
||||
parser.queue = '';
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function splitToken (parser: splitParser, sql: string): string {
|
||||
let queue = parser.queue;
|
||||
if (queue.endsWith(';')) {
|
||||
if (!haveEnd && parser.index == sql.length - 1) {
|
||||
parser.sqls.push(parser.index - 1);
|
||||
queue = '';
|
||||
} else {
|
||||
parser.sqls.push(parser.index);
|
||||
queue = '';
|
||||
}
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
let parser: splitParser = {
|
||||
index: 0,
|
||||
queue: '',
|
||||
sqls: []
|
||||
};
|
||||
for (parser.index = 0; parser.index < sql.length; parser.index++) {
|
||||
let char = sql[parser.index];
|
||||
parser.queue += char;
|
||||
let tokenFuncs = [quoteToken, singleLineCommentToken, multipleLineCommentToken, splitToken];
|
||||
for (let i = 0; i < tokenFuncs.length; i++) {
|
||||
tokenFuncs[i](parser, sql);
|
||||
}
|
||||
}
|
||||
return parser.sqls;
|
||||
}
|
||||
export {
|
||||
replaceStrFormIndexArr
|
||||
replaceStrFormIndexArr,
|
||||
splitSql
|
||||
}
|
@ -1,19 +1,21 @@
|
||||
const dtSqlParser = require('../lib/index');
|
||||
import * as dtSqlParser from '../src';
|
||||
import { SyntaxResult } from '../src/core/sqlSyntaxParser';
|
||||
const parser = dtSqlParser.parser;
|
||||
const filter = dtSqlParser.filter;
|
||||
const flinksqlParser = dtSqlParser.flinksqlParser;
|
||||
|
||||
|
||||
describe('complete test', () => {
|
||||
describe('hive', () => {
|
||||
test('complete result', () => {
|
||||
const sql = 'select id,name from user ';
|
||||
const result = parser.parserSql([sql, ''], 'hive');
|
||||
const result = parser.parserSql([sql, ''], dtSqlParser.parser.sqlType.Hive);
|
||||
expect(result.locations).toBeInstanceOf(Array);
|
||||
expect(result.suggestKeywords).toBeInstanceOf(Array);
|
||||
});
|
||||
test('empty result', () => {
|
||||
const sql = 'i';
|
||||
const result = parser.parserSql([sql, ''], 'hive');
|
||||
const result = parser.parserSql([sql, ''], dtSqlParser.parser.sqlType.Hive);
|
||||
expect(result.locations).toBeInstanceOf(Array);
|
||||
expect(result.locations).toHaveLength(0);
|
||||
expect(result.suggestKeywords).toBeInstanceOf(Array);
|
||||
@ -25,12 +27,12 @@ describe('syntax test', () => {
|
||||
describe('hive', () => {
|
||||
test('no error', () => {
|
||||
const sql = 'select id,name from user ';
|
||||
const result = parser.parseSyntax([sql, ''], 'hive');
|
||||
const result = parser.parseSyntax([sql, ''], dtSqlParser.parser.sqlType.Hive);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
test('select table should not be null', () => {
|
||||
const sql = 'select id,name from ';
|
||||
const result = parser.parseSyntax([sql, ''], 'hive');
|
||||
const result = parser.parseSyntax([sql, ''], dtSqlParser.parser.sqlType.Hive) as SyntaxResult;
|
||||
expect(result.loc).toEqual({
|
||||
first_line: 1,
|
||||
last_line: 1,
|
||||
@ -44,7 +46,7 @@ describe('syntax test', () => {
|
||||
,order_date bigint comment 'order date'
|
||||
)comment 'order table'
|
||||
PARTITIONED BY (ds string);`;
|
||||
const result = parser.parseSyntax([sql, ''], 'hive');
|
||||
const result = parser.parseSyntax([sql, ''], dtSqlParser.parser.sqlType.Hive) as SyntaxResult;
|
||||
expect(result.text).toBe('1exists');
|
||||
expect(result.loc).toEqual({
|
||||
first_line: 1,
|
||||
@ -54,4 +56,26 @@ describe('syntax test', () => {
|
||||
})
|
||||
});
|
||||
})
|
||||
describe('flinksql', () => {
|
||||
test('no error', () => {
|
||||
const sql = `select id from user.id;`;
|
||||
const result = flinksqlParser(sql);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
test('empty sql', () => {
|
||||
const sql = ``;
|
||||
const result = flinksqlParser(sql);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
test('syntax error', () => {
|
||||
const sql = 'select id from user.id; \nselect id from us*er.id; \nselect id from *user.id;';
|
||||
const result = flinksqlParser(sql);
|
||||
expect(result).toMatchObject({
|
||||
line: 2,
|
||||
column: 17,
|
||||
});
|
||||
expect(result.token.start).toBe(42);
|
||||
expect(result.token.stop).toBe(42);
|
||||
})
|
||||
})
|
||||
})
|
37
test/t.js
37
test/t.js
@ -0,0 +1,37 @@
|
||||
const dtSqlParser = require('../lib/index');
|
||||
const flinkParser = require('../lib/lib/flinkParser').default;
|
||||
const parser = dtSqlParser.parser;
|
||||
|
||||
console.log(flinkParser(`select * from user
|
||||
wh1ere a`))
|
||||
console.time('t')
|
||||
const sql = `INSERT INTO TABLE STUDENT_SCORES VALUES
|
||||
('1','111','68','69','90','CLASS1','DEPARTMENT1'),
|
||||
('2','112','73','80','96','CLASS1','DEPARTMENT1'),
|
||||
('3','113','90','74','75','CLASS1','DEPARTMENT1'),
|
||||
('4','114','89','94','93','CLASS1','DEPARTMENT2'),
|
||||
('5','115','99','93','89','CLASS1','DEPARTMENT1'),
|
||||
('6','121','96','74','79','CLASS2','DEPARTMENT1'),
|
||||
('7','122','89','86','85','CLASS2','DEPARTMENT1'),
|
||||
('8','123','70','78','61','CLASS2','DEPARTMENT1'),
|
||||
('9','124','76','70','76','CLASS2','DEPARTMENT1'),
|
||||
('10','211','89','93','60','CLASS1','DEPARTMENT2'),
|
||||
('11','212','76','83','75','CLASS1','DEPARTMENT2'),
|
||||
('12','213','71','94','90','CLASS2','DEPARTMENT2'),
|
||||
('13','214','94','94','66','CLASS1','DEPARTMENT2'),
|
||||
('14','215','84','82','73','CLASS1','DEPARTMENT2'),
|
||||
('15','216','85','74','93','CLASS1','DEPARTMENT2'),
|
||||
('16','221','77','99','61','CLASS2','DEPARTMENT2'),
|
||||
('17','222','80','78','96','CLASS2','DEPARTMENT2'),
|
||||
('18','223','79','74','96','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('20','225','82','85','63','CLASS2','DEPARTMENT2')`;
|
||||
const result = parser.parserSql([sql, ''], 'hive');
|
||||
console.timeEnd('t')
|
20
test/utils/index.test.ts
Normal file
20
test/utils/index.test.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import * as utils from '../../src/utils';
|
||||
describe('utils', () => {
|
||||
describe('split sql', () => {
|
||||
test('single', () => {
|
||||
let sql = 'select id,name from user';
|
||||
let result = utils.splitSql(sql);
|
||||
expect(result).toEqual([sql.length - 1])
|
||||
sql += ';';
|
||||
result = utils.splitSql(sql);
|
||||
expect(result).toEqual([sql.length - 1])
|
||||
});
|
||||
test('multiple', () => {
|
||||
const sql = `-- a ;
|
||||
select * from a;
|
||||
select user from b`;
|
||||
const result = utils.splitSql(sql);
|
||||
expect(result).toEqual([34, 65])
|
||||
});
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user