dt-sql-parser 4.0.0-ng.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -112
- package/dist/index.d.ts +14 -6
- package/dist/index.js +11 -4
- package/dist/lib/SQLParserBase.d.ts +8 -0
- package/dist/lib/SQLParserBase.js +14 -0
- package/dist/lib/{flinksql → flink}/FlinkSqlLexer.d.ts +2 -2
- package/dist/lib/{flinksql → flink}/FlinkSqlLexer.js +2 -1
- package/dist/lib/{flinksql → flink}/FlinkSqlParser.d.ts +5 -11
- package/dist/lib/{flinksql → flink}/FlinkSqlParser.js +2065 -2054
- package/dist/lib/{flinksql → flink}/FlinkSqlParserListener.d.ts +0 -13
- package/dist/lib/{flinksql → flink}/FlinkSqlParserListener.js +1 -1
- package/dist/lib/{flinksql → flink}/FlinkSqlParserVisitor.d.ts +0 -8
- package/dist/lib/{flinksql → flink}/FlinkSqlParserVisitor.js +2 -1
- package/dist/lib/hive/HiveSqlLexer.d.ts +258 -257
- package/dist/lib/hive/HiveSqlLexer.js +1794 -1786
- package/dist/lib/hive/HiveSqlParser.d.ts +1266 -3176
- package/dist/lib/hive/HiveSqlParser.js +23046 -33454
- package/dist/lib/hive/HiveSqlParserListener.d.ts +141 -2036
- package/dist/lib/hive/HiveSqlParserVisitor.d.ts +151 -1358
- package/dist/lib/hive/HiveSqlParserVisitor.js +1 -0
- package/dist/lib/impala/ImpalaSqlLexer.d.ts +170 -154
- package/dist/lib/impala/ImpalaSqlLexer.js +1179 -1099
- package/dist/lib/impala/ImpalaSqlParser.d.ts +282 -240
- package/dist/lib/impala/ImpalaSqlParser.js +3881 -3744
- package/dist/lib/impala/ImpalaSqlParserListener.d.ts +22 -11
- package/dist/lib/impala/ImpalaSqlParserVisitor.d.ts +14 -7
- package/dist/lib/impala/ImpalaSqlParserVisitor.js +1 -0
- package/dist/lib/index.d.ts +6 -6
- package/dist/lib/index.js +6 -6
- package/dist/lib/mysql/MySqlLexer.d.ts +2 -2
- package/dist/lib/mysql/MySqlLexer.js +1 -0
- package/dist/lib/mysql/MySqlParser.d.ts +347 -418
- package/dist/lib/mysql/MySqlParser.js +10484 -11099
- package/dist/lib/mysql/MySqlParserListener.d.ts +41 -126
- package/dist/lib/mysql/MySqlParserVisitor.d.ts +23 -76
- package/dist/lib/mysql/MySqlParserVisitor.js +1 -0
- package/dist/lib/plsql/PlSqlBaseLexer.d.ts +1 -2
- package/dist/lib/plsql/PlSqlBaseLexer.js +1 -1
- package/dist/lib/plsql/PlSqlBaseParser.d.ts +3 -2
- package/dist/lib/plsql/PlSqlBaseParser.js +2 -2
- package/dist/lib/plsql/PlSqlLexer.d.ts +3 -3
- package/dist/lib/plsql/PlSqlLexer.js +2 -1
- package/dist/lib/plsql/PlSqlParser.d.ts +3 -3
- package/dist/lib/plsql/PlSqlParser.js +2 -1
- package/dist/lib/plsql/PlSqlParserVisitor.js +1 -0
- package/dist/lib/{pgsql/PostgreSQLLexer.d.ts → postgresql/PostgreSqlLexer.d.ts} +3 -3
- package/dist/lib/{pgsql/PostgreSQLLexer.js → postgresql/PostgreSqlLexer.js} +618 -617
- package/dist/lib/{pgsql/PostgreSQLParser.d.ts → postgresql/PostgreSqlParser.d.ts} +3598 -3484
- package/dist/lib/{pgsql/PostgreSQLParser.js → postgresql/PostgreSqlParser.js} +41502 -42831
- package/dist/lib/{pgsql/PostgreSQLParserListener.d.ts → postgresql/PostgreSqlParserListener.d.ts} +2797 -2730
- package/dist/lib/{pgsql/PostgreSQLParserListener.js → postgresql/PostgreSqlParserListener.js} +3 -3
- package/dist/lib/{pgsql/PostgreSQLParserVisitor.d.ts → postgresql/PostgreSqlParserVisitor.d.ts} +1845 -1810
- package/dist/lib/{pgsql/PostgreSQLParserVisitor.js → postgresql/PostgreSqlParserVisitor.js} +4 -3
- package/dist/lib/spark/SparkSqlLexer.d.ts +305 -298
- package/dist/lib/spark/SparkSqlLexer.js +1777 -1735
- package/dist/lib/spark/SparkSqlParser.d.ts +1764 -669
- package/dist/lib/spark/SparkSqlParser.js +15460 -10769
- package/dist/lib/spark/SparkSqlParserListener.d.ts +1285 -35
- package/dist/lib/spark/SparkSqlParserVisitor.d.ts +790 -21
- package/dist/lib/spark/SparkSqlParserVisitor.js +1 -0
- package/dist/lib/{trinosql → trino}/TrinoSqlLexer.d.ts +2 -2
- package/dist/lib/{trinosql → trino}/TrinoSqlLexer.js +2 -1
- package/dist/lib/{trinosql → trino}/TrinoSqlListener.d.ts +7 -5
- package/dist/lib/{trinosql → trino}/TrinoSqlListener.js +1 -1
- package/dist/lib/{trinosql → trino}/TrinoSqlParser.d.ts +11 -5
- package/dist/lib/{trinosql → trino}/TrinoSqlParser.js +360 -320
- package/dist/lib/{trinosql → trino}/TrinoSqlVisitor.d.ts +4 -3
- package/dist/lib/{trinosql → trino}/TrinoSqlVisitor.js +2 -1
- package/dist/parser/common/{basicParser.d.ts → basicSQL.d.ts} +22 -19
- package/dist/parser/common/{basicParser.js → basicSQL.js} +52 -34
- package/dist/parser/common/entityCollector.d.ts +78 -0
- package/dist/parser/common/entityCollector.js +191 -0
- package/dist/parser/common/{utils/findCaretTokenIndex.d.ts → findCaretTokenIndex.d.ts} +2 -2
- package/dist/parser/common/{utils/findCaretTokenIndex.js → findCaretTokenIndex.js} +3 -2
- package/dist/parser/common/parseErrorListener.d.ts +6 -6
- package/dist/parser/common/parseErrorListener.js +1 -1
- package/dist/parser/common/simpleStack.d.ts +10 -0
- package/dist/parser/common/simpleStack.js +23 -0
- package/dist/parser/common/splitListener.d.ts +8 -0
- package/dist/parser/common/splitListener.js +12 -0
- package/dist/parser/common/textAndWord.d.ts +52 -0
- package/dist/parser/common/textAndWord.js +58 -0
- package/dist/parser/common/{basic-parser-types.d.ts → types.d.ts} +4 -31
- package/dist/parser/common/types.js +34 -0
- package/dist/parser/flink/flinkEntityCollector.d.ts +33 -0
- package/dist/parser/flink/flinkEntityCollector.js +84 -0
- package/dist/parser/flink/flinkSplitListener.d.ts +6 -0
- package/dist/parser/flink/flinkSplitListener.js +6 -0
- package/dist/parser/flink/index.d.ts +17 -0
- package/dist/parser/{flinksql.js → flink/index.js} +26 -37
- package/dist/parser/hive/hiveEntityCollector.d.ts +35 -0
- package/dist/parser/hive/hiveEntityCollector.js +90 -0
- package/dist/parser/hive/hiveSplitListener.d.ts +6 -0
- package/dist/parser/hive/hiveSplitListener.js +6 -0
- package/dist/parser/hive/index.d.ts +17 -0
- package/dist/parser/{hive.js → hive/index.js} +24 -34
- package/dist/parser/impala/impalaEntityCollector.d.ts +35 -0
- package/dist/parser/impala/impalaEntityCollector.js +90 -0
- package/dist/parser/impala/impalaSplitListener.d.ts +6 -0
- package/dist/parser/impala/impalaSplitListener.js +6 -0
- package/dist/parser/impala/index.d.ts +17 -0
- package/dist/parser/{impala.js → impala/index.js} +24 -34
- package/dist/parser/index.d.ts +8 -8
- package/dist/parser/index.js +8 -8
- package/dist/parser/mysql/index.d.ts +17 -0
- package/dist/parser/{mysql.js → mysql/index.js} +24 -34
- package/dist/parser/mysql/mysqlEntityCollector.d.ts +37 -0
- package/dist/parser/mysql/mysqlEntityCollector.js +96 -0
- package/dist/parser/mysql/mysqlSplitListener.d.ts +6 -0
- package/dist/parser/mysql/mysqlSplitListener.js +6 -0
- package/dist/parser/plsql.d.ts +7 -6
- package/dist/parser/plsql.js +6 -4
- package/dist/parser/postgresql/index.d.ts +17 -0
- package/dist/parser/postgresql/index.js +130 -0
- package/dist/parser/postgresql/postgreEntityCollector.d.ts +37 -0
- package/dist/parser/postgresql/postgreEntityCollector.js +96 -0
- package/dist/parser/postgresql/postgreSplitListener.d.ts +6 -0
- package/dist/parser/postgresql/postgreSplitListener.js +6 -0
- package/dist/parser/spark/index.d.ts +17 -0
- package/dist/parser/{spark.js → spark/index.js} +29 -40
- package/dist/parser/spark/sparkEntityCollector.d.ts +37 -0
- package/dist/parser/spark/sparkEntityCollector.js +96 -0
- package/dist/parser/spark/sparkSplitListener.d.ts +6 -0
- package/dist/parser/spark/sparkSplitListener.js +6 -0
- package/dist/parser/trino/index.d.ts +17 -0
- package/dist/parser/{trinosql.js → trino/index.js} +25 -36
- package/dist/parser/trino/trinoEntityCollector.d.ts +30 -0
- package/dist/parser/trino/trinoEntityCollector.js +75 -0
- package/dist/parser/trino/trinoSplitListener.d.ts +6 -0
- package/dist/parser/trino/trinoSplitListener.js +6 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/token.d.ts +1 -1
- package/package.json +3 -3
- package/dist/parser/common/basic-parser-types.js +0 -34
- package/dist/parser/flinksql.d.ts +0 -23
- package/dist/parser/hive.d.ts +0 -23
- package/dist/parser/impala.d.ts +0 -23
- package/dist/parser/mysql.d.ts +0 -23
- package/dist/parser/pgsql.d.ts +0 -23
- package/dist/parser/pgsql.js +0 -140
- package/dist/parser/spark.d.ts +0 -23
- package/dist/parser/trinosql.d.ts +0 -23
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { EntityContextType } from '../common/types';
|
|
2
|
+
import { StmtContextType, EntityCollector } from '../common/entityCollector';
|
|
3
|
+
export class SparkEntityCollector extends EntityCollector {
|
|
4
|
+
/** ====== Entity Begin */
|
|
5
|
+
exitNamespaceName(ctx) {
|
|
6
|
+
this.pushEntity(ctx, EntityContextType.DATABASE);
|
|
7
|
+
}
|
|
8
|
+
exitNamespaceNameCreate(ctx) {
|
|
9
|
+
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE);
|
|
10
|
+
}
|
|
11
|
+
exitTableName(ctx) {
|
|
12
|
+
this.pushEntity(ctx, EntityContextType.TABLE);
|
|
13
|
+
}
|
|
14
|
+
exitTableNameCreate(ctx) {
|
|
15
|
+
this.pushEntity(ctx, EntityContextType.TABLE_CREATE);
|
|
16
|
+
}
|
|
17
|
+
exitViewName(ctx) {
|
|
18
|
+
this.pushEntity(ctx, EntityContextType.VIEW);
|
|
19
|
+
}
|
|
20
|
+
exitViewNameCreate(ctx) {
|
|
21
|
+
this.pushEntity(ctx, EntityContextType.VIEW_CREATE);
|
|
22
|
+
}
|
|
23
|
+
exitFunctionNameCreate(ctx) {
|
|
24
|
+
this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE);
|
|
25
|
+
}
|
|
26
|
+
exitColumnNameCreate(ctx) {
|
|
27
|
+
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE);
|
|
28
|
+
}
|
|
29
|
+
/** ===== Statement begin */
|
|
30
|
+
enterSingleStatement(ctx) {
|
|
31
|
+
this.pushStmt(ctx, StmtContextType.COMMON_STMT);
|
|
32
|
+
}
|
|
33
|
+
exitSingleStatement(ctx) {
|
|
34
|
+
this.popStmt();
|
|
35
|
+
}
|
|
36
|
+
enterCreateTable(ctx) {
|
|
37
|
+
this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT);
|
|
38
|
+
}
|
|
39
|
+
exitCreateTable(ctx) {
|
|
40
|
+
this.popStmt();
|
|
41
|
+
}
|
|
42
|
+
enterCreateTableLike(ctx) {
|
|
43
|
+
this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT);
|
|
44
|
+
}
|
|
45
|
+
exitCreateTableLike(ctx) {
|
|
46
|
+
this.popStmt();
|
|
47
|
+
}
|
|
48
|
+
enterReplaceTable(ctx) {
|
|
49
|
+
this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT);
|
|
50
|
+
}
|
|
51
|
+
exitReplaceTable(ctx) {
|
|
52
|
+
this.popStmt();
|
|
53
|
+
}
|
|
54
|
+
enterCreateView(ctx) {
|
|
55
|
+
this.pushStmt(ctx, StmtContextType.CREATE_VIEW_STMT);
|
|
56
|
+
}
|
|
57
|
+
exitCreateView(ctx) {
|
|
58
|
+
this.popStmt();
|
|
59
|
+
}
|
|
60
|
+
enterCreateTempViewUsing(ctx) {
|
|
61
|
+
this.pushStmt(ctx, StmtContextType.CREATE_VIEW_STMT);
|
|
62
|
+
}
|
|
63
|
+
exitCreateTempViewUsing(ctx) {
|
|
64
|
+
this.popStmt();
|
|
65
|
+
}
|
|
66
|
+
enterQueryStatement(ctx) {
|
|
67
|
+
this.pushStmt(ctx, StmtContextType.SELECT_STMT);
|
|
68
|
+
}
|
|
69
|
+
exitQueryStatement(ctx) {
|
|
70
|
+
this.popStmt();
|
|
71
|
+
}
|
|
72
|
+
enterInsertFromQuery(ctx) {
|
|
73
|
+
this.pushStmt(ctx, StmtContextType.INSERT_STMT);
|
|
74
|
+
}
|
|
75
|
+
exitInsertFromQuery(ctx) {
|
|
76
|
+
this.popStmt();
|
|
77
|
+
}
|
|
78
|
+
enterMultipleInsert(ctx) {
|
|
79
|
+
this.pushStmt(ctx, StmtContextType.INSERT_STMT);
|
|
80
|
+
}
|
|
81
|
+
exitMultipleInsert(ctx) {
|
|
82
|
+
this.popStmt();
|
|
83
|
+
}
|
|
84
|
+
enterCreateNamespace(ctx) {
|
|
85
|
+
this.pushStmt(ctx, StmtContextType.CREATE_DATABASE_STMT);
|
|
86
|
+
}
|
|
87
|
+
exitCreateNamespace(ctx) {
|
|
88
|
+
this.popStmt();
|
|
89
|
+
}
|
|
90
|
+
enterCreateFunction(ctx) {
|
|
91
|
+
this.pushStmt(ctx, StmtContextType.CREATE_FUNCTION_STMT);
|
|
92
|
+
}
|
|
93
|
+
exitCreateFunction(ctx) {
|
|
94
|
+
this.popStmt();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SingleStatementContext } from '../../lib/spark/SparkSqlParser';
|
|
2
|
+
import { SparkSqlParserListener } from '../../lib/spark/SparkSqlParserListener';
|
|
3
|
+
import { SplitListener } from '../common/splitListener';
|
|
4
|
+
export declare class SparkSqlSplitListener extends SplitListener<SingleStatementContext> implements SparkSqlParserListener {
|
|
5
|
+
exitSingleStatement(ctx: SingleStatementContext): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CharStream, CommonTokenStream, Token } from 'antlr4ng';
|
|
2
|
+
import { CandidatesCollection } from 'antlr4-c3';
|
|
3
|
+
import { TrinoSqlLexer } from '../../lib/trino/TrinoSqlLexer';
|
|
4
|
+
import { TrinoSqlParser, ProgramContext } from '../../lib/trino/TrinoSqlParser';
|
|
5
|
+
import { BasicSQL } from '../common/basicSQL';
|
|
6
|
+
import { Suggestions } from '../common/types';
|
|
7
|
+
import { TrinoSqlSplitListener } from './trinoSplitListener';
|
|
8
|
+
import { TrinoEntityCollector } from './trinoEntityCollector';
|
|
9
|
+
export { TrinoSqlSplitListener, TrinoEntityCollector };
|
|
10
|
+
export declare class TrinoSQL extends BasicSQL<TrinoSqlLexer, ProgramContext, TrinoSqlParser> {
|
|
11
|
+
protected createLexerFromCharStream(charStreams: CharStream): TrinoSqlLexer;
|
|
12
|
+
protected createParserFromTokenStream(tokenStream: CommonTokenStream): TrinoSqlParser;
|
|
13
|
+
protected get splitListener(): TrinoSqlSplitListener;
|
|
14
|
+
protected createEntityCollector(input: string, caretTokenIndex?: number): TrinoEntityCollector;
|
|
15
|
+
protected preferredRules: Set<number>;
|
|
16
|
+
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
17
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { TrinoSqlLexer } from '
|
|
2
|
-
import { TrinoSqlParser
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { TrinoSqlLexer } from '../../lib/trino/TrinoSqlLexer';
|
|
2
|
+
import { TrinoSqlParser } from '../../lib/trino/TrinoSqlParser';
|
|
3
|
+
import { BasicSQL } from '../common/basicSQL';
|
|
4
|
+
import { EntityContextType } from '../common/types';
|
|
5
|
+
import { TrinoSqlSplitListener } from './trinoSplitListener';
|
|
6
|
+
import { TrinoEntityCollector } from './trinoEntityCollector';
|
|
7
|
+
export { TrinoSqlSplitListener, TrinoEntityCollector };
|
|
8
|
+
export class TrinoSQL extends BasicSQL {
|
|
6
9
|
constructor() {
|
|
7
10
|
super(...arguments);
|
|
8
11
|
this.preferredRules = new Set([
|
|
@@ -20,16 +23,17 @@ export default class TrinoSQL extends BasicParser {
|
|
|
20
23
|
]);
|
|
21
24
|
}
|
|
22
25
|
createLexerFromCharStream(charStreams) {
|
|
23
|
-
|
|
24
|
-
return lexer;
|
|
26
|
+
return new TrinoSqlLexer(charStreams);
|
|
25
27
|
}
|
|
26
28
|
createParserFromTokenStream(tokenStream) {
|
|
27
|
-
|
|
28
|
-
return parser;
|
|
29
|
+
return new TrinoSqlParser(tokenStream);
|
|
29
30
|
}
|
|
30
31
|
get splitListener() {
|
|
31
32
|
return new TrinoSqlSplitListener();
|
|
32
33
|
}
|
|
34
|
+
createEntityCollector(input, caretTokenIndex) {
|
|
35
|
+
return new TrinoEntityCollector(input, caretTokenIndex);
|
|
36
|
+
}
|
|
33
37
|
processCandidates(candidates, allTokens, caretTokenIndex, tokenIndexOffset) {
|
|
34
38
|
const originalSyntaxSuggestions = [];
|
|
35
39
|
const keywords = [];
|
|
@@ -37,46 +41,46 @@ export default class TrinoSQL extends BasicParser {
|
|
|
37
41
|
const [ruleType, candidateRule] = candidate;
|
|
38
42
|
const startTokenIndex = candidateRule.startTokenIndex + tokenIndexOffset;
|
|
39
43
|
const tokenRanges = allTokens.slice(startTokenIndex, caretTokenIndex + tokenIndexOffset + 1);
|
|
40
|
-
let syntaxContextType;
|
|
44
|
+
let syntaxContextType = void 0;
|
|
41
45
|
switch (ruleType) {
|
|
42
46
|
case TrinoSqlParser.RULE_catalogName: {
|
|
43
|
-
syntaxContextType =
|
|
47
|
+
syntaxContextType = EntityContextType.CATALOG;
|
|
44
48
|
break;
|
|
45
49
|
}
|
|
46
50
|
case TrinoSqlParser.RULE_schemaName: {
|
|
47
|
-
syntaxContextType =
|
|
51
|
+
syntaxContextType = EntityContextType.DATABASE;
|
|
48
52
|
break;
|
|
49
53
|
}
|
|
50
54
|
case TrinoSqlParser.RULE_schemaNameCreate: {
|
|
51
|
-
syntaxContextType =
|
|
55
|
+
syntaxContextType = EntityContextType.DATABASE_CREATE;
|
|
52
56
|
break;
|
|
53
57
|
}
|
|
54
58
|
case TrinoSqlParser.RULE_tableName: {
|
|
55
|
-
syntaxContextType =
|
|
59
|
+
syntaxContextType = EntityContextType.TABLE;
|
|
56
60
|
break;
|
|
57
61
|
}
|
|
58
62
|
case TrinoSqlParser.RULE_tableNameCreate: {
|
|
59
|
-
syntaxContextType =
|
|
63
|
+
syntaxContextType = EntityContextType.TABLE_CREATE;
|
|
60
64
|
break;
|
|
61
65
|
}
|
|
62
66
|
case TrinoSqlParser.RULE_viewName: {
|
|
63
|
-
syntaxContextType =
|
|
67
|
+
syntaxContextType = EntityContextType.VIEW;
|
|
64
68
|
break;
|
|
65
69
|
}
|
|
66
70
|
case TrinoSqlParser.RULE_viewNameCreate: {
|
|
67
|
-
syntaxContextType =
|
|
71
|
+
syntaxContextType = EntityContextType.VIEW_CREATE;
|
|
68
72
|
break;
|
|
69
73
|
}
|
|
70
74
|
case TrinoSqlParser.RULE_functionName: {
|
|
71
|
-
syntaxContextType =
|
|
75
|
+
syntaxContextType = EntityContextType.FUNCTION;
|
|
72
76
|
break;
|
|
73
77
|
}
|
|
74
78
|
case TrinoSqlParser.RULE_columnNameCreate: {
|
|
75
|
-
syntaxContextType =
|
|
79
|
+
syntaxContextType = EntityContextType.COLUMN_CREATE;
|
|
76
80
|
break;
|
|
77
81
|
}
|
|
78
82
|
case TrinoSqlParser.RULE_columnName: {
|
|
79
|
-
syntaxContextType =
|
|
83
|
+
syntaxContextType = EntityContextType.COLUMN;
|
|
80
84
|
break;
|
|
81
85
|
}
|
|
82
86
|
default:
|
|
@@ -92,7 +96,7 @@ export default class TrinoSQL extends BasicParser {
|
|
|
92
96
|
for (let candidate of candidates.tokens) {
|
|
93
97
|
const symbolicName = this._parser.vocabulary.getSymbolicName(candidate[0]);
|
|
94
98
|
const displayName = this._parser.vocabulary.getDisplayName(candidate[0]);
|
|
95
|
-
if (symbolicName && symbolicName.startsWith('KW_')) {
|
|
99
|
+
if (displayName && symbolicName && symbolicName.startsWith('KW_')) {
|
|
96
100
|
const keyword = displayName.startsWith("'") && displayName.endsWith("'")
|
|
97
101
|
? displayName.slice(1, -1)
|
|
98
102
|
: displayName;
|
|
@@ -105,18 +109,3 @@ export default class TrinoSQL extends BasicParser {
|
|
|
105
109
|
};
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
|
-
export class TrinoSqlSplitListener {
|
|
109
|
-
constructor() {
|
|
110
|
-
this._statementsContext = [];
|
|
111
|
-
this.exitSingleStatement = (ctx) => {
|
|
112
|
-
this._statementsContext.push(ctx);
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
visitTerminal() { }
|
|
116
|
-
visitErrorNode() { }
|
|
117
|
-
enterEveryRule() { }
|
|
118
|
-
exitEveryRule() { }
|
|
119
|
-
get statementsContext() {
|
|
120
|
-
return this._statementsContext;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ColumnNameCreateContext, CreateMaterializedViewContext, CreateSchemaContext, CreateTableAsSelectContext, CreateTableContext, CreateViewContext, InsertIntoContext, QueryStatementContext, SchemaNameContext, SchemaNameCreateContext, SingleStatementContext, TableNameContext, TableNameCreateContext, ViewNameContext, ViewNameCreateContext } from '../../lib/trino/TrinoSqlParser';
|
|
2
|
+
import type { TrinoSqlListener } from '../../lib/trino/TrinoSqlListener';
|
|
3
|
+
import { EntityCollector } from '../common/entityCollector';
|
|
4
|
+
export declare class TrinoEntityCollector extends EntityCollector implements TrinoSqlListener {
|
|
5
|
+
/** ====== Entity Begin */
|
|
6
|
+
exitSchemaName(ctx: SchemaNameContext): void;
|
|
7
|
+
exitSchemaNameCreate(ctx: SchemaNameCreateContext): void;
|
|
8
|
+
exitTableName(ctx: TableNameContext): void;
|
|
9
|
+
exitTableNameCreate(ctx: TableNameCreateContext): void;
|
|
10
|
+
exitViewName(ctx: ViewNameContext): void;
|
|
11
|
+
exitViewNameCreate(ctx: ViewNameCreateContext): void;
|
|
12
|
+
exitColumnNameCreate(ctx: ColumnNameCreateContext): void;
|
|
13
|
+
/** ===== Statement begin */
|
|
14
|
+
enterSingleStatement(ctx: SingleStatementContext): void;
|
|
15
|
+
exitSingleStatement(ctx: SingleStatementContext): void;
|
|
16
|
+
enterCreateSchema(ctx: CreateSchemaContext): void;
|
|
17
|
+
exitCreateSchema(ctx: CreateSchemaContext): void;
|
|
18
|
+
enterCreateTableAsSelect(ctx: CreateTableAsSelectContext): void;
|
|
19
|
+
exitCreateTableAsSelect(ctx: CreateTableAsSelectContext): void;
|
|
20
|
+
enterCreateTable(ctx: CreateTableContext): void;
|
|
21
|
+
exitCreateTable(ctx: CreateTableContext): void;
|
|
22
|
+
enterCreateView(ctx: CreateViewContext): void;
|
|
23
|
+
exitCreateView(ctx: CreateViewContext): void;
|
|
24
|
+
enterCreateMaterializedView(ctx: CreateMaterializedViewContext): void;
|
|
25
|
+
exitCreateMaterializedView(ctx: CreateMaterializedViewContext): void;
|
|
26
|
+
enterQueryStatement(ctx: QueryStatementContext): void;
|
|
27
|
+
exitQueryStatement(ctx: QueryStatementContext): void;
|
|
28
|
+
enterInsertInto(ctx: InsertIntoContext): void;
|
|
29
|
+
exitInsertInto(ctx: InsertIntoContext): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { EntityContextType } from '../common/types';
|
|
2
|
+
import { StmtContextType, EntityCollector } from '../common/entityCollector';
|
|
3
|
+
export class TrinoEntityCollector extends EntityCollector {
|
|
4
|
+
/** ====== Entity Begin */
|
|
5
|
+
exitSchemaName(ctx) {
|
|
6
|
+
this.pushEntity(ctx, EntityContextType.DATABASE);
|
|
7
|
+
}
|
|
8
|
+
exitSchemaNameCreate(ctx) {
|
|
9
|
+
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE);
|
|
10
|
+
}
|
|
11
|
+
exitTableName(ctx) {
|
|
12
|
+
this.pushEntity(ctx, EntityContextType.TABLE);
|
|
13
|
+
}
|
|
14
|
+
exitTableNameCreate(ctx) {
|
|
15
|
+
this.pushEntity(ctx, EntityContextType.TABLE_CREATE);
|
|
16
|
+
}
|
|
17
|
+
exitViewName(ctx) {
|
|
18
|
+
this.pushEntity(ctx, EntityContextType.VIEW);
|
|
19
|
+
}
|
|
20
|
+
exitViewNameCreate(ctx) {
|
|
21
|
+
this.pushEntity(ctx, EntityContextType.VIEW_CREATE);
|
|
22
|
+
}
|
|
23
|
+
exitColumnNameCreate(ctx) {
|
|
24
|
+
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE);
|
|
25
|
+
}
|
|
26
|
+
/** ===== Statement begin */
|
|
27
|
+
enterSingleStatement(ctx) {
|
|
28
|
+
this.pushStmt(ctx, StmtContextType.COMMON_STMT);
|
|
29
|
+
}
|
|
30
|
+
exitSingleStatement(ctx) {
|
|
31
|
+
this.popStmt();
|
|
32
|
+
}
|
|
33
|
+
enterCreateSchema(ctx) {
|
|
34
|
+
this.pushStmt(ctx, StmtContextType.CREATE_DATABASE_STMT);
|
|
35
|
+
}
|
|
36
|
+
exitCreateSchema(ctx) {
|
|
37
|
+
this.popStmt();
|
|
38
|
+
}
|
|
39
|
+
enterCreateTableAsSelect(ctx) {
|
|
40
|
+
this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT);
|
|
41
|
+
}
|
|
42
|
+
exitCreateTableAsSelect(ctx) {
|
|
43
|
+
this.popStmt();
|
|
44
|
+
}
|
|
45
|
+
enterCreateTable(ctx) {
|
|
46
|
+
this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT);
|
|
47
|
+
}
|
|
48
|
+
exitCreateTable(ctx) {
|
|
49
|
+
this.popStmt();
|
|
50
|
+
}
|
|
51
|
+
enterCreateView(ctx) {
|
|
52
|
+
this.pushStmt(ctx, StmtContextType.CREATE_VIEW_STMT);
|
|
53
|
+
}
|
|
54
|
+
exitCreateView(ctx) {
|
|
55
|
+
this.popStmt();
|
|
56
|
+
}
|
|
57
|
+
enterCreateMaterializedView(ctx) {
|
|
58
|
+
this.pushStmt(ctx, StmtContextType.CREATE_VIEW_STMT);
|
|
59
|
+
}
|
|
60
|
+
exitCreateMaterializedView(ctx) {
|
|
61
|
+
this.popStmt();
|
|
62
|
+
}
|
|
63
|
+
enterQueryStatement(ctx) {
|
|
64
|
+
this.pushStmt(ctx, StmtContextType.SELECT_STMT);
|
|
65
|
+
}
|
|
66
|
+
exitQueryStatement(ctx) {
|
|
67
|
+
this.popStmt();
|
|
68
|
+
}
|
|
69
|
+
enterInsertInto(ctx) {
|
|
70
|
+
this.pushStmt(ctx, StmtContextType.INSERT_STMT);
|
|
71
|
+
}
|
|
72
|
+
exitInsertInto(ctx) {
|
|
73
|
+
this.popStmt();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SingleStatementContext } from '../../lib/trino/TrinoSqlParser';
|
|
2
|
+
import { TrinoSqlListener } from '../../lib/trino/TrinoSqlListener';
|
|
3
|
+
import { SplitListener } from '../common/splitListener';
|
|
4
|
+
export declare class TrinoSqlSplitListener extends SplitListener<SingleStatementContext> implements TrinoSqlListener {
|
|
5
|
+
exitSingleStatement(ctx: SingleStatementContext): void;
|
|
6
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ declare function legacy_lexer(input: string): Legacy_Token[];
|
|
|
9
9
|
* @param {String} sql
|
|
10
10
|
* @deprecated use parser.splitSQLByStatement() instead.
|
|
11
11
|
*/
|
|
12
|
-
declare function legacy_splitSql(sql: string):
|
|
12
|
+
declare function legacy_splitSql(sql: string): string[];
|
|
13
13
|
/**
|
|
14
14
|
* clean comment
|
|
15
15
|
* @param {String} sql
|
package/dist/utils/token.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dt-sql-parser",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"authors": "DTStack Corporation",
|
|
5
5
|
"description": "SQL Parsers for BigData, built with antlr4",
|
|
6
6
|
"keywords": [
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"registry": "https://registry.npmjs.org/"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"antlr4-c3": "3.3.
|
|
64
|
-
"antlr4ng": "2.0.
|
|
63
|
+
"antlr4-c3": "3.3.7",
|
|
64
|
+
"antlr4ng": "2.0.11"
|
|
65
65
|
},
|
|
66
66
|
"sideEffects": false
|
|
67
67
|
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Syntax context type at caret position
|
|
3
|
-
*/
|
|
4
|
-
export var SyntaxContextType;
|
|
5
|
-
(function (SyntaxContextType) {
|
|
6
|
-
/** catalog name */
|
|
7
|
-
SyntaxContextType["CATALOG"] = "catalog";
|
|
8
|
-
/** catalog name that will be created */
|
|
9
|
-
SyntaxContextType["CATALOG_CREATE"] = "catalogCreate";
|
|
10
|
-
/** database name path, such as catalog.db */
|
|
11
|
-
SyntaxContextType["DATABASE"] = "database";
|
|
12
|
-
/** database name path that will be created */
|
|
13
|
-
SyntaxContextType["DATABASE_CREATE"] = "databaseCreate";
|
|
14
|
-
/** table name path, such as catalog.db.tb */
|
|
15
|
-
SyntaxContextType["TABLE"] = "table";
|
|
16
|
-
/** table name path that will be created */
|
|
17
|
-
SyntaxContextType["TABLE_CREATE"] = "tableCreate";
|
|
18
|
-
/** view name path, such as db.tb.view */
|
|
19
|
-
SyntaxContextType["VIEW"] = "view";
|
|
20
|
-
/** view name path that will be created */
|
|
21
|
-
SyntaxContextType["VIEW_CREATE"] = "viewCreate";
|
|
22
|
-
/** function name */
|
|
23
|
-
SyntaxContextType["FUNCTION"] = "function";
|
|
24
|
-
/** function name that will be created */
|
|
25
|
-
SyntaxContextType["FUNCTION_CREATE"] = "functionCreate";
|
|
26
|
-
/** procedure name */
|
|
27
|
-
SyntaxContextType["PROCEDURE"] = "procedure";
|
|
28
|
-
/** procedure name that will be created */
|
|
29
|
-
SyntaxContextType["PROCEDURE_CREATE"] = "procedureCreate";
|
|
30
|
-
/** column name */
|
|
31
|
-
SyntaxContextType["COLUMN"] = "column";
|
|
32
|
-
/** column name that will be created */
|
|
33
|
-
SyntaxContextType["COLUMN_CREATE"] = "columnCreate";
|
|
34
|
-
})(SyntaxContextType || (SyntaxContextType = {}));
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Token } from 'antlr4ng';
|
|
2
|
-
import { CandidatesCollection } from 'antlr4-c3';
|
|
3
|
-
import { FlinkSqlLexer } from '../lib/flinksql/FlinkSqlLexer';
|
|
4
|
-
import { FlinkSqlParser, ProgramContext, SingleStatementContext } from '../lib/flinksql/FlinkSqlParser';
|
|
5
|
-
import { FlinkSqlParserListener } from '../lib/flinksql/FlinkSqlParserListener';
|
|
6
|
-
import { Suggestions } from './common/basic-parser-types';
|
|
7
|
-
import BasicParser from './common/basicParser';
|
|
8
|
-
export default class FlinkSQL extends BasicParser<FlinkSqlLexer, ProgramContext, FlinkSqlParser> {
|
|
9
|
-
protected createLexerFromCharStream(charStreams: any): FlinkSqlLexer;
|
|
10
|
-
protected createParserFromTokenStream(tokenStream: any): FlinkSqlParser;
|
|
11
|
-
protected preferredRules: Set<number>;
|
|
12
|
-
protected get splitListener(): FlinkSqlSplitListener;
|
|
13
|
-
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
14
|
-
}
|
|
15
|
-
export declare class FlinkSqlSplitListener implements FlinkSqlParserListener {
|
|
16
|
-
private _statementsContext;
|
|
17
|
-
exitSingleStatement: (ctx: SingleStatementContext) => void;
|
|
18
|
-
visitTerminal(): void;
|
|
19
|
-
visitErrorNode(): void;
|
|
20
|
-
enterEveryRule(): void;
|
|
21
|
-
exitEveryRule(): void;
|
|
22
|
-
get statementsContext(): SingleStatementContext[];
|
|
23
|
-
}
|
package/dist/parser/hive.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Token } from 'antlr4ng';
|
|
2
|
-
import { CandidatesCollection } from 'antlr4-c3';
|
|
3
|
-
import { HiveSqlLexer } from '../lib/hive/HiveSqlLexer';
|
|
4
|
-
import { HiveSqlParser, ProgramContext, StatementContext } from '../lib/hive/HiveSqlParser';
|
|
5
|
-
import BasicParser from './common/basicParser';
|
|
6
|
-
import { HiveSqlParserListener } from '../lib/hive/HiveSqlParserListener';
|
|
7
|
-
import { Suggestions } from './common/basic-parser-types';
|
|
8
|
-
export default class HiveSQL extends BasicParser<HiveSqlLexer, ProgramContext, HiveSqlParser> {
|
|
9
|
-
protected createLexerFromCharStream(charStreams: any): HiveSqlLexer;
|
|
10
|
-
protected createParserFromTokenStream(tokenStream: any): HiveSqlParser;
|
|
11
|
-
protected preferredRules: Set<number>;
|
|
12
|
-
protected get splitListener(): HiveSqlSplitListener;
|
|
13
|
-
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
14
|
-
}
|
|
15
|
-
export declare class HiveSqlSplitListener implements HiveSqlParserListener {
|
|
16
|
-
private _statementContext;
|
|
17
|
-
exitStatement: (ctx: StatementContext) => void;
|
|
18
|
-
visitTerminal(): void;
|
|
19
|
-
visitErrorNode(): void;
|
|
20
|
-
enterEveryRule(): void;
|
|
21
|
-
exitEveryRule(): void;
|
|
22
|
-
get statementsContext(): StatementContext[];
|
|
23
|
-
}
|
package/dist/parser/impala.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Token } from 'antlr4ng';
|
|
2
|
-
import { CandidatesCollection } from 'antlr4-c3';
|
|
3
|
-
import { ImpalaSqlLexer } from '../lib/impala/ImpalaSqlLexer';
|
|
4
|
-
import { ImpalaSqlParser, ProgramContext, SingleStatementContext } from '../lib/impala/ImpalaSqlParser';
|
|
5
|
-
import BasicParser from './common/basicParser';
|
|
6
|
-
import { ImpalaSqlParserListener } from '../lib/impala/ImpalaSqlParserListener';
|
|
7
|
-
import { Suggestions } from './common/basic-parser-types';
|
|
8
|
-
export default class ImpalaSQL extends BasicParser<ImpalaSqlLexer, ProgramContext, ImpalaSqlParser> {
|
|
9
|
-
protected createLexerFromCharStream(charStreams: any): ImpalaSqlLexer;
|
|
10
|
-
protected createParserFromTokenStream(tokenStream: any): ImpalaSqlParser;
|
|
11
|
-
protected preferredRules: Set<number>;
|
|
12
|
-
protected get splitListener(): ImpalaSqlSplitListener;
|
|
13
|
-
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
14
|
-
}
|
|
15
|
-
export declare class ImpalaSqlSplitListener implements ImpalaSqlParserListener {
|
|
16
|
-
private _statementContext;
|
|
17
|
-
exitSingleStatement: (ctx: SingleStatementContext) => void;
|
|
18
|
-
visitTerminal(): void;
|
|
19
|
-
visitErrorNode(): void;
|
|
20
|
-
enterEveryRule(): void;
|
|
21
|
-
exitEveryRule(): void;
|
|
22
|
-
get statementsContext(): SingleStatementContext[];
|
|
23
|
-
}
|
package/dist/parser/mysql.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Token } from 'antlr4ng';
|
|
2
|
-
import { CandidatesCollection } from 'antlr4-c3';
|
|
3
|
-
import { MySqlLexer } from '../lib/mysql/MySqlLexer';
|
|
4
|
-
import { MySqlParser, ProgramContext, SingleStatementContext } from '../lib/mysql/MySqlParser';
|
|
5
|
-
import BasicParser from './common/basicParser';
|
|
6
|
-
import { Suggestions } from './common/basic-parser-types';
|
|
7
|
-
import { MySqlParserListener } from '../lib/mysql/MySqlParserListener';
|
|
8
|
-
export default class MySQL extends BasicParser<MySqlLexer, ProgramContext, MySqlParser> {
|
|
9
|
-
protected createLexerFromCharStream(charStreams: any): MySqlLexer;
|
|
10
|
-
protected createParserFromTokenStream(tokenStream: any): MySqlParser;
|
|
11
|
-
protected preferredRules: Set<number>;
|
|
12
|
-
protected get splitListener(): MysqlSplitListener;
|
|
13
|
-
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
14
|
-
}
|
|
15
|
-
export declare class MysqlSplitListener implements MySqlParserListener {
|
|
16
|
-
private _statementsContext;
|
|
17
|
-
exitSingleStatement: (ctx: SingleStatementContext) => void;
|
|
18
|
-
visitTerminal(): void;
|
|
19
|
-
visitErrorNode(): void;
|
|
20
|
-
enterEveryRule(): void;
|
|
21
|
-
exitEveryRule(): void;
|
|
22
|
-
get statementsContext(): SingleStatementContext[];
|
|
23
|
-
}
|
package/dist/parser/pgsql.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Token } from 'antlr4ng';
|
|
2
|
-
import { CandidatesCollection } from 'antlr4-c3';
|
|
3
|
-
import { PostgreSQLLexer } from '../lib/pgsql/PostgreSQLLexer';
|
|
4
|
-
import { PostgreSQLParser, ProgramContext, SingleStmtContext } from '../lib/pgsql/PostgreSQLParser';
|
|
5
|
-
import BasicParser from './common/basicParser';
|
|
6
|
-
import { PostgreSQLParserListener } from '../lib/pgsql/PostgreSQLParserListener';
|
|
7
|
-
import { Suggestions } from './common/basic-parser-types';
|
|
8
|
-
export default class PostgresSQL extends BasicParser<PostgreSQLLexer, ProgramContext, PostgreSQLParser> {
|
|
9
|
-
protected createLexerFromCharStream(charStreams: any): PostgreSQLLexer;
|
|
10
|
-
protected createParserFromTokenStream(tokenStream: any): PostgreSQLParser;
|
|
11
|
-
protected preferredRules: Set<number>;
|
|
12
|
-
protected get splitListener(): PgSqlSplitListener;
|
|
13
|
-
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
14
|
-
}
|
|
15
|
-
export declare class PgSqlSplitListener implements PostgreSQLParserListener {
|
|
16
|
-
private _statementsContext;
|
|
17
|
-
exitSingleStmt: (ctx: SingleStmtContext) => void;
|
|
18
|
-
visitTerminal(): void;
|
|
19
|
-
visitErrorNode(): void;
|
|
20
|
-
enterEveryRule(): void;
|
|
21
|
-
exitEveryRule(): void;
|
|
22
|
-
get statementsContext(): SingleStmtContext[];
|
|
23
|
-
}
|