dt-sql-parser 4.1.2-beta.0 → 4.2.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 +51 -0
- package/dist/lib/flink/FlinkSqlLexer.d.ts +5 -5
- package/dist/lib/flink/FlinkSqlLexer.js +1991 -1992
- package/dist/lib/flink/FlinkSqlParser.d.ts +240 -230
- package/dist/lib/flink/FlinkSqlParser.js +3036 -2978
- package/dist/lib/flink/FlinkSqlParserListener.d.ts +81 -70
- package/dist/lib/flink/FlinkSqlParserVisitor.d.ts +49 -42
- package/dist/lib/hive/HiveSqlParser.d.ts +251 -231
- package/dist/lib/hive/HiveSqlParser.js +6264 -5674
- package/dist/lib/hive/HiveSqlParserListener.d.ts +32 -10
- package/dist/lib/hive/HiveSqlParserVisitor.d.ts +20 -6
- package/dist/lib/impala/ImpalaSqlLexer.d.ts +2 -2
- package/dist/lib/impala/ImpalaSqlLexer.js +587 -588
- package/dist/lib/impala/ImpalaSqlParser.d.ts +151 -113
- package/dist/lib/impala/ImpalaSqlParser.js +3464 -3250
- package/dist/lib/impala/ImpalaSqlParserListener.d.ts +49 -5
- package/dist/lib/impala/ImpalaSqlParserVisitor.d.ts +31 -3
- package/dist/lib/mysql/MySqlLexer.d.ts +2 -2
- package/dist/lib/mysql/MySqlLexer.js +3515 -3516
- package/dist/lib/mysql/MySqlParser.d.ts +138 -138
- package/dist/lib/mysql/MySqlParser.js +511 -511
- package/dist/lib/mysql/MySqlParserListener.d.ts +105 -105
- package/dist/lib/mysql/MySqlParserVisitor.d.ts +63 -63
- package/dist/lib/postgresql/PostgreSqlLexer.d.ts +14 -15
- package/dist/lib/postgresql/PostgreSqlLexer.js +2077 -2092
- package/dist/lib/postgresql/PostgreSqlParser.d.ts +2860 -2980
- package/dist/lib/postgresql/PostgreSqlParser.js +20155 -20660
- package/dist/lib/postgresql/PostgreSqlParserListener.d.ts +2110 -2181
- package/dist/lib/postgresql/PostgreSqlParserVisitor.d.ts +1261 -1301
- package/dist/lib/spark/SparkSqlLexer.d.ts +2 -2
- package/dist/lib/spark/SparkSqlLexer.js +949 -950
- package/dist/lib/spark/SparkSqlParser.d.ts +413 -645
- package/dist/lib/spark/SparkSqlParser.js +6840 -8200
- package/dist/lib/spark/SparkSqlParserListener.d.ts +68 -356
- package/dist/lib/spark/SparkSqlParserVisitor.d.ts +42 -225
- package/dist/lib/trino/TrinoSqlLexer.d.ts +2 -2
- package/dist/lib/trino/TrinoSqlLexer.js +319 -321
- package/dist/lib/trino/TrinoSqlListener.d.ts +67 -23
- package/dist/lib/trino/TrinoSqlParser.d.ts +210 -181
- package/dist/lib/trino/TrinoSqlParser.js +4854 -4695
- package/dist/lib/trino/TrinoSqlVisitor.d.ts +42 -14
- package/dist/parser/common/basicSQL.d.ts +43 -9
- package/dist/parser/common/basicSQL.js +147 -40
- package/dist/parser/common/semanticContextCollector.d.ts +50 -0
- package/dist/parser/common/semanticContextCollector.js +202 -0
- package/dist/parser/common/tokenUtils.d.ts +12 -0
- package/dist/parser/common/tokenUtils.js +38 -0
- package/dist/parser/common/types.d.ts +25 -0
- package/dist/parser/common/types.js +7 -0
- package/dist/parser/flink/flinkErrorListener.js +14 -2
- package/dist/parser/flink/flinkSemanticContextCollector.d.ts +9 -0
- package/dist/parser/flink/flinkSemanticContextCollector.js +14 -0
- package/dist/parser/flink/index.d.ts +4 -2
- package/dist/parser/flink/index.js +22 -14
- package/dist/parser/hive/hiveErrorListener.js +9 -3
- package/dist/parser/hive/hiveSemanticContextCollector.d.ts +9 -0
- package/dist/parser/hive/hiveSemanticContextCollector.js +14 -0
- package/dist/parser/hive/index.d.ts +4 -2
- package/dist/parser/hive/index.js +29 -14
- package/dist/parser/impala/ImpalaErrorListener.js +8 -2
- package/dist/parser/impala/impalaSemanticContextCollector.d.ts +9 -0
- package/dist/parser/impala/impalaSemanticContextCollector.js +14 -0
- package/dist/parser/impala/index.d.ts +4 -2
- package/dist/parser/impala/index.js +21 -14
- package/dist/parser/mysql/index.d.ts +4 -2
- package/dist/parser/mysql/index.js +10 -14
- package/dist/parser/mysql/mysqlErrorListener.js +6 -2
- package/dist/parser/mysql/mysqlSemanticContextCollector.d.ts +9 -0
- package/dist/parser/mysql/mysqlSemanticContextCollector.js +14 -0
- package/dist/parser/postgresql/index.d.ts +4 -2
- package/dist/parser/postgresql/index.js +51 -42
- package/dist/parser/postgresql/postgreEntityCollector.d.ts +5 -5
- package/dist/parser/postgresql/postgreEntityCollector.js +7 -7
- package/dist/parser/postgresql/postgreErrorListener.js +36 -30
- package/dist/parser/postgresql/postgreSemanticContextCollector.d.ts +9 -0
- package/dist/parser/postgresql/postgreSemanticContextCollector.js +14 -0
- package/dist/parser/spark/index.d.ts +4 -2
- package/dist/parser/spark/index.js +26 -14
- package/dist/parser/spark/sparkErrorListener.js +9 -3
- package/dist/parser/spark/sparkSemanticContextCollector.d.ts +9 -0
- package/dist/parser/spark/sparkSemanticContextCollector.js +14 -0
- package/dist/parser/trino/index.d.ts +4 -2
- package/dist/parser/trino/index.js +22 -14
- package/dist/parser/trino/trinoErrorListener.js +9 -3
- package/dist/parser/trino/trinoSemanticContextCollector.d.ts +9 -0
- package/dist/parser/trino/trinoSemanticContextCollector.js +14 -0
- package/package.json +2 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PostgreSqlParserListener } from '../../lib';
|
|
2
|
+
import { SingleStmtContext } from '../../lib/postgresql/PostgreSqlParser';
|
|
3
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
4
|
+
declare class PostgreSemanticContextCollector extends SemanticContextCollector implements PostgreSqlParserListener {
|
|
5
|
+
getWhiteSpaceRuleType(): number;
|
|
6
|
+
getStatementRuleType(): number;
|
|
7
|
+
enterSingleStmt(ctx: SingleStmtContext): void;
|
|
8
|
+
}
|
|
9
|
+
export { PostgreSemanticContextCollector };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PostgreSqlParser } from '../../lib/postgresql/PostgreSqlParser';
|
|
2
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
3
|
+
class PostgreSemanticContextCollector extends SemanticContextCollector {
|
|
4
|
+
getWhiteSpaceRuleType() {
|
|
5
|
+
return PostgreSqlParser.WHITE_SPACE;
|
|
6
|
+
}
|
|
7
|
+
getStatementRuleType() {
|
|
8
|
+
return PostgreSqlParser.RULE_singleStmt;
|
|
9
|
+
}
|
|
10
|
+
enterSingleStmt(ctx) {
|
|
11
|
+
this.visitStatement(ctx);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export { PostgreSemanticContextCollector };
|
|
@@ -3,11 +3,12 @@ import { CharStream, CommonTokenStream, Token } from 'antlr4ng';
|
|
|
3
3
|
import { SparkSqlLexer } from '../../lib/spark/SparkSqlLexer';
|
|
4
4
|
import { ProgramContext, SparkSqlParser } from '../../lib/spark/SparkSqlParser';
|
|
5
5
|
import { BasicSQL } from '../common/basicSQL';
|
|
6
|
+
import { Suggestions, CaretPosition, SemanticCollectOptions } from '../common/types';
|
|
6
7
|
import { ErrorListener } from '../common/parseErrorListener';
|
|
7
|
-
import { Suggestions } from '../common/types';
|
|
8
8
|
import { SparkEntityCollector } from './sparkEntityCollector';
|
|
9
9
|
import { SparkErrorListener } from './sparkErrorListener';
|
|
10
10
|
import { SparkSqlSplitListener } from './sparkSplitListener';
|
|
11
|
+
import { SparkSemanticContextCollector } from './sparkSemanticContextCollector';
|
|
11
12
|
export { SparkEntityCollector, SparkSqlSplitListener };
|
|
12
13
|
export declare class SparkSQL extends BasicSQL<SparkSqlLexer, ProgramContext, SparkSqlParser> {
|
|
13
14
|
protected createLexerFromCharStream(charStreams: CharStream): SparkSqlLexer;
|
|
@@ -16,5 +17,6 @@ export declare class SparkSQL extends BasicSQL<SparkSqlLexer, ProgramContext, Sp
|
|
|
16
17
|
protected get splitListener(): SparkSqlSplitListener;
|
|
17
18
|
protected createErrorListener(_errorListener: ErrorListener): SparkErrorListener;
|
|
18
19
|
protected createEntityCollector(input: string, allTokens?: Token[], caretTokenIndex?: number): SparkEntityCollector;
|
|
19
|
-
protected
|
|
20
|
+
protected createSemanticContextCollector(input: string, caretPosition: CaretPosition, allTokens: Token[], options?: SemanticCollectOptions): SparkSemanticContextCollector;
|
|
21
|
+
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number): Suggestions<Token>;
|
|
20
22
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { processTokenCandidates } from '../common/tokenUtils';
|
|
1
2
|
import { SparkSqlLexer } from '../../lib/spark/SparkSqlLexer';
|
|
2
3
|
import { SparkSqlParser } from '../../lib/spark/SparkSqlParser';
|
|
3
4
|
import { BasicSQL } from '../common/basicSQL';
|
|
4
|
-
import { EntityContextType } from '../common/types';
|
|
5
|
+
import { EntityContextType, } from '../common/types';
|
|
5
6
|
import { SparkEntityCollector } from './sparkEntityCollector';
|
|
6
7
|
import { SparkErrorListener } from './sparkErrorListener';
|
|
7
8
|
import { SparkSqlSplitListener } from './sparkSplitListener';
|
|
9
|
+
import { SparkSemanticContextCollector } from './sparkSemanticContextCollector';
|
|
8
10
|
export { SparkEntityCollector, SparkSqlSplitListener };
|
|
9
11
|
export class SparkSQL extends BasicSQL {
|
|
10
12
|
constructor() {
|
|
@@ -19,6 +21,7 @@ export class SparkSQL extends BasicSQL {
|
|
|
19
21
|
SparkSqlParser.RULE_functionName,
|
|
20
22
|
SparkSqlParser.RULE_functionNameCreate,
|
|
21
23
|
SparkSqlParser.RULE_columnName,
|
|
24
|
+
SparkSqlParser.RULE_columnNamePath,
|
|
22
25
|
SparkSqlParser.RULE_columnNameCreate,
|
|
23
26
|
]);
|
|
24
27
|
}
|
|
@@ -38,13 +41,15 @@ export class SparkSQL extends BasicSQL {
|
|
|
38
41
|
createEntityCollector(input, allTokens, caretTokenIndex) {
|
|
39
42
|
return new SparkEntityCollector(input, allTokens, caretTokenIndex);
|
|
40
43
|
}
|
|
41
|
-
|
|
44
|
+
createSemanticContextCollector(input, caretPosition, allTokens, options) {
|
|
45
|
+
return new SparkSemanticContextCollector(input, caretPosition, allTokens, options);
|
|
46
|
+
}
|
|
47
|
+
processCandidates(candidates, allTokens, caretTokenIndex) {
|
|
42
48
|
const originalSyntaxSuggestions = [];
|
|
43
49
|
const keywords = [];
|
|
44
50
|
for (const candidate of candidates.rules) {
|
|
45
51
|
const [ruleType, candidateRule] = candidate;
|
|
46
|
-
const
|
|
47
|
-
const tokenRanges = allTokens.slice(startTokenIndex, caretTokenIndex + tokenIndexOffset + 1);
|
|
52
|
+
const tokenRanges = allTokens.slice(candidateRule.startTokenIndex, caretTokenIndex + 1);
|
|
48
53
|
let syntaxContextType = void 0;
|
|
49
54
|
switch (ruleType) {
|
|
50
55
|
case SparkSqlParser.RULE_namespaceName: {
|
|
@@ -87,6 +92,21 @@ export class SparkSQL extends BasicSQL {
|
|
|
87
92
|
syntaxContextType = EntityContextType.COLUMN_CREATE;
|
|
88
93
|
break;
|
|
89
94
|
}
|
|
95
|
+
case SparkSqlParser.RULE_columnNamePath: {
|
|
96
|
+
if (candidateRule.ruleList.includes(SparkSqlParser.RULE_whenClause) ||
|
|
97
|
+
candidateRule.ruleList.includes(SparkSqlParser.RULE_whereClause) ||
|
|
98
|
+
candidateRule.ruleList.includes(SparkSqlParser.RULE_joinRelation) ||
|
|
99
|
+
candidateRule.ruleList.includes(SparkSqlParser.RULE_orderOrSortByClause) ||
|
|
100
|
+
candidateRule.ruleList.includes(SparkSqlParser.RULE_groupByClause) ||
|
|
101
|
+
candidateRule.ruleList.includes(SparkSqlParser.RULE_aggregationClause) ||
|
|
102
|
+
candidateRule.ruleList.includes(SparkSqlParser.RULE_havingClause) ||
|
|
103
|
+
candidateRule.ruleList.includes(SparkSqlParser.RULE_windowClause) ||
|
|
104
|
+
candidateRule.ruleList.includes(SparkSqlParser.RULE_selectClause) ||
|
|
105
|
+
candidateRule.ruleList.includes(SparkSqlParser.RULE_limitClause) ||
|
|
106
|
+
candidateRule.ruleList.includes(SparkSqlParser.RULE_clusterOrDistributeBy)) {
|
|
107
|
+
syntaxContextType = EntityContextType.COLUMN;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
90
110
|
default:
|
|
91
111
|
break;
|
|
92
112
|
}
|
|
@@ -97,16 +117,8 @@ export class SparkSQL extends BasicSQL {
|
|
|
97
117
|
});
|
|
98
118
|
}
|
|
99
119
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const displayName = this._parser.vocabulary.getDisplayName(candidate[0]);
|
|
103
|
-
if (displayName && symbolicName && symbolicName.startsWith('KW_')) {
|
|
104
|
-
const keyword = displayName.startsWith("'") && displayName.endsWith("'")
|
|
105
|
-
? displayName.slice(1, -1)
|
|
106
|
-
: displayName;
|
|
107
|
-
keywords.push(keyword);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
120
|
+
const processedKeywords = processTokenCandidates(this._parser, candidates.tokens);
|
|
121
|
+
keywords.push(...processedKeywords);
|
|
110
122
|
return {
|
|
111
123
|
syntax: originalSyntaxSuggestions,
|
|
112
124
|
keywords,
|
|
@@ -14,6 +14,7 @@ export class SparkErrorListener extends ParseErrorListener {
|
|
|
14
14
|
[SparkSqlParser.RULE_functionName, 'function'],
|
|
15
15
|
[SparkSqlParser.RULE_functionNameCreate, 'function'],
|
|
16
16
|
[SparkSqlParser.RULE_columnName, 'column'],
|
|
17
|
+
[SparkSqlParser.RULE_columnNamePath, 'column'],
|
|
17
18
|
[SparkSqlParser.RULE_columnNameCreate, 'column'],
|
|
18
19
|
]);
|
|
19
20
|
}
|
|
@@ -48,8 +49,11 @@ export class SparkErrorListener extends ParseErrorListener {
|
|
|
48
49
|
case SparkSqlParser.RULE_tableName:
|
|
49
50
|
case SparkSqlParser.RULE_viewName:
|
|
50
51
|
case SparkSqlParser.RULE_functionName:
|
|
51
|
-
case SparkSqlParser.RULE_columnName:
|
|
52
|
-
|
|
52
|
+
case SparkSqlParser.RULE_columnName:
|
|
53
|
+
case SparkSqlParser.RULE_columnNamePath: {
|
|
54
|
+
if (!result.includes(`{existing}${name}`)) {
|
|
55
|
+
result.push(`{existing}${name}`);
|
|
56
|
+
}
|
|
53
57
|
break;
|
|
54
58
|
}
|
|
55
59
|
case SparkSqlParser.RULE_namespaceNameCreate:
|
|
@@ -57,7 +61,9 @@ export class SparkErrorListener extends ParseErrorListener {
|
|
|
57
61
|
case SparkSqlParser.RULE_functionNameCreate:
|
|
58
62
|
case SparkSqlParser.RULE_viewNameCreate:
|
|
59
63
|
case SparkSqlParser.RULE_columnNameCreate: {
|
|
60
|
-
result.
|
|
64
|
+
if (!result.includes(`{new}${name}`)) {
|
|
65
|
+
result.push(`{new}${name}`);
|
|
66
|
+
}
|
|
61
67
|
break;
|
|
62
68
|
}
|
|
63
69
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SparkSqlParserListener } from '../../lib';
|
|
2
|
+
import { SingleStatementContext } from '../../lib/spark/SparkSqlParser';
|
|
3
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
4
|
+
declare class SparkSemanticContextCollector extends SemanticContextCollector implements SparkSqlParserListener {
|
|
5
|
+
getWhiteSpaceRuleType(): number;
|
|
6
|
+
getStatementRuleType(): number;
|
|
7
|
+
enterSingleStatement(ctx: SingleStatementContext): void;
|
|
8
|
+
}
|
|
9
|
+
export { SparkSemanticContextCollector };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SparkSqlParser } from '../../lib/spark/SparkSqlParser';
|
|
2
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
3
|
+
class SparkSemanticContextCollector extends SemanticContextCollector {
|
|
4
|
+
getWhiteSpaceRuleType() {
|
|
5
|
+
return SparkSqlParser.WHITE_SPACE;
|
|
6
|
+
}
|
|
7
|
+
getStatementRuleType() {
|
|
8
|
+
return SparkSqlParser.RULE_singleStatement;
|
|
9
|
+
}
|
|
10
|
+
enterSingleStatement(ctx) {
|
|
11
|
+
this.visitStatement(ctx);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export { SparkSemanticContextCollector };
|
|
@@ -3,11 +3,12 @@ import { CharStream, CommonTokenStream, Token } from 'antlr4ng';
|
|
|
3
3
|
import { TrinoSqlLexer } from '../../lib/trino/TrinoSqlLexer';
|
|
4
4
|
import { ProgramContext, TrinoSqlParser } from '../../lib/trino/TrinoSqlParser';
|
|
5
5
|
import { BasicSQL } from '../common/basicSQL';
|
|
6
|
+
import { Suggestions, CaretPosition, SemanticCollectOptions } from '../common/types';
|
|
6
7
|
import { ErrorListener } from '../common/parseErrorListener';
|
|
7
|
-
import { Suggestions } from '../common/types';
|
|
8
8
|
import { TrinoEntityCollector } from './trinoEntityCollector';
|
|
9
9
|
import { TrinoErrorListener } from './trinoErrorListener';
|
|
10
10
|
import { TrinoSqlSplitListener } from './trinoSplitListener';
|
|
11
|
+
import { TrinoSemanticContextCollector } from './trinoSemanticContextCollector';
|
|
11
12
|
export { TrinoEntityCollector, TrinoSqlSplitListener };
|
|
12
13
|
export declare class TrinoSQL extends BasicSQL<TrinoSqlLexer, ProgramContext, TrinoSqlParser> {
|
|
13
14
|
protected createLexerFromCharStream(charStreams: CharStream): TrinoSqlLexer;
|
|
@@ -15,6 +16,7 @@ export declare class TrinoSQL extends BasicSQL<TrinoSqlLexer, ProgramContext, Tr
|
|
|
15
16
|
protected get splitListener(): TrinoSqlSplitListener;
|
|
16
17
|
protected createErrorListener(_errorListener: ErrorListener): TrinoErrorListener;
|
|
17
18
|
protected createEntityCollector(input: string, allTokens?: Token[], caretTokenIndex?: number): TrinoEntityCollector;
|
|
19
|
+
protected createSemanticContextCollector(input: string, caretPosition: CaretPosition, allTokens: Token[], options?: SemanticCollectOptions): TrinoSemanticContextCollector;
|
|
18
20
|
protected preferredRules: Set<number>;
|
|
19
|
-
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number
|
|
21
|
+
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number): Suggestions<Token>;
|
|
20
22
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { processTokenCandidates } from '../common/tokenUtils';
|
|
1
2
|
import { TrinoSqlLexer } from '../../lib/trino/TrinoSqlLexer';
|
|
2
3
|
import { TrinoSqlParser } from '../../lib/trino/TrinoSqlParser';
|
|
3
4
|
import { BasicSQL } from '../common/basicSQL';
|
|
4
|
-
import { EntityContextType } from '../common/types';
|
|
5
|
+
import { EntityContextType, } from '../common/types';
|
|
5
6
|
import { TrinoEntityCollector } from './trinoEntityCollector';
|
|
6
7
|
import { TrinoErrorListener } from './trinoErrorListener';
|
|
7
8
|
import { TrinoSqlSplitListener } from './trinoSplitListener';
|
|
9
|
+
import { TrinoSemanticContextCollector } from './trinoSemanticContextCollector';
|
|
8
10
|
export { TrinoEntityCollector, TrinoSqlSplitListener };
|
|
9
11
|
export class TrinoSQL extends BasicSQL {
|
|
10
12
|
constructor() {
|
|
@@ -21,6 +23,7 @@ export class TrinoSQL extends BasicSQL {
|
|
|
21
23
|
TrinoSqlParser.RULE_functionName,
|
|
22
24
|
TrinoSqlParser.RULE_functionNameCreate,
|
|
23
25
|
TrinoSqlParser.RULE_columnRef,
|
|
26
|
+
TrinoSqlParser.RULE_columnName,
|
|
24
27
|
TrinoSqlParser.RULE_columnNameCreate,
|
|
25
28
|
]);
|
|
26
29
|
}
|
|
@@ -40,13 +43,15 @@ export class TrinoSQL extends BasicSQL {
|
|
|
40
43
|
createEntityCollector(input, allTokens, caretTokenIndex) {
|
|
41
44
|
return new TrinoEntityCollector(input, allTokens, caretTokenIndex);
|
|
42
45
|
}
|
|
43
|
-
|
|
46
|
+
createSemanticContextCollector(input, caretPosition, allTokens, options) {
|
|
47
|
+
return new TrinoSemanticContextCollector(input, caretPosition, allTokens, options);
|
|
48
|
+
}
|
|
49
|
+
processCandidates(candidates, allTokens, caretTokenIndex) {
|
|
44
50
|
const originalSyntaxSuggestions = [];
|
|
45
51
|
const keywords = [];
|
|
46
52
|
for (let candidate of candidates.rules) {
|
|
47
53
|
const [ruleType, candidateRule] = candidate;
|
|
48
|
-
const
|
|
49
|
-
const tokenRanges = allTokens.slice(startTokenIndex, caretTokenIndex + tokenIndexOffset + 1);
|
|
54
|
+
const tokenRanges = allTokens.slice(candidateRule.startTokenIndex, caretTokenIndex + 1);
|
|
50
55
|
let syntaxContextType = void 0;
|
|
51
56
|
switch (ruleType) {
|
|
52
57
|
case TrinoSqlParser.RULE_catalogRef: {
|
|
@@ -97,6 +102,17 @@ export class TrinoSQL extends BasicSQL {
|
|
|
97
102
|
syntaxContextType = EntityContextType.COLUMN;
|
|
98
103
|
break;
|
|
99
104
|
}
|
|
105
|
+
case TrinoSqlParser.RULE_columnName: {
|
|
106
|
+
if (candidateRule.ruleList.includes(TrinoSqlParser.RULE_groupBy) ||
|
|
107
|
+
candidateRule.ruleList.includes(TrinoSqlParser.RULE_sortItem) ||
|
|
108
|
+
candidateRule.ruleList.includes(TrinoSqlParser.RULE_whereClause) ||
|
|
109
|
+
candidateRule.ruleList.includes(TrinoSqlParser.RULE_havingClause) ||
|
|
110
|
+
candidateRule.ruleList.includes(TrinoSqlParser.RULE_partitionBy) ||
|
|
111
|
+
candidateRule.ruleList.includes(TrinoSqlParser.RULE_whenClause) ||
|
|
112
|
+
candidateRule.ruleList.includes(TrinoSqlParser.RULE_relation)) {
|
|
113
|
+
syntaxContextType = EntityContextType.COLUMN;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
100
116
|
default:
|
|
101
117
|
break;
|
|
102
118
|
}
|
|
@@ -107,16 +123,8 @@ export class TrinoSQL extends BasicSQL {
|
|
|
107
123
|
});
|
|
108
124
|
}
|
|
109
125
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const displayName = this._parser.vocabulary.getDisplayName(candidate[0]);
|
|
113
|
-
if (displayName && symbolicName && symbolicName.startsWith('KW_')) {
|
|
114
|
-
const keyword = displayName.startsWith("'") && displayName.endsWith("'")
|
|
115
|
-
? displayName.slice(1, -1)
|
|
116
|
-
: displayName;
|
|
117
|
-
keywords.push(keyword);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
126
|
+
const processedKeywords = processTokenCandidates(this._parser, candidates.tokens);
|
|
127
|
+
keywords.push(...processedKeywords);
|
|
120
128
|
return {
|
|
121
129
|
syntax: originalSyntaxSuggestions,
|
|
122
130
|
keywords,
|
|
@@ -15,6 +15,7 @@ export class TrinoErrorListener extends ParseErrorListener {
|
|
|
15
15
|
[TrinoSqlParser.RULE_schemaNameCreate, 'schema'],
|
|
16
16
|
[TrinoSqlParser.RULE_functionName, 'function'],
|
|
17
17
|
[TrinoSqlParser.RULE_columnRef, 'column'],
|
|
18
|
+
[TrinoSqlParser.RULE_columnName, 'column'],
|
|
18
19
|
[TrinoSqlParser.RULE_columnNameCreate, 'column'],
|
|
19
20
|
]);
|
|
20
21
|
}
|
|
@@ -50,8 +51,11 @@ export class TrinoErrorListener extends ParseErrorListener {
|
|
|
50
51
|
case TrinoSqlParser.RULE_tableRef:
|
|
51
52
|
case TrinoSqlParser.RULE_viewRef:
|
|
52
53
|
case TrinoSqlParser.RULE_functionName:
|
|
53
|
-
case TrinoSqlParser.RULE_columnRef:
|
|
54
|
-
|
|
54
|
+
case TrinoSqlParser.RULE_columnRef:
|
|
55
|
+
case TrinoSqlParser.RULE_columnName: {
|
|
56
|
+
if (!result.includes(`{existing}${name}`)) {
|
|
57
|
+
result.push(`{existing}${name}`);
|
|
58
|
+
}
|
|
55
59
|
break;
|
|
56
60
|
}
|
|
57
61
|
case TrinoSqlParser.RULE_catalogNameCreate:
|
|
@@ -59,7 +63,9 @@ export class TrinoErrorListener extends ParseErrorListener {
|
|
|
59
63
|
case TrinoSqlParser.RULE_schemaNameCreate:
|
|
60
64
|
case TrinoSqlParser.RULE_viewNameCreate:
|
|
61
65
|
case TrinoSqlParser.RULE_tableNameCreate: {
|
|
62
|
-
result.
|
|
66
|
+
if (!result.includes(`{new}${name}`)) {
|
|
67
|
+
result.push(`{new}${name}`);
|
|
68
|
+
}
|
|
63
69
|
break;
|
|
64
70
|
}
|
|
65
71
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TrinoSqlListener } from '../../lib';
|
|
2
|
+
import { StatementsContext } from '../../lib/trino/TrinoSqlParser';
|
|
3
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
4
|
+
declare class TrinoSemanticContextCollector extends SemanticContextCollector implements TrinoSqlListener {
|
|
5
|
+
getWhiteSpaceRuleType(): number;
|
|
6
|
+
getStatementRuleType(): number;
|
|
7
|
+
enterStatements(ctx: StatementsContext): void;
|
|
8
|
+
}
|
|
9
|
+
export { TrinoSemanticContextCollector };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TrinoSqlParser } from '../../lib/trino/TrinoSqlParser';
|
|
2
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
3
|
+
class TrinoSemanticContextCollector extends SemanticContextCollector {
|
|
4
|
+
getWhiteSpaceRuleType() {
|
|
5
|
+
return TrinoSqlParser.WHITE_SPACE;
|
|
6
|
+
}
|
|
7
|
+
getStatementRuleType() {
|
|
8
|
+
return TrinoSqlParser.RULE_statements;
|
|
9
|
+
}
|
|
10
|
+
enterStatements(ctx) {
|
|
11
|
+
this.visitStatement(ctx);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export { TrinoSemanticContextCollector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dt-sql-parser",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"authors": "DTStack Corporation",
|
|
5
5
|
"description": "SQL Parsers for BigData, built with antlr4",
|
|
6
6
|
"keywords": [
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"prepublishOnly": "npm run build",
|
|
28
28
|
"antlr4": "node ./scripts/antlr4.js",
|
|
29
29
|
"build": "rm -rf dist && tsc",
|
|
30
|
+
"watch": "tsc -w",
|
|
30
31
|
"check-types": "tsc -p ./tsconfig.json && tsc -p ./test/tsconfig.json",
|
|
31
32
|
"test": "NODE_OPTIONS=--max_old_space_size=4096 && jest",
|
|
32
33
|
"release": "node ./scripts/release.js",
|