dt-sql-parser 4.5.0 → 4.5.1-beta.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/dist/lib/flink/FlinkSqlLexer.d.ts +397 -399
- package/dist/lib/flink/FlinkSqlLexer.js +2489 -2504
- package/dist/lib/flink/FlinkSqlParser.d.ts +465 -617
- package/dist/lib/flink/FlinkSqlParser.js +3360 -5015
- package/dist/lib/flink/FlinkSqlParserListener.d.ts +0 -90
- package/dist/lib/flink/FlinkSqlParserVisitor.d.ts +0 -57
- package/dist/lib/generic/GenericSqlListener.d.ts +90 -5
- package/dist/lib/generic/GenericSqlParser.d.ts +101 -32
- package/dist/lib/generic/GenericSqlParser.js +1312 -912
- package/dist/lib/generic/GenericSqlVisitor.d.ts +56 -3
- package/dist/lib/spark/SparkSqlParser.d.ts +1 -1
- package/dist/lib/spark/SparkSqlParser.js +2963 -2925
- package/dist/lib/trino/TrinoSqlLexer.d.ts +296 -297
- package/dist/lib/trino/TrinoSqlLexer.js +1445 -1451
- package/dist/lib/trino/TrinoSqlListener.d.ts +0 -13
- package/dist/lib/trino/TrinoSqlParser.d.ts +297 -308
- package/dist/lib/trino/TrinoSqlParser.js +2300 -2381
- package/dist/lib/trino/TrinoSqlVisitor.d.ts +0 -8
- package/dist/parser/common/basicSQL.d.ts +0 -12
- package/dist/parser/common/basicSQL.js +0 -71
- package/dist/parser/generic/genericEntityCollector.d.ts +6 -3
- package/dist/parser/generic/genericEntityCollector.js +29 -21
- package/dist/parser/generic/index.js +15 -0
- package/package.json +1 -1
|
@@ -223,7 +223,6 @@ import { NullLiteralContext } from "./TrinoSqlParser.js";
|
|
|
223
223
|
import { RowConstructorContext } from "./TrinoSqlParser.js";
|
|
224
224
|
import { SubscriptContext } from "./TrinoSqlParser.js";
|
|
225
225
|
import { JsonExistsContext } from "./TrinoSqlParser.js";
|
|
226
|
-
import { CoalesceContext } from "./TrinoSqlParser.js";
|
|
227
226
|
import { CurrentPathContext } from "./TrinoSqlParser.js";
|
|
228
227
|
import { SubqueryExpressionContext } from "./TrinoSqlParser.js";
|
|
229
228
|
import { BinaryLiteralContext } from "./TrinoSqlParser.js";
|
|
@@ -1889,13 +1888,6 @@ export declare class TrinoSqlVisitor<Result> extends AbstractParseTreeVisitor<Re
|
|
|
1889
1888
|
* @return the visitor result
|
|
1890
1889
|
*/
|
|
1891
1890
|
visitJsonExists?: (ctx: JsonExistsContext) => Result;
|
|
1892
|
-
/**
|
|
1893
|
-
* Visit a parse tree produced by the `coalesce`
|
|
1894
|
-
* labeled alternative in `TrinoSqlParser.primaryExpression`.
|
|
1895
|
-
* @param ctx the parse tree
|
|
1896
|
-
* @return the visitor result
|
|
1897
|
-
*/
|
|
1898
|
-
visitCoalesce?: (ctx: CoalesceContext) => Result;
|
|
1899
1891
|
/**
|
|
1900
1892
|
* Visit a parse tree produced by the `currentPath`
|
|
1901
1893
|
* labeled alternative in `TrinoSqlParser.primaryExpression`.
|
|
@@ -95,22 +95,10 @@ export declare abstract class BasicSQL<L extends Lexer = Lexer, PRC extends Pars
|
|
|
95
95
|
private parseWithCache;
|
|
96
96
|
/**
|
|
97
97
|
* Validate input string and return syntax errors if exists.
|
|
98
|
-
* When input contains multiple statements separated by semicolons
|
|
99
|
-
* and the initial parse doesn't capture all errors, each statement
|
|
100
|
-
* is validated independently to collect all errors.
|
|
101
98
|
* @param input source string
|
|
102
99
|
* @returns syntax errors
|
|
103
100
|
*/
|
|
104
101
|
validate(input: string): ParseError[];
|
|
105
|
-
/**
|
|
106
|
-
* Validate each statement fragment independently and collect all errors.
|
|
107
|
-
*/
|
|
108
|
-
private validateStatements;
|
|
109
|
-
/**
|
|
110
|
-
* Split input into individual statement strings by semicolons.
|
|
111
|
-
* Handles semicolons inside quoted strings correctly.
|
|
112
|
-
*/
|
|
113
|
-
private splitStatements;
|
|
114
102
|
/**
|
|
115
103
|
* Get the input string that has been parsed.
|
|
116
104
|
*/
|
|
@@ -104,84 +104,13 @@ export class BasicSQL {
|
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* Validate input string and return syntax errors if exists.
|
|
107
|
-
* When input contains multiple statements separated by semicolons
|
|
108
|
-
* and the initial parse doesn't capture all errors, each statement
|
|
109
|
-
* is validated independently to collect all errors.
|
|
110
107
|
* @param input source string
|
|
111
108
|
* @returns syntax errors
|
|
112
109
|
*/
|
|
113
110
|
validate(input) {
|
|
114
111
|
this.parseWithCache(input);
|
|
115
|
-
if (this._parseErrors.length > 0) {
|
|
116
|
-
const statements = this.splitStatements(input);
|
|
117
|
-
if (statements.length > 1) {
|
|
118
|
-
const splitErrors = this.validateStatements(statements);
|
|
119
|
-
if (splitErrors.length > this._parseErrors.length) {
|
|
120
|
-
this._parseErrors = splitErrors;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
112
|
return this._parseErrors;
|
|
125
113
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Validate each statement fragment independently and collect all errors.
|
|
128
|
-
*/
|
|
129
|
-
validateStatements(statements) {
|
|
130
|
-
const allErrors = [];
|
|
131
|
-
let lineOffset = 0;
|
|
132
|
-
for (const statement of statements) {
|
|
133
|
-
if (!statement.text.trim()) {
|
|
134
|
-
const newlines = (statement.text.match(/\n/g) || []).length;
|
|
135
|
-
lineOffset += newlines;
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
const parser = this.createParser(statement.text);
|
|
139
|
-
const errors = [];
|
|
140
|
-
parser.removeErrorListeners();
|
|
141
|
-
parser.addErrorListener(this.createErrorListener((error) => {
|
|
142
|
-
errors.push({
|
|
143
|
-
startLine: error.startLine + lineOffset,
|
|
144
|
-
endLine: error.endLine + lineOffset,
|
|
145
|
-
startColumn: error.startColumn,
|
|
146
|
-
endColumn: error.endColumn,
|
|
147
|
-
message: error.message,
|
|
148
|
-
});
|
|
149
|
-
}));
|
|
150
|
-
parser.errorHandler = new ErrorStrategy();
|
|
151
|
-
parser.program();
|
|
152
|
-
allErrors.push(...errors);
|
|
153
|
-
const newlines = (statement.text.match(/\n/g) || []).length;
|
|
154
|
-
lineOffset += newlines;
|
|
155
|
-
}
|
|
156
|
-
return allErrors;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Split input into individual statement strings by semicolons.
|
|
160
|
-
* Handles semicolons inside quoted strings correctly.
|
|
161
|
-
*/
|
|
162
|
-
splitStatements(input) {
|
|
163
|
-
const statements = [];
|
|
164
|
-
let inSingleQuote = false;
|
|
165
|
-
let inDoubleQuote = false;
|
|
166
|
-
let lastSplit = 0;
|
|
167
|
-
for (let i = 0; i < input.length; i++) {
|
|
168
|
-
const ch = input[i];
|
|
169
|
-
if (ch === "'" && !inDoubleQuote) {
|
|
170
|
-
inSingleQuote = !inSingleQuote;
|
|
171
|
-
}
|
|
172
|
-
else if (ch === '"' && !inSingleQuote) {
|
|
173
|
-
inDoubleQuote = !inDoubleQuote;
|
|
174
|
-
}
|
|
175
|
-
else if (ch === ';' && !inSingleQuote && !inDoubleQuote) {
|
|
176
|
-
statements.push({ text: input.slice(lastSplit, i + 1), start: lastSplit });
|
|
177
|
-
lastSplit = i + 1;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (lastSplit < input.length) {
|
|
181
|
-
statements.push({ text: input.slice(lastSplit), start: lastSplit });
|
|
182
|
-
}
|
|
183
|
-
return statements;
|
|
184
|
-
}
|
|
185
114
|
/**
|
|
186
115
|
* Get the input string that has been parsed.
|
|
187
116
|
*/
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import type { GenericSqlListener } from '../../lib/generic/GenericSqlListener';
|
|
2
|
-
import { AlterTableContext,
|
|
2
|
+
import { AlterTableContext, ColumnRefContext, ColumnRefCreateContext, CreateTableContext, DeleteContext, DropTableContext, InsertContext, QuerySpecificationContext, QueryStatementContext, SelectAllElementContext, SelectEmptyElementContext, SelectExpressionElementContext, SelectStarElementContext, SingleStatementContext, TableNameContext, TableNameCreateContext, UpdateContext } from '../../lib/generic/GenericSqlParser';
|
|
3
3
|
import { EntityCollector } from '../common/entityCollector';
|
|
4
4
|
export declare class GenericEntityCollector extends EntityCollector implements GenericSqlListener {
|
|
5
5
|
/** ====== Entity Begin */
|
|
6
6
|
exitTableName(ctx: TableNameContext): void;
|
|
7
7
|
exitTableNameCreate(ctx: TableNameCreateContext): void;
|
|
8
8
|
exitColumnRef(ctx: ColumnRefContext): void;
|
|
9
|
-
|
|
9
|
+
exitColumnRefCreate(ctx: ColumnRefCreateContext): void;
|
|
10
10
|
exitQuerySpecification(ctx: QuerySpecificationContext): void;
|
|
11
|
-
|
|
11
|
+
exitSelectExpressionElement(ctx: SelectExpressionElementContext): void;
|
|
12
|
+
exitSelectStarElement(ctx: SelectStarElementContext): void;
|
|
13
|
+
exitSelectAllElement(ctx: SelectAllElementContext): void;
|
|
14
|
+
exitSelectEmptyElement(ctx: SelectEmptyElementContext): void;
|
|
12
15
|
private isSimpleColumnReference;
|
|
13
16
|
/** ===== Statement begin */
|
|
14
17
|
enterSingleStatement(ctx: SingleStatementContext): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColumnDefinitionContext, CreateTableStatementContext,
|
|
1
|
+
import { ColumnDefinitionContext, CreateTableStatementContext, SelectExpressionElementContext, } from '../../lib/generic/GenericSqlParser';
|
|
2
2
|
import { AttrName, ColumnDeclareType, EntityCollector, StmtContextType, TableDeclareType, } from '../common/entityCollector';
|
|
3
3
|
import { EntityContextType } from '../common/types';
|
|
4
4
|
export class GenericEntityCollector extends EntityCollector {
|
|
@@ -19,7 +19,7 @@ export class GenericEntityCollector extends EntityCollector {
|
|
|
19
19
|
exitColumnRef(ctx) {
|
|
20
20
|
this.pushEntity(ctx, EntityContextType.COLUMN);
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
exitColumnRefCreate(ctx) {
|
|
23
23
|
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [
|
|
24
24
|
{
|
|
25
25
|
attrName: AttrName.colType,
|
|
@@ -34,25 +34,33 @@ export class GenericEntityCollector extends EntityCollector {
|
|
|
34
34
|
exitQuerySpecification(ctx) {
|
|
35
35
|
this.pushEntity(ctx, EntityContextType.QUERY_RESULT);
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
37
|
+
exitSelectExpressionElement(ctx) {
|
|
38
|
+
const isSimpleColumn = this.isSimpleColumnReference(ctx);
|
|
39
|
+
this.pushEntity(ctx, EntityContextType.COLUMN, [
|
|
40
|
+
{
|
|
41
|
+
attrName: AttrName.alias,
|
|
42
|
+
endContextList: [SelectExpressionElementContext.name],
|
|
43
|
+
},
|
|
44
|
+
], {
|
|
45
|
+
declareType: isSimpleColumn
|
|
46
|
+
? ColumnDeclareType.LITERAL
|
|
47
|
+
: ColumnDeclareType.EXPRESSION,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exitSelectStarElement(ctx) {
|
|
51
|
+
this.pushEntity(ctx, EntityContextType.COLUMN, [], {
|
|
52
|
+
declareType: ColumnDeclareType.ALL,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exitSelectAllElement(ctx) {
|
|
56
|
+
this.pushEntity(ctx, EntityContextType.COLUMN, [], {
|
|
57
|
+
declareType: ColumnDeclareType.ALL,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
exitSelectEmptyElement(ctx) {
|
|
61
|
+
this.pushEntity(ctx, EntityContextType.COLUMN, [], {
|
|
62
|
+
declareType: ColumnDeclareType.LITERAL,
|
|
63
|
+
});
|
|
56
64
|
}
|
|
57
65
|
isSimpleColumnReference(ctx) {
|
|
58
66
|
const text = ctx.getText();
|
|
@@ -19,6 +19,9 @@ export class GenericSQL extends BasicSQL {
|
|
|
19
19
|
GenericSqlParser.RULE_tableName,
|
|
20
20
|
GenericSqlParser.RULE_tableNameCreate,
|
|
21
21
|
GenericSqlParser.RULE_columnRef,
|
|
22
|
+
GenericSqlParser.RULE_columnRefCreate,
|
|
23
|
+
GenericSqlParser.RULE_columnName,
|
|
24
|
+
GenericSqlParser.RULE_functionName,
|
|
22
25
|
...this.excludeKeywordRules,
|
|
23
26
|
]);
|
|
24
27
|
this._diagnostics = (options === null || options === void 0 ? void 0 : options.diagnostics) !== false;
|
|
@@ -68,6 +71,18 @@ export class GenericSQL extends BasicSQL {
|
|
|
68
71
|
syntaxContextType = EntityContextType.COLUMN;
|
|
69
72
|
break;
|
|
70
73
|
}
|
|
74
|
+
case GenericSqlParser.RULE_columnRefCreate: {
|
|
75
|
+
syntaxContextType = EntityContextType.COLUMN_CREATE;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case GenericSqlParser.RULE_columnName: {
|
|
79
|
+
syntaxContextType = EntityContextType.COLUMN;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case GenericSqlParser.RULE_functionName: {
|
|
83
|
+
syntaxContextType = EntityContextType.FUNCTION;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
71
86
|
default:
|
|
72
87
|
break;
|
|
73
88
|
}
|