dt-sql-parser 4.5.1-beta.3 → 4.5.2-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/SQLParserBase.d.ts +9 -0
- package/dist/lib/SQLParserBase.js +15 -0
- package/dist/lib/generic/GenericSqlListener.d.ts +11 -0
- package/dist/lib/generic/GenericSqlParser.d.ts +61 -47
- package/dist/lib/generic/GenericSqlParser.js +1047 -949
- package/dist/lib/generic/GenericSqlVisitor.d.ts +7 -0
- package/dist/lib/hive/HiveSqlParser.d.ts +54 -30
- package/dist/lib/hive/HiveSqlParser.js +5633 -5467
- package/dist/lib/hive/HiveSqlParserListener.d.ts +22 -0
- package/dist/lib/hive/HiveSqlParserVisitor.d.ts +14 -0
- package/dist/lib/mysql/MySqlParser.d.ts +34 -9
- package/dist/lib/mysql/MySqlParser.js +5697 -5550
- package/dist/lib/mysql/MySqlParserListener.d.ts +33 -5
- package/dist/lib/mysql/MySqlParserVisitor.d.ts +20 -3
- package/dist/lib/postgresql/PostgreSqlParser.d.ts +200 -166
- package/dist/lib/postgresql/PostgreSqlParser.js +10389 -10136
- package/dist/lib/postgresql/PostgreSqlParserListener.d.ts +31 -5
- package/dist/lib/postgresql/PostgreSqlParserVisitor.d.ts +19 -3
- package/dist/lib/trino/TrinoSqlListener.d.ts +33 -0
- package/dist/lib/trino/TrinoSqlParser.d.ts +157 -115
- package/dist/lib/trino/TrinoSqlParser.js +4775 -4494
- package/dist/lib/trino/TrinoSqlVisitor.d.ts +21 -0
- package/dist/parser/common/basicSQL.d.ts +3 -0
- package/dist/parser/common/basicSQL.js +47 -1
- package/dist/parser/common/entityCollector.d.ts +37 -2
- package/dist/parser/common/entityCollector.js +303 -2
- package/dist/parser/flink/flinkEntityCollector.d.ts +2 -1
- package/dist/parser/flink/flinkEntityCollector.js +4 -0
- package/dist/parser/flink/index.js +1 -1
- package/dist/parser/generic/genericEntityCollector.d.ts +7 -2
- package/dist/parser/generic/genericEntityCollector.js +65 -15
- package/dist/parser/generic/index.js +13 -1
- package/dist/parser/hive/hiveEntityCollector.d.ts +2 -1
- package/dist/parser/hive/hiveEntityCollector.js +5 -0
- package/dist/parser/hive/index.js +1 -1
- package/dist/parser/impala/impalaEntityCollector.d.ts +2 -1
- package/dist/parser/impala/impalaEntityCollector.js +4 -0
- package/dist/parser/impala/index.js +1 -1
- package/dist/parser/mysql/index.js +15 -1
- package/dist/parser/mysql/mysqlEntityCollector.d.ts +3 -1
- package/dist/parser/mysql/mysqlEntityCollector.js +24 -0
- package/dist/parser/postgresql/index.js +3 -2
- package/dist/parser/postgresql/postgreEntityCollector.d.ts +3 -1
- package/dist/parser/postgresql/postgreEntityCollector.js +10 -0
- package/dist/parser/spark/index.js +1 -1
- package/dist/parser/spark/sparkEntityCollector.d.ts +2 -1
- package/dist/parser/spark/sparkEntityCollector.js +5 -0
- package/dist/parser/trino/index.js +4 -2
- package/dist/parser/trino/trinoEntityCollector.d.ts +2 -1
- package/dist/parser/trino/trinoEntityCollector.js +5 -0
- package/package.json +1 -1
|
@@ -1,13 +1,32 @@
|
|
|
1
|
-
import { ColumnDefinitionContext,
|
|
2
|
-
import { AttrName, ColumnDeclareType, EntityCollector, StmtContextType, TableDeclareType, } from '../common/entityCollector';
|
|
1
|
+
import { ColumnDefinitionContext, AliasedRelationContext, CreateTableStatementContext, } from '../../lib/generic/GenericSqlParser';
|
|
2
|
+
import { AttrName, ColumnDeclareType, EntityCollector, isColumnEntityContext, isCommonEntityContext, StmtContextType, TableDeclareType, } from '../common/entityCollector';
|
|
3
3
|
import { EntityContextType } from '../common/types';
|
|
4
|
+
import { tokenToWord } from '../common/textAndWord';
|
|
4
5
|
export class GenericEntityCollector extends EntityCollector {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
/** Select-list source text for each query result. The result itself keeps the full statement. */
|
|
9
|
+
this.selectListText = new Map();
|
|
10
|
+
}
|
|
11
|
+
enterProgram() {
|
|
12
|
+
this.selectListText.clear();
|
|
13
|
+
super.enterProgram();
|
|
14
|
+
}
|
|
5
15
|
/** ====== Entity Begin */
|
|
6
16
|
exitTableName(ctx) {
|
|
7
|
-
this.pushEntity(ctx, EntityContextType.TABLE, [
|
|
17
|
+
this.pushEntity(ctx, EntityContextType.TABLE, [
|
|
18
|
+
{
|
|
19
|
+
attrName: AttrName.alias,
|
|
20
|
+
endContextList: [AliasedRelationContext.name],
|
|
21
|
+
},
|
|
22
|
+
], {
|
|
8
23
|
declareType: TableDeclareType.LITERAL,
|
|
9
24
|
});
|
|
10
25
|
}
|
|
26
|
+
exitNamedQuery(ctx) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
this.collectCte(ctx, ctx.identifier(), ctx.queryStatement(), (_b = (_a = ctx.stop) === null || _a === void 0 ? void 0 : _a.tokenIndex) !== null && _b !== void 0 ? _b : -1, [], ctx.cteColumnList());
|
|
29
|
+
}
|
|
11
30
|
exitTableNameCreate(ctx) {
|
|
12
31
|
this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [
|
|
13
32
|
{
|
|
@@ -20,21 +39,51 @@ export class GenericEntityCollector extends EntityCollector {
|
|
|
20
39
|
this.pushEntity(ctx, EntityContextType.COLUMN);
|
|
21
40
|
}
|
|
22
41
|
exitColumnDefinition(ctx) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
42
|
+
var _a, _b;
|
|
43
|
+
// The name is only `columnRef`. Pushing the whole definition made the
|
|
44
|
+
// completion label `age int` and inserted the type into the SQL.
|
|
45
|
+
const entity = this.pushEntity(ctx.columnRef(), EntityContextType.COLUMN_CREATE, [
|
|
28
46
|
{
|
|
29
47
|
attrName: AttrName.comment,
|
|
30
48
|
endContextList: [ColumnDefinitionContext.name],
|
|
31
49
|
},
|
|
32
50
|
]);
|
|
51
|
+
const dataType = ctx.dataType();
|
|
52
|
+
if (entity && isColumnEntityContext(entity) && (dataType === null || dataType === void 0 ? void 0 : dataType.start) && dataType.stop) {
|
|
53
|
+
const startIndex = dataType.start.start;
|
|
54
|
+
const endIndex = dataType.stop.stop;
|
|
55
|
+
const typeText = this.sourceSlice(startIndex, endIndex);
|
|
56
|
+
const startColumn = dataType.start.column + 1;
|
|
57
|
+
entity[AttrName.colType] = {
|
|
58
|
+
text: typeText,
|
|
59
|
+
line: dataType.start.line,
|
|
60
|
+
startIndex,
|
|
61
|
+
endIndex,
|
|
62
|
+
startColumn,
|
|
63
|
+
endColumn: dataType.stop.line === dataType.start.line
|
|
64
|
+
? startColumn + typeText.length
|
|
65
|
+
: dataType.stop.column + 1 + ((_b = (_a = dataType.stop.text) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
33
68
|
}
|
|
34
69
|
exitQuerySpecification(ctx) {
|
|
35
|
-
|
|
70
|
+
var _a, _b;
|
|
71
|
+
const entity = this.pushEntity(ctx, EntityContextType.QUERY_RESULT);
|
|
72
|
+
const items = ctx.selectItem();
|
|
73
|
+
const first = (_a = items[0]) === null || _a === void 0 ? void 0 : _a.start;
|
|
74
|
+
const last = (_b = items[items.length - 1]) === null || _b === void 0 ? void 0 : _b.stop;
|
|
75
|
+
if (entity && isCommonEntityContext(entity) && first && last) {
|
|
76
|
+
this.selectListText.set(entity, this.sourceSlice(first.start, last.stop));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
adaptOutwardQueryResult(entity) {
|
|
80
|
+
const text = this.selectListText.get(entity);
|
|
81
|
+
if (text == null)
|
|
82
|
+
return entity;
|
|
83
|
+
return Object.assign(Object.assign({}, entity), { text });
|
|
36
84
|
}
|
|
37
85
|
exitSelectItem(ctx) {
|
|
86
|
+
var _a;
|
|
38
87
|
if (ctx.ASTERISK()) {
|
|
39
88
|
this.pushEntity(ctx, EntityContextType.COLUMN, [], {
|
|
40
89
|
declareType: ColumnDeclareType.ALL,
|
|
@@ -42,16 +91,17 @@ export class GenericEntityCollector extends EntityCollector {
|
|
|
42
91
|
}
|
|
43
92
|
else {
|
|
44
93
|
const isSimpleColumn = this.isSimpleColumnReference(ctx);
|
|
45
|
-
this.pushEntity(ctx, EntityContextType.COLUMN, [
|
|
46
|
-
{
|
|
47
|
-
attrName: AttrName.alias,
|
|
48
|
-
endContextList: [SelectItemContext.name],
|
|
49
|
-
},
|
|
50
|
-
], {
|
|
94
|
+
const entity = this.pushEntity(ctx, EntityContextType.COLUMN, [], {
|
|
51
95
|
declareType: isSimpleColumn
|
|
52
96
|
? ColumnDeclareType.LITERAL
|
|
53
97
|
: ColumnDeclareType.EXPRESSION,
|
|
54
98
|
});
|
|
99
|
+
// The alias sits on this select item. Searching parents would pick a
|
|
100
|
+
// later item's alias and label every column with that name.
|
|
101
|
+
const aliasToken = (_a = ctx._alias) === null || _a === void 0 ? void 0 : _a.start;
|
|
102
|
+
if (entity && aliasToken) {
|
|
103
|
+
entity[AttrName.alias] = tokenToWord(aliasToken, '');
|
|
104
|
+
}
|
|
55
105
|
}
|
|
56
106
|
}
|
|
57
107
|
isSimpleColumnReference(ctx) {
|
|
@@ -19,6 +19,7 @@ export class GenericSQL extends BasicSQL {
|
|
|
19
19
|
GenericSqlParser.RULE_tableName,
|
|
20
20
|
GenericSqlParser.RULE_tableNameCreate,
|
|
21
21
|
GenericSqlParser.RULE_columnRef,
|
|
22
|
+
GenericSqlParser.RULE_qualifiedName,
|
|
22
23
|
...this.excludeKeywordRules,
|
|
23
24
|
]);
|
|
24
25
|
this._diagnostics = (options === null || options === void 0 ? void 0 : options.diagnostics) !== false;
|
|
@@ -53,7 +54,7 @@ export class GenericSQL extends BasicSQL {
|
|
|
53
54
|
const keywords = [];
|
|
54
55
|
for (const candidate of candidates.rules) {
|
|
55
56
|
const [ruleType, candidateRule] = candidate;
|
|
56
|
-
const tokenRanges =
|
|
57
|
+
const tokenRanges = this.getCandidateTokenRanges(candidates, candidateRule.startTokenIndex, allTokens, caretTokenIndex);
|
|
57
58
|
let syntaxContextType = void 0;
|
|
58
59
|
switch (ruleType) {
|
|
59
60
|
case GenericSqlParser.RULE_tableName: {
|
|
@@ -68,6 +69,17 @@ export class GenericSQL extends BasicSQL {
|
|
|
68
69
|
syntaxContextType = EntityContextType.COLUMN;
|
|
69
70
|
break;
|
|
70
71
|
}
|
|
72
|
+
case GenericSqlParser.RULE_qualifiedName: {
|
|
73
|
+
// Expressions use qualifiedName for columns. Table names use the same
|
|
74
|
+
// rule through tableName, and those stay TABLE suggestions.
|
|
75
|
+
const rules = candidateRule.ruleList;
|
|
76
|
+
if (!rules.includes(GenericSqlParser.RULE_tableName) &&
|
|
77
|
+
!rules.includes(GenericSqlParser.RULE_tableNameCreate) &&
|
|
78
|
+
rules.includes(GenericSqlParser.RULE_expression)) {
|
|
79
|
+
syntaxContextType = EntityContextType.COLUMN;
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
71
83
|
default:
|
|
72
84
|
break;
|
|
73
85
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HiveSqlParserListener } from '../../lib';
|
|
2
|
-
import { AtomPartitionedTableFunctionContext, AtomValuesClauseContext, ColumnNameCreateContext, CreateDatabaseStatementContext, CreateFunctionStatementContext, CreateMaterializedViewStatementContext, CreateTableStatementContext, CreateViewStatementContext, DbSchemaNameContext, DbSchemaNameCreateContext, FromInsertStmtContext, FromSelectStmtContext, FunctionNameCreateContext, InsertStmtContext, QueryStatementExpressionContext, SelectExpressionColumnNameContext, SelectListContext, SelectLiteralColumnNameContext, SelectStatementContext, StatementContext, TableAllColumnsContext, TableNameContext, TableNameCreateContext, ViewNameContext, ViewNameCreateContext } from '../../lib/hive/HiveSqlParser';
|
|
2
|
+
import { AtomPartitionedTableFunctionContext, AtomValuesClauseContext, ColumnNameCreateContext, CreateDatabaseStatementContext, CreateFunctionStatementContext, CreateMaterializedViewStatementContext, CreateTableStatementContext, CreateViewStatementContext, CteStatementContext, DbSchemaNameContext, DbSchemaNameCreateContext, FromInsertStmtContext, FromSelectStmtContext, FunctionNameCreateContext, InsertStmtContext, QueryStatementExpressionContext, SelectExpressionColumnNameContext, SelectListContext, SelectLiteralColumnNameContext, SelectStatementContext, StatementContext, TableAllColumnsContext, TableNameContext, TableNameCreateContext, ViewNameContext, ViewNameCreateContext } from '../../lib/hive/HiveSqlParser';
|
|
3
3
|
import { EntityCollector } from '../common/entityCollector';
|
|
4
4
|
export declare class HiveEntityCollector extends EntityCollector implements HiveSqlParserListener {
|
|
5
5
|
/** ====== Entity Begin */
|
|
@@ -19,6 +19,7 @@ export declare class HiveEntityCollector extends EntityCollector implements Hive
|
|
|
19
19
|
exitTableAllColumns(ctx: TableAllColumnsContext): void;
|
|
20
20
|
exitViewNameCreate(ctx: ViewNameCreateContext): void;
|
|
21
21
|
exitSelectList(ctx: SelectListContext): void;
|
|
22
|
+
exitCteStatement(ctx: CteStatementContext): void;
|
|
22
23
|
exitViewName(ctx: ViewNameContext): void;
|
|
23
24
|
exitDbSchemaNameCreate(ctx: DbSchemaNameCreateContext): void;
|
|
24
25
|
exitDbSchemaName(ctx: DbSchemaNameContext): void;
|
|
@@ -116,6 +116,11 @@ export class HiveEntityCollector extends EntityCollector {
|
|
|
116
116
|
exitSelectList(ctx) {
|
|
117
117
|
this.pushEntity(ctx, EntityContextType.QUERY_RESULT);
|
|
118
118
|
}
|
|
119
|
+
exitCteStatement(ctx) {
|
|
120
|
+
var _a, _b, _c, _d;
|
|
121
|
+
const columns = (_b = (_a = ctx.columnNameList()) === null || _a === void 0 ? void 0 : _a.columnName()) !== null && _b !== void 0 ? _b : [];
|
|
122
|
+
this.collectCte(ctx, ctx.id_(), ctx.queryStatementExpression(), (_d = (_c = ctx.stop) === null || _c === void 0 ? void 0 : _c.tokenIndex) !== null && _d !== void 0 ? _d : -1, columns);
|
|
123
|
+
}
|
|
119
124
|
exitViewName(ctx) {
|
|
120
125
|
this.pushEntity(ctx, EntityContextType.VIEW);
|
|
121
126
|
}
|
|
@@ -55,7 +55,7 @@ export class HiveSQL extends BasicSQL {
|
|
|
55
55
|
const keywords = [];
|
|
56
56
|
for (let candidate of candidates.rules) {
|
|
57
57
|
const [ruleType, candidateRule] = candidate;
|
|
58
|
-
const tokenRanges =
|
|
58
|
+
const tokenRanges = this.getCandidateTokenRanges(candidates, candidateRule.startTokenIndex, allTokens, caretTokenIndex);
|
|
59
59
|
let syntaxContextType = void 0;
|
|
60
60
|
switch (ruleType) {
|
|
61
61
|
case HiveSqlParser.RULE_dbSchemaName: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ImpalaSqlParserListener } from '../../lib';
|
|
2
|
-
import { AtomSubQueryTableSourceContext, ColumnNamePathCreateContext, CreateAggregateFunctionContext, CreateFunctionContext, CreateKuduTableAsSelectContext, CreateSchemaContext, CreateTableLikeContext, CreateTableSelectContext, CreateViewContext, DatabaseNameCreateContext, DatabaseNamePathContext, FunctionNameCreateContext, InsertStatementContext, QueryStatementContext, SelectExpressionColumnNameContext, SelectListContext, SelectLiteralColumnNameContext, SingleStatementContext, TableAllColumnsContext, TableNameCreateContext, TableNamePathContext, UnnestContext, ViewNameCreateContext, ViewNamePathContext } from '../../lib/impala/ImpalaSqlParser';
|
|
2
|
+
import { AtomSubQueryTableSourceContext, ColumnNamePathCreateContext, CreateAggregateFunctionContext, CreateFunctionContext, CreateKuduTableAsSelectContext, CreateSchemaContext, CreateTableLikeContext, CreateTableSelectContext, CreateViewContext, DatabaseNameCreateContext, DatabaseNamePathContext, FunctionNameCreateContext, InsertStatementContext, NamedQueryContext, QueryStatementContext, SelectExpressionColumnNameContext, SelectListContext, SelectLiteralColumnNameContext, SingleStatementContext, TableAllColumnsContext, TableNameCreateContext, TableNamePathContext, UnnestContext, ViewNameCreateContext, ViewNamePathContext } from '../../lib/impala/ImpalaSqlParser';
|
|
3
3
|
import { EntityCollector } from '../common/entityCollector';
|
|
4
4
|
export declare class ImpalaEntityCollector extends EntityCollector implements ImpalaSqlParserListener {
|
|
5
5
|
/** ===== Entity begin */
|
|
@@ -9,6 +9,7 @@ export declare class ImpalaEntityCollector extends EntityCollector implements Im
|
|
|
9
9
|
exitUnnest(ctx: UnnestContext): void;
|
|
10
10
|
exitColumnNamePathCreate(ctx: ColumnNamePathCreateContext): void;
|
|
11
11
|
exitViewNameCreate(ctx: ViewNameCreateContext): void;
|
|
12
|
+
exitNamedQuery(ctx: NamedQueryContext): void;
|
|
12
13
|
exitViewNamePath(ctx: ViewNamePathContext): void;
|
|
13
14
|
exitDatabaseNamePath(ctx: DatabaseNamePathContext): void;
|
|
14
15
|
exitDatabaseNameCreate(ctx: DatabaseNameCreateContext): void;
|
|
@@ -72,6 +72,10 @@ export class ImpalaEntityCollector extends EntityCollector {
|
|
|
72
72
|
},
|
|
73
73
|
]);
|
|
74
74
|
}
|
|
75
|
+
exitNamedQuery(ctx) {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
this.collectCte(ctx, ctx.identifier(), ctx.subQueryRelation(), (_b = (_a = ctx.stop) === null || _a === void 0 ? void 0 : _a.tokenIndex) !== null && _b !== void 0 ? _b : -1, [], ctx.columnAliases());
|
|
78
|
+
}
|
|
75
79
|
exitViewNamePath(ctx) {
|
|
76
80
|
this.pushEntity(ctx, EntityContextType.VIEW);
|
|
77
81
|
}
|
|
@@ -54,7 +54,7 @@ export class ImpalaSQL extends BasicSQL {
|
|
|
54
54
|
const keywords = [];
|
|
55
55
|
for (let candidate of candidates.rules) {
|
|
56
56
|
const [ruleType, candidateRule] = candidate;
|
|
57
|
-
const tokenRanges =
|
|
57
|
+
const tokenRanges = this.getCandidateTokenRanges(candidates, candidateRule.startTokenIndex, allTokens, caretTokenIndex);
|
|
58
58
|
let syntaxContextType = void 0;
|
|
59
59
|
switch (ruleType) {
|
|
60
60
|
case ImpalaSqlParser.RULE_functionNameCreate: {
|
|
@@ -8,6 +8,13 @@ import { MysqlErrorListener } from './mysqlErrorListener';
|
|
|
8
8
|
import { MysqlSplitListener } from './mysqlSplitListener';
|
|
9
9
|
import { MySqlSemanticContextCollector } from '../mysql/mysqlSemanticContextCollector';
|
|
10
10
|
export { MySqlEntityCollector, MysqlSplitListener };
|
|
11
|
+
const ALLOW_EMPTY_COLUMN_PARENT_RULES = new Set([
|
|
12
|
+
MySqlParser.RULE_joinSpec,
|
|
13
|
+
MySqlParser.RULE_fromClause,
|
|
14
|
+
MySqlParser.RULE_orderByExpression,
|
|
15
|
+
MySqlParser.RULE_groupByItem,
|
|
16
|
+
MySqlParser.RULE_havingClause,
|
|
17
|
+
]);
|
|
11
18
|
export class MySQL extends BasicSQL {
|
|
12
19
|
constructor() {
|
|
13
20
|
super(...arguments);
|
|
@@ -26,6 +33,7 @@ export class MySQL extends BasicSQL {
|
|
|
26
33
|
MySqlParser.RULE_functionNameCreate,
|
|
27
34
|
MySqlParser.RULE_columnName,
|
|
28
35
|
MySqlParser.RULE_columnNamePath,
|
|
36
|
+
MySqlParser.RULE_columnNamePathAllowEmpty,
|
|
29
37
|
MySqlParser.RULE_columnNameCreate,
|
|
30
38
|
...this.excludeKeywordRules,
|
|
31
39
|
]);
|
|
@@ -54,7 +62,7 @@ export class MySQL extends BasicSQL {
|
|
|
54
62
|
const keywords = [];
|
|
55
63
|
for (const candidate of candidates.rules) {
|
|
56
64
|
const [ruleType, candidateRule] = candidate;
|
|
57
|
-
const tokenRanges =
|
|
65
|
+
const tokenRanges = this.getCandidateTokenRanges(candidates, candidateRule.startTokenIndex, allTokens, caretTokenIndex);
|
|
58
66
|
let syntaxContextType = void 0;
|
|
59
67
|
switch (ruleType) {
|
|
60
68
|
case MySqlParser.RULE_databaseName: {
|
|
@@ -94,6 +102,12 @@ export class MySQL extends BasicSQL {
|
|
|
94
102
|
syntaxContextType = EntityContextType.COLUMN;
|
|
95
103
|
break;
|
|
96
104
|
}
|
|
105
|
+
case MySqlParser.RULE_columnNamePathAllowEmpty: {
|
|
106
|
+
if (candidateRule.ruleList.some((rule) => ALLOW_EMPTY_COLUMN_PARENT_RULES.has(rule))) {
|
|
107
|
+
syntaxContextType = EntityContextType.COLUMN;
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
97
111
|
case MySqlParser.RULE_columnNameCreate: {
|
|
98
112
|
syntaxContextType = EntityContextType.COLUMN_CREATE;
|
|
99
113
|
break;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColumnCreateTableContext, ColumnNameCreateContext, CopyCreateTableContext, CreateDatabaseContext, CreateFunctionContext, CreateFunctionLoadableContext, CreateViewContext, DatabaseNameContext, DatabaseNameCreateContext, FunctionNameCreateContext, InsertStatementContext, QueryCreateTableContext, SelectElementsContext, SelectExpressionElementContext, SelectLiteralColumnNameContext, SelectStatementContext, SingleStatementContext, TableNameContext, TableNameCreateContext, ViewNameContext, ViewNameCreateContext, TableAllColumnsContext, AtomSubQueryTableSourceContext, PureAllColumnsContext, SelectElement_dot_emptyContext } from '../../lib/mysql/MySqlParser';
|
|
1
|
+
import { ColumnCreateTableContext, ColumnNameCreateContext, CopyCreateTableContext, CreateDatabaseContext, CreateFunctionContext, CreateFunctionLoadableContext, CreateViewContext, DatabaseNameContext, DatabaseNameCreateContext, FunctionNameCreateContext, InsertStatementContext, QueryCreateTableContext, SelectElementsContext, SelectExpressionElementContext, SelectLiteralColumnNameContext, SelectStatementContext, SingleStatementContext, TableNameContext, TableNameCreateContext, ViewNameContext, ViewNameCreateContext, TableAllColumnsContext, AtomSubQueryTableSourceContext, CommonTableExpressionsContext, PureAllColumnsContext, SelectElement_dot_emptyContext, ColumnNamePath_dot_emptyContext } from '../../lib/mysql/MySqlParser';
|
|
2
2
|
import type { MySqlParserListener } from '../../lib/mysql/MySqlParserListener';
|
|
3
3
|
import { EntityCollector } from '../common/entityCollector';
|
|
4
4
|
export declare class MySqlEntityCollector extends EntityCollector implements MySqlParserListener {
|
|
@@ -7,6 +7,7 @@ export declare class MySqlEntityCollector extends EntityCollector implements MyS
|
|
|
7
7
|
exitDatabaseNameCreate(ctx: DatabaseNameCreateContext): void;
|
|
8
8
|
/** Table Entity Rules */
|
|
9
9
|
exitTableName(ctx: TableNameContext): void;
|
|
10
|
+
exitCommonTableExpressions(ctx: CommonTableExpressionsContext): void;
|
|
10
11
|
/** SubQuery Table Entity Rules */
|
|
11
12
|
exitAtomSubQueryTableSource(ctx: AtomSubQueryTableSourceContext): void;
|
|
12
13
|
exitTableNameCreate(ctx: TableNameCreateContext): void;
|
|
@@ -19,6 +20,7 @@ export declare class MySqlEntityCollector extends EntityCollector implements MyS
|
|
|
19
20
|
exitPureAllColumns(ctx: PureAllColumnsContext): void;
|
|
20
21
|
exitSelectLiteralColumnName(ctx: SelectLiteralColumnNameContext): void;
|
|
21
22
|
exitSelectElement_dot_empty(ctx: SelectElement_dot_emptyContext): void;
|
|
23
|
+
exitColumnNamePath_dot_empty(ctx: ColumnNamePath_dot_emptyContext): void;
|
|
22
24
|
exitSelectExpressionElement(ctx: SelectExpressionElementContext): void;
|
|
23
25
|
/** ===== Statement begin */
|
|
24
26
|
enterSingleStatement(ctx: SingleStatementContext): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TerminalNode } from 'antlr4ng';
|
|
1
2
|
import { ColumnCreateTableContext, CreateDefinitionContext, CreateFunctionContext, TableSourceItemContext, AtomTableItemContext, SubqueryTableItemContext, SelectElement_labelContext, SelectElement_exprContext, } from '../../lib/mysql/MySqlParser';
|
|
2
3
|
import { AttrName, ColumnDeclareType, EntityCollector, StmtContextType, TableDeclareType, } from '../common/entityCollector';
|
|
3
4
|
import { EntityContextType } from '../common/types';
|
|
@@ -20,6 +21,24 @@ export class MySqlEntityCollector extends EntityCollector {
|
|
|
20
21
|
declareType: TableDeclareType.LITERAL,
|
|
21
22
|
});
|
|
22
23
|
}
|
|
24
|
+
exitCommonTableExpressions(ctx) {
|
|
25
|
+
var _a, _b, _c;
|
|
26
|
+
const names = ctx.uid();
|
|
27
|
+
if (!(names === null || names === void 0 ? void 0 : names.length))
|
|
28
|
+
return;
|
|
29
|
+
const bodyEnd = (_c = (_b = (_a = ctx.dmlStatement()) === null || _a === void 0 ? void 0 : _a.stop) === null || _b === void 0 ? void 0 : _b.tokenIndex) !== null && _c !== void 0 ? _c : -1;
|
|
30
|
+
let endTokenIndex = bodyEnd;
|
|
31
|
+
for (let i = 0; i < ctx.getChildCount(); i++) {
|
|
32
|
+
const child = ctx.getChild(i);
|
|
33
|
+
if (!(child instanceof TerminalNode))
|
|
34
|
+
continue;
|
|
35
|
+
if (child.symbol.text === ')' && child.symbol.tokenIndex > bodyEnd) {
|
|
36
|
+
endTokenIndex = child.symbol.tokenIndex;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
this.collectCte(ctx, names[0], ctx.dmlStatement(), endTokenIndex, names.slice(1));
|
|
41
|
+
}
|
|
23
42
|
/** SubQuery Table Entity Rules */
|
|
24
43
|
exitAtomSubQueryTableSource(ctx) {
|
|
25
44
|
this.pushEntity(ctx, EntityContextType.TABLE, [
|
|
@@ -98,6 +117,11 @@ export class MySqlEntityCollector extends EntityCollector {
|
|
|
98
117
|
declareType: ColumnDeclareType.LITERAL,
|
|
99
118
|
});
|
|
100
119
|
}
|
|
120
|
+
exitColumnNamePath_dot_empty(ctx) {
|
|
121
|
+
this.pushEntity(ctx, EntityContextType.COLUMN, [], {
|
|
122
|
+
declareType: ColumnDeclareType.LITERAL,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
101
125
|
exitSelectExpressionElement(ctx) {
|
|
102
126
|
this.pushEntity(ctx, EntityContextType.COLUMN, [
|
|
103
127
|
{
|
|
@@ -64,7 +64,7 @@ export class PostgreSQL extends BasicSQL {
|
|
|
64
64
|
const keywords = [];
|
|
65
65
|
for (let candidate of candidates.rules) {
|
|
66
66
|
const [ruleType, candidateRule] = candidate;
|
|
67
|
-
const tokenRanges =
|
|
67
|
+
const tokenRanges = this.getCandidateTokenRanges(candidates, candidateRule.startTokenIndex, allTokens, caretTokenIndex);
|
|
68
68
|
let syntaxContextType = void 0;
|
|
69
69
|
switch (ruleType) {
|
|
70
70
|
case PostgreSqlParser.RULE_tableNameCreate: {
|
|
@@ -130,7 +130,8 @@ export class PostgreSQL extends BasicSQL {
|
|
|
130
130
|
candidateRule.ruleList.includes(PostgreSqlParser.RULE_whereClause) ||
|
|
131
131
|
candidateRule.ruleList.includes(PostgreSqlParser.RULE_havingClause) ||
|
|
132
132
|
candidateRule.ruleList.includes(PostgreSqlParser.RULE_windowClause) ||
|
|
133
|
-
candidateRule.ruleList.includes(PostgreSqlParser.RULE_triggerWhen)
|
|
133
|
+
candidateRule.ruleList.includes(PostgreSqlParser.RULE_triggerWhen) ||
|
|
134
|
+
candidateRule.ruleList.includes(PostgreSqlParser.RULE_joinQual)) {
|
|
134
135
|
syntaxContextType = EntityContextType.COLUMN;
|
|
135
136
|
}
|
|
136
137
|
break;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AlterTableStmtContext, type ColumnCreateTableContext, type ColumnNameCreateContext, type CreateDatabaseContext, type CreateForeignTableContext, type CreateFunctionStmtContext, type CreateMaterializedViewContext, type CreatePartitionForeignTableContext, type CreateViewContext, type DatabaseNameContext, type DatabaseNameCreateContext, FuncTableContext, type FunctionNameCreateContext, type InsertStatementContext, type ProcedureNameContext, type ProcedureNameCreateContext, type QueryCreateTableContext, SelectExpressionColumnNameContext, SelectLiteralColumnNameContext, SelectNoParensContext, type SelectStatementContext, SelectWithParensContext, type SingleStmtContext, TableAllColumnsContext, type TableNameContext, type TableNameCreateContext, Target_dot_emptyContext, Target_emptyContext, TargetListContext, type ViewNameContext, type ViewNameCreateContext, XmlTableContext } from '../../lib/postgresql/PostgreSqlParser';
|
|
1
|
+
import { type AlterTableStmtContext, type ColumnCreateTableContext, type CommonTableExprContext, type ColumnNameCreateContext, type CreateDatabaseContext, type CreateForeignTableContext, type CreateFunctionStmtContext, type CreateMaterializedViewContext, type CreatePartitionForeignTableContext, type CreateViewContext, type DatabaseNameContext, type DatabaseNameCreateContext, FuncTableContext, type FunctionNameCreateContext, type InsertStatementContext, type ProcedureNameContext, type ProcedureNameCreateContext, type QueryCreateTableContext, SelectExpressionColumnNameContext, SelectLiteralColumnNameContext, SelectNoParensContext, type SelectStatementContext, SelectWithParensContext, type SingleStmtContext, TableAllColumnsContext, type TableNameContext, type TableNameCreateContext, Target_dot_emptyContext, Target_emptyContext, ColumnNamePath_dot_emptyContext, TargetListContext, type ViewNameContext, type ViewNameCreateContext, XmlTableContext } from '../../lib/postgresql/PostgreSqlParser';
|
|
2
2
|
import type { PostgreSqlParserListener } from '../../lib/postgresql/PostgreSqlParserListener';
|
|
3
3
|
import { EntityCollector } from '../common/entityCollector';
|
|
4
4
|
export declare class PostgreSqlEntityCollector extends EntityCollector implements PostgreSqlParserListener {
|
|
@@ -10,6 +10,7 @@ export declare class PostgreSqlEntityCollector extends EntityCollector implement
|
|
|
10
10
|
exitFuncTable(ctx: FuncTableContext): void;
|
|
11
11
|
exitSelectWithParens(ctx: SelectWithParensContext): void;
|
|
12
12
|
exitTableNameCreate(ctx: TableNameCreateContext): void;
|
|
13
|
+
exitCommonTableExpr(ctx: CommonTableExprContext): void;
|
|
13
14
|
exitViewName(ctx: ViewNameContext): void;
|
|
14
15
|
exitViewNameCreate(ctx: ViewNameCreateContext): void;
|
|
15
16
|
exitFunctionNameCreate(ctx: FunctionNameCreateContext): void;
|
|
@@ -18,6 +19,7 @@ export declare class PostgreSqlEntityCollector extends EntityCollector implement
|
|
|
18
19
|
exitTableAllColumns(ctx: TableAllColumnsContext): void;
|
|
19
20
|
exitTarget_empty(ctx: Target_emptyContext): void;
|
|
20
21
|
exitTarget_dot_empty(ctx: Target_dot_emptyContext): void;
|
|
22
|
+
exitColumnNamePath_dot_empty(ctx: ColumnNamePath_dot_emptyContext): void;
|
|
21
23
|
exitSelectExpressionColumnName(ctx: SelectExpressionColumnNameContext): void;
|
|
22
24
|
exitSelectLiteralColumnName(ctx: SelectLiteralColumnNameContext): void;
|
|
23
25
|
exitProcedureName(ctx: ProcedureNameContext): void;
|
|
@@ -54,6 +54,11 @@ export class PostgreSqlEntityCollector extends EntityCollector {
|
|
|
54
54
|
exitTableNameCreate(ctx) {
|
|
55
55
|
this.pushEntity(ctx, EntityContextType.TABLE_CREATE);
|
|
56
56
|
}
|
|
57
|
+
exitCommonTableExpr(ctx) {
|
|
58
|
+
var _a, _b, _c, _d, _e;
|
|
59
|
+
const columns = (_c = (_b = (_a = ctx.optColumnList()) === null || _a === void 0 ? void 0 : _a.columnList()) === null || _b === void 0 ? void 0 : _b.columnName()) !== null && _c !== void 0 ? _c : [];
|
|
60
|
+
this.collectCte(ctx, ctx.colId(), ctx.preParableStmt(), (_e = (_d = ctx.stop) === null || _d === void 0 ? void 0 : _d.tokenIndex) !== null && _e !== void 0 ? _e : -1, columns);
|
|
61
|
+
}
|
|
57
62
|
exitViewName(ctx) {
|
|
58
63
|
this.pushEntity(ctx, EntityContextType.VIEW, [
|
|
59
64
|
{
|
|
@@ -105,6 +110,11 @@ export class PostgreSqlEntityCollector extends EntityCollector {
|
|
|
105
110
|
declareType: ColumnDeclareType.LITERAL,
|
|
106
111
|
});
|
|
107
112
|
}
|
|
113
|
+
exitColumnNamePath_dot_empty(ctx) {
|
|
114
|
+
this.pushEntity(ctx, EntityContextType.COLUMN, [], {
|
|
115
|
+
declareType: ColumnDeclareType.LITERAL,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
108
118
|
exitSelectExpressionColumnName(ctx) {
|
|
109
119
|
this.pushEntity(ctx, EntityContextType.COLUMN, [
|
|
110
120
|
{
|
|
@@ -59,7 +59,7 @@ export class SparkSQL extends BasicSQL {
|
|
|
59
59
|
const keywords = [];
|
|
60
60
|
for (const candidate of candidates.rules) {
|
|
61
61
|
const [ruleType, candidateRule] = candidate;
|
|
62
|
-
const tokenRanges =
|
|
62
|
+
const tokenRanges = this.getCandidateTokenRanges(candidates, candidateRule.startTokenIndex, allTokens, caretTokenIndex);
|
|
63
63
|
let syntaxContextType = void 0;
|
|
64
64
|
switch (ruleType) {
|
|
65
65
|
case SparkSqlParser.RULE_namespaceName: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AtomSubQueryTableSourceContext, ColumnNameCreateContext, CreateFunctionContext, CreateNamespaceContext, CreateTableContext, CreateTableLikeContext, CreateTempViewUsingContext, CreateViewContext, FunctionNameCreateContext, FunctionTableSourceContext, InlineTableSourceContext, InsertFromQueryContext, MultipleInsertContext, NamespaceNameContext, NamespaceNameCreateContext, QueryStatementContext, ReplaceTableContext, SelectExpressionColumnNameContext, SelectListContext, SelectLiteralColumnNameContext, SingleStatementContext, TableAllColumnsContext, TableNameContext, TableNameCreateContext, ViewNameContext, ViewNameCreateContext } from '../../lib/spark/SparkSqlParser';
|
|
1
|
+
import { AtomSubQueryTableSourceContext, ColumnNameCreateContext, CreateFunctionContext, CreateNamespaceContext, CreateTableContext, CreateTableLikeContext, CreateTempViewUsingContext, CreateViewContext, FunctionNameCreateContext, FunctionTableSourceContext, InlineTableSourceContext, InsertFromQueryContext, MultipleInsertContext, NamedQueryContext, NamespaceNameContext, NamespaceNameCreateContext, QueryStatementContext, ReplaceTableContext, SelectExpressionColumnNameContext, SelectListContext, SelectLiteralColumnNameContext, SingleStatementContext, TableAllColumnsContext, TableNameContext, TableNameCreateContext, ViewNameContext, ViewNameCreateContext } from '../../lib/spark/SparkSqlParser';
|
|
2
2
|
import type { SparkSqlParserListener } from '../../lib/spark/SparkSqlParserListener';
|
|
3
3
|
import { EntityCollector } from '../common/entityCollector';
|
|
4
4
|
export declare class SparkEntityCollector extends EntityCollector implements SparkSqlParserListener {
|
|
@@ -14,6 +14,7 @@ export declare class SparkEntityCollector extends EntityCollector implements Spa
|
|
|
14
14
|
/** SubQuery Table Entity Rules */
|
|
15
15
|
exitAtomSubQueryTableSource(ctx: AtomSubQueryTableSourceContext): void;
|
|
16
16
|
exitTableNameCreate(ctx: TableNameCreateContext): void;
|
|
17
|
+
exitNamedQuery(ctx: NamedQueryContext): void;
|
|
17
18
|
exitViewName(ctx: ViewNameContext): void;
|
|
18
19
|
exitSelectList(ctx: SelectListContext): void;
|
|
19
20
|
exitViewNameCreate(ctx: ViewNameCreateContext): void;
|
|
@@ -70,6 +70,11 @@ export class SparkEntityCollector extends EntityCollector {
|
|
|
70
70
|
},
|
|
71
71
|
]);
|
|
72
72
|
}
|
|
73
|
+
exitNamedQuery(ctx) {
|
|
74
|
+
var _a, _b, _c, _d, _e;
|
|
75
|
+
const columns = (_c = (_b = (_a = ctx.identifierList()) === null || _a === void 0 ? void 0 : _a.identifierSeq()) === null || _b === void 0 ? void 0 : _b.errorCapturingIdentifier()) !== null && _c !== void 0 ? _c : [];
|
|
76
|
+
this.collectCte(ctx, ctx.errorCapturingIdentifier(), ctx.query(), (_e = (_d = ctx.stop) === null || _d === void 0 ? void 0 : _d.tokenIndex) !== null && _e !== void 0 ? _e : -1, columns);
|
|
77
|
+
}
|
|
73
78
|
exitViewName(ctx) {
|
|
74
79
|
this.pushEntity(ctx, EntityContextType.VIEW);
|
|
75
80
|
}
|
|
@@ -56,7 +56,7 @@ export class TrinoSQL extends BasicSQL {
|
|
|
56
56
|
const keywords = [];
|
|
57
57
|
for (let candidate of candidates.rules) {
|
|
58
58
|
const [ruleType, candidateRule] = candidate;
|
|
59
|
-
const tokenRanges =
|
|
59
|
+
const tokenRanges = this.getCandidateTokenRanges(candidates, candidateRule.startTokenIndex, allTokens, caretTokenIndex);
|
|
60
60
|
let syntaxContextType = void 0;
|
|
61
61
|
switch (ruleType) {
|
|
62
62
|
case TrinoSqlParser.RULE_catalogRef: {
|
|
@@ -115,9 +115,11 @@ export class TrinoSQL extends BasicSQL {
|
|
|
115
115
|
candidateRule.ruleList.includes(TrinoSqlParser.RULE_havingClause) ||
|
|
116
116
|
candidateRule.ruleList.includes(TrinoSqlParser.RULE_partitionBy) ||
|
|
117
117
|
candidateRule.ruleList.includes(TrinoSqlParser.RULE_whenClause) ||
|
|
118
|
-
candidateRule.ruleList.includes(TrinoSqlParser.RULE_relation)
|
|
118
|
+
candidateRule.ruleList.includes(TrinoSqlParser.RULE_relation) ||
|
|
119
|
+
candidateRule.ruleList.includes(TrinoSqlParser.RULE_joinCriteria)) {
|
|
119
120
|
syntaxContextType = EntityContextType.COLUMN;
|
|
120
121
|
}
|
|
122
|
+
break;
|
|
121
123
|
}
|
|
122
124
|
default:
|
|
123
125
|
break;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TrinoSqlListener } from '../../lib/trino/TrinoSqlListener';
|
|
2
|
-
import { CatalogNameCreateContext, CatalogRefContext, ColumnNameCreateContext, CreateMaterializedViewContext, CreateSchemaContext, CreateTableAsSelectContext, CreateTableContext, CreateViewContext, ExpressionSourceTableContext, InsertIntoContext, QueryStatementContext, SchemaNameCreateContext, SchemaRefContext, SelectAllWithoutTableContext, SelectExpressionColumnNameContext, SelectListContext, SelectLiteralColumnNameContext, SingleStatementContext, TableAllColumnsContext, TableNameCreateContext, TableRefContext, ViewNameCreateContext, ViewRefContext } from '../../lib/trino/TrinoSqlParser';
|
|
2
|
+
import { CatalogNameCreateContext, CatalogRefContext, ColumnNameCreateContext, CreateMaterializedViewContext, CreateSchemaContext, CreateTableAsSelectContext, CreateTableContext, CreateViewContext, ExpressionSourceTableContext, InsertIntoContext, NamedQueryContext, QueryStatementContext, SchemaNameCreateContext, SchemaRefContext, SelectAllWithoutTableContext, SelectExpressionColumnNameContext, SelectListContext, SelectLiteralColumnNameContext, SingleStatementContext, TableAllColumnsContext, TableNameCreateContext, TableRefContext, ViewNameCreateContext, ViewRefContext } from '../../lib/trino/TrinoSqlParser';
|
|
3
3
|
import { EntityCollector } from '../common/entityCollector';
|
|
4
4
|
export declare class TrinoEntityCollector extends EntityCollector implements TrinoSqlListener {
|
|
5
5
|
/** ====== Entity Begin */
|
|
@@ -10,6 +10,7 @@ export declare class TrinoEntityCollector extends EntityCollector implements Tri
|
|
|
10
10
|
exitTableRef(ctx: TableRefContext): void;
|
|
11
11
|
exitExpressionSourceTable(ctx: ExpressionSourceTableContext): void;
|
|
12
12
|
exitTableNameCreate(ctx: TableNameCreateContext): void;
|
|
13
|
+
exitNamedQuery(ctx: NamedQueryContext): void;
|
|
13
14
|
exitViewRef(ctx: ViewRefContext): void;
|
|
14
15
|
exitViewNameCreate(ctx: ViewNameCreateContext): void;
|
|
15
16
|
exitSelectList(ctx: SelectListContext): void;
|
|
@@ -43,6 +43,11 @@ export class TrinoEntityCollector extends EntityCollector {
|
|
|
43
43
|
},
|
|
44
44
|
]);
|
|
45
45
|
}
|
|
46
|
+
exitNamedQuery(ctx) {
|
|
47
|
+
var _a, _b, _c, _d;
|
|
48
|
+
const columns = (_b = (_a = ctx.columnAliases()) === null || _a === void 0 ? void 0 : _a.identifier()) !== null && _b !== void 0 ? _b : [];
|
|
49
|
+
this.collectCte(ctx, ctx.identifier(), ctx.query(), (_d = (_c = ctx.stop) === null || _c === void 0 ? void 0 : _c.tokenIndex) !== null && _d !== void 0 ? _d : -1, columns);
|
|
50
|
+
}
|
|
46
51
|
exitViewRef(ctx) {
|
|
47
52
|
this.pushEntity(ctx, EntityContextType.VIEW);
|
|
48
53
|
}
|