dt-sql-parser 4.0.3-beta.0 → 4.0.3-beta.1
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/index.d.ts +1 -1
- package/dist/lib/flink/FlinkSqlParser.d.ts +168 -171
- package/dist/lib/flink/FlinkSqlParser.js +2341 -2426
- package/dist/lib/flink/FlinkSqlParserListener.d.ts +0 -11
- package/dist/lib/flink/FlinkSqlParserVisitor.d.ts +0 -7
- package/dist/lib/hive/HiveSqlParser.d.ts +5 -1
- package/dist/lib/hive/HiveSqlParser.js +145 -130
- package/dist/lib/impala/ImpalaSqlParser.d.ts +121 -105
- package/dist/lib/impala/ImpalaSqlParser.js +3303 -3225
- package/dist/lib/impala/ImpalaSqlParserListener.d.ts +22 -0
- package/dist/lib/impala/ImpalaSqlParserVisitor.d.ts +14 -0
- package/dist/lib/mysql/MySqlParser.d.ts +4 -0
- package/dist/lib/mysql/MySqlParser.js +4 -4
- package/dist/lib/postgresql/PostgreSqlParser.d.ts +3 -0
- package/dist/lib/postgresql/PostgreSqlParser.js +1500 -1492
- package/dist/lib/spark/SparkSqlParser.d.ts +16 -13
- package/dist/lib/spark/SparkSqlParser.js +49 -49
- package/dist/lib/spark/SparkSqlParserListener.d.ts +10 -10
- package/dist/lib/spark/SparkSqlParserVisitor.d.ts +6 -6
- package/dist/lib/trino/TrinoSqlParser.d.ts +13 -5
- package/dist/lib/trino/TrinoSqlParser.js +23 -23
- package/dist/locale/locale.d.ts +41 -0
- package/dist/locale/locale.js +43 -0
- package/dist/parser/common/basicSQL.d.ts +7 -2
- package/dist/parser/common/basicSQL.js +5 -5
- package/dist/parser/common/entityCollector.d.ts +58 -11
- package/dist/parser/common/entityCollector.js +140 -17
- package/dist/parser/common/parseErrorListener.d.ts +6 -3
- package/dist/parser/common/parseErrorListener.js +83 -2
- package/dist/parser/common/textAndWord.d.ts +6 -9
- package/dist/parser/common/textAndWord.js +9 -20
- package/dist/parser/common/transform.d.ts +8 -0
- package/dist/parser/common/transform.js +11 -0
- package/dist/parser/common/types.d.ts +1 -0
- package/dist/parser/flink/flinkEntityCollector.js +40 -6
- package/dist/parser/flink/flinkErrorListener.d.ts +9 -0
- package/dist/parser/flink/flinkErrorListener.js +67 -0
- package/dist/parser/flink/index.d.ts +3 -0
- package/dist/parser/flink/index.js +4 -0
- package/dist/parser/hive/hiveEntityCollector.js +40 -6
- package/dist/parser/hive/hiveErrorListener.d.ts +9 -0
- package/dist/parser/hive/hiveErrorListener.js +65 -0
- package/dist/parser/hive/index.d.ts +3 -0
- package/dist/parser/hive/index.js +4 -0
- package/dist/parser/impala/ImpalaErrorListener.d.ts +9 -0
- package/dist/parser/impala/ImpalaErrorListener.js +63 -0
- package/dist/parser/impala/impalaEntityCollector.js +51 -6
- package/dist/parser/impala/index.d.ts +3 -0
- package/dist/parser/impala/index.js +4 -0
- package/dist/parser/mysql/index.d.ts +3 -0
- package/dist/parser/mysql/index.js +4 -0
- package/dist/parser/mysql/mysqlEntityCollector.d.ts +1 -1
- package/dist/parser/mysql/mysqlEntityCollector.js +34 -5
- package/dist/parser/mysql/mysqlErrorListener.d.ts +9 -0
- package/dist/parser/mysql/mysqlErrorListener.js +63 -0
- package/dist/parser/postgresql/index.d.ts +3 -0
- package/dist/parser/postgresql/index.js +4 -0
- package/dist/parser/postgresql/postgreEntityCollector.d.ts +3 -1
- package/dist/parser/postgresql/postgreEntityCollector.js +38 -4
- package/dist/parser/postgresql/postgreErrorListener.d.ts +9 -0
- package/dist/parser/postgresql/postgreErrorListener.js +71 -0
- package/dist/parser/spark/index.d.ts +3 -0
- package/dist/parser/spark/index.js +4 -0
- package/dist/parser/spark/sparkEntityCollector.d.ts +1 -1
- package/dist/parser/spark/sparkEntityCollector.js +43 -6
- package/dist/parser/spark/sparkErrorListener.d.ts +9 -0
- package/dist/parser/spark/sparkErrorListener.js +63 -0
- package/dist/parser/trino/index.d.ts +3 -0
- package/dist/parser/trino/index.js +4 -0
- package/dist/parser/trino/trinoEntityCollector.d.ts +1 -1
- package/dist/parser/trino/trinoEntityCollector.js +34 -5
- package/dist/parser/trino/trinoErrorListener.d.ts +9 -0
- package/dist/parser/trino/trinoErrorListener.js +65 -0
- package/package.json +5 -3
|
@@ -1,18 +1,58 @@
|
|
|
1
|
+
import { ColumnDefinitionContext, CreateKuduTableAsSelectContext, CreateSchemaContext, CreateTableSelectContext, CreateViewContext, KuduTableElementContext, SampledRelationContext, ViewColumnItemContext, } from '../../lib/impala/ImpalaSqlParser';
|
|
2
|
+
import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector';
|
|
1
3
|
import { EntityContextType } from '../common/types';
|
|
2
|
-
import { StmtContextType, EntityCollector } from '../common/entityCollector';
|
|
3
4
|
export class ImpalaEntityCollector extends EntityCollector {
|
|
4
5
|
/** ===== Entity begin */
|
|
5
6
|
exitTableNameCreate(ctx) {
|
|
6
|
-
this.pushEntity(ctx, EntityContextType.TABLE_CREATE
|
|
7
|
+
this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [
|
|
8
|
+
{
|
|
9
|
+
attrName: AttrName.comment,
|
|
10
|
+
endContextList: [
|
|
11
|
+
CreateTableSelectContext.name,
|
|
12
|
+
CreateKuduTableAsSelectContext.name,
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
]);
|
|
7
16
|
}
|
|
8
17
|
exitTableNamePath(ctx) {
|
|
9
|
-
|
|
18
|
+
var _a;
|
|
19
|
+
const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT;
|
|
20
|
+
this.pushEntity(ctx, EntityContextType.TABLE, needCollectAttr
|
|
21
|
+
? [
|
|
22
|
+
{
|
|
23
|
+
attrName: AttrName.alias,
|
|
24
|
+
endContextList: [SampledRelationContext.name],
|
|
25
|
+
},
|
|
26
|
+
]
|
|
27
|
+
: undefined);
|
|
10
28
|
}
|
|
11
29
|
exitColumnNamePathCreate(ctx) {
|
|
12
|
-
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE
|
|
30
|
+
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [
|
|
31
|
+
{
|
|
32
|
+
attrName: AttrName.comment,
|
|
33
|
+
endContextList: [
|
|
34
|
+
ColumnDefinitionContext.name,
|
|
35
|
+
KuduTableElementContext.name,
|
|
36
|
+
ViewColumnItemContext.name,
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
attrName: AttrName.colType,
|
|
41
|
+
endContextList: [
|
|
42
|
+
ColumnDefinitionContext.name,
|
|
43
|
+
KuduTableElementContext.name,
|
|
44
|
+
ViewColumnItemContext.name,
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
13
48
|
}
|
|
14
49
|
exitViewNameCreate(ctx) {
|
|
15
|
-
this.pushEntity(ctx, EntityContextType.VIEW_CREATE
|
|
50
|
+
this.pushEntity(ctx, EntityContextType.VIEW_CREATE, [
|
|
51
|
+
{
|
|
52
|
+
attrName: AttrName.comment,
|
|
53
|
+
endContextList: [CreateViewContext.name],
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
16
56
|
}
|
|
17
57
|
exitViewNamePath(ctx) {
|
|
18
58
|
this.pushEntity(ctx, EntityContextType.VIEW);
|
|
@@ -21,7 +61,12 @@ export class ImpalaEntityCollector extends EntityCollector {
|
|
|
21
61
|
this.pushEntity(ctx, EntityContextType.DATABASE);
|
|
22
62
|
}
|
|
23
63
|
exitDatabaseNameCreate(ctx) {
|
|
24
|
-
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE
|
|
64
|
+
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE, [
|
|
65
|
+
{
|
|
66
|
+
attrName: AttrName.comment,
|
|
67
|
+
endContextList: [CreateSchemaContext.name],
|
|
68
|
+
},
|
|
69
|
+
]);
|
|
25
70
|
}
|
|
26
71
|
exitFunctionNameCreate(ctx) {
|
|
27
72
|
this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE);
|
|
@@ -6,12 +6,15 @@ import { BasicSQL } from '../common/basicSQL';
|
|
|
6
6
|
import { Suggestions } from '../common/types';
|
|
7
7
|
import { ImpalaSqlSplitListener } from './impalaSplitListener';
|
|
8
8
|
import { ImpalaEntityCollector } from './impalaEntityCollector';
|
|
9
|
+
import { ErrorListener } from '../common/parseErrorListener';
|
|
10
|
+
import { ImpalaErrorListener } from './ImpalaErrorListener';
|
|
9
11
|
export { ImpalaEntityCollector, ImpalaSqlSplitListener };
|
|
10
12
|
export declare class ImpalaSQL extends BasicSQL<ImpalaSqlLexer, ProgramContext, ImpalaSqlParser> {
|
|
11
13
|
protected createLexerFromCharStream(charStreams: CharStream): ImpalaSqlLexer;
|
|
12
14
|
protected createParserFromTokenStream(tokenStream: CommonTokenStream): ImpalaSqlParser;
|
|
13
15
|
protected preferredRules: Set<number>;
|
|
14
16
|
protected get splitListener(): ImpalaSqlSplitListener;
|
|
17
|
+
protected createErrorListener(_errorListener: ErrorListener): ImpalaErrorListener;
|
|
15
18
|
protected createEntityCollector(input: string, caretTokenIndex?: number): ImpalaEntityCollector;
|
|
16
19
|
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
17
20
|
}
|
|
@@ -4,6 +4,7 @@ import { BasicSQL } from '../common/basicSQL';
|
|
|
4
4
|
import { EntityContextType } from '../common/types';
|
|
5
5
|
import { ImpalaSqlSplitListener } from './impalaSplitListener';
|
|
6
6
|
import { ImpalaEntityCollector } from './impalaEntityCollector';
|
|
7
|
+
import { ImpalaErrorListener } from './ImpalaErrorListener';
|
|
7
8
|
export { ImpalaEntityCollector, ImpalaSqlSplitListener };
|
|
8
9
|
export class ImpalaSQL extends BasicSQL {
|
|
9
10
|
constructor() {
|
|
@@ -30,6 +31,9 @@ export class ImpalaSQL extends BasicSQL {
|
|
|
30
31
|
get splitListener() {
|
|
31
32
|
return new ImpalaSqlSplitListener();
|
|
32
33
|
}
|
|
34
|
+
createErrorListener(_errorListener) {
|
|
35
|
+
return new ImpalaErrorListener(_errorListener, this.preferredRules, this.locale);
|
|
36
|
+
}
|
|
33
37
|
createEntityCollector(input, caretTokenIndex) {
|
|
34
38
|
return new ImpalaEntityCollector(input, caretTokenIndex);
|
|
35
39
|
}
|
|
@@ -6,12 +6,15 @@ import { BasicSQL } from '../common/basicSQL';
|
|
|
6
6
|
import { Suggestions } from '../common/types';
|
|
7
7
|
import { MysqlSplitListener } from './mysqlSplitListener';
|
|
8
8
|
import { MySqlEntityCollector } from './mysqlEntityCollector';
|
|
9
|
+
import { MysqlErrorListener } from './mysqlErrorListener';
|
|
10
|
+
import { ErrorListener } from '../common/parseErrorListener';
|
|
9
11
|
export { MySqlEntityCollector, MysqlSplitListener };
|
|
10
12
|
export declare class MySQL extends BasicSQL<MySqlLexer, ProgramContext, MySqlParser> {
|
|
11
13
|
protected createLexerFromCharStream(charStreams: CharStream): MySqlLexer;
|
|
12
14
|
protected createParserFromTokenStream(tokenStream: CommonTokenStream): MySqlParser;
|
|
13
15
|
protected preferredRules: Set<number>;
|
|
14
16
|
protected get splitListener(): MysqlSplitListener;
|
|
17
|
+
protected createErrorListener(_errorListener: ErrorListener): MysqlErrorListener;
|
|
15
18
|
protected createEntityCollector(input: string, caretTokenIndex?: number): MySqlEntityCollector;
|
|
16
19
|
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
17
20
|
}
|
|
@@ -4,6 +4,7 @@ import { BasicSQL } from '../common/basicSQL';
|
|
|
4
4
|
import { EntityContextType } from '../common/types';
|
|
5
5
|
import { MysqlSplitListener } from './mysqlSplitListener';
|
|
6
6
|
import { MySqlEntityCollector } from './mysqlEntityCollector';
|
|
7
|
+
import { MysqlErrorListener } from './mysqlErrorListener';
|
|
7
8
|
export { MySqlEntityCollector, MysqlSplitListener };
|
|
8
9
|
export class MySQL extends BasicSQL {
|
|
9
10
|
constructor() {
|
|
@@ -30,6 +31,9 @@ export class MySQL extends BasicSQL {
|
|
|
30
31
|
get splitListener() {
|
|
31
32
|
return new MysqlSplitListener();
|
|
32
33
|
}
|
|
34
|
+
createErrorListener(_errorListener) {
|
|
35
|
+
return new MysqlErrorListener(_errorListener, this.preferredRules, this.locale);
|
|
36
|
+
}
|
|
33
37
|
createEntityCollector(input, caretTokenIndex) {
|
|
34
38
|
return new MySqlEntityCollector(input, caretTokenIndex);
|
|
35
39
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ColumnCreateTableContext, ColumnNameCreateContext, CopyCreateTableContext, CreateDatabaseContext, CreateFunctionContext, CreateFunctionLoadableContext, CreateViewContext, DatabaseNameContext, DatabaseNameCreateContext, FunctionNameCreateContext, InsertStatementContext, QueryCreateTableContext, SelectStatementContext, SingleStatementContext, TableNameContext, TableNameCreateContext, ViewNameContext, ViewNameCreateContext } 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 {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { ColumnCreateTableContext, CreateDefinitionContext, CreateFunctionContext, TableSourceContext, } from '../../lib/mysql/MySqlParser';
|
|
2
|
+
import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector';
|
|
1
3
|
import { EntityContextType } from '../common/types';
|
|
2
|
-
import { StmtContextType, EntityCollector } from '../common/entityCollector';
|
|
3
4
|
export class MySqlEntityCollector extends EntityCollector {
|
|
4
5
|
/** ====== Entity Begin */
|
|
5
6
|
exitDatabaseName(ctx) {
|
|
@@ -9,10 +10,24 @@ export class MySqlEntityCollector extends EntityCollector {
|
|
|
9
10
|
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE);
|
|
10
11
|
}
|
|
11
12
|
exitTableName(ctx) {
|
|
12
|
-
|
|
13
|
+
var _a;
|
|
14
|
+
const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT;
|
|
15
|
+
this.pushEntity(ctx, EntityContextType.TABLE, needCollectAttr
|
|
16
|
+
? [
|
|
17
|
+
{
|
|
18
|
+
attrName: AttrName.alias,
|
|
19
|
+
endContextList: [TableSourceContext.name],
|
|
20
|
+
},
|
|
21
|
+
]
|
|
22
|
+
: undefined);
|
|
13
23
|
}
|
|
14
24
|
exitTableNameCreate(ctx) {
|
|
15
|
-
this.pushEntity(ctx, EntityContextType.TABLE_CREATE
|
|
25
|
+
this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [
|
|
26
|
+
{
|
|
27
|
+
attrName: AttrName.comment,
|
|
28
|
+
endContextList: [ColumnCreateTableContext.name],
|
|
29
|
+
},
|
|
30
|
+
]);
|
|
16
31
|
}
|
|
17
32
|
exitViewName(ctx) {
|
|
18
33
|
this.pushEntity(ctx, EntityContextType.VIEW);
|
|
@@ -21,10 +36,24 @@ export class MySqlEntityCollector extends EntityCollector {
|
|
|
21
36
|
this.pushEntity(ctx, EntityContextType.VIEW_CREATE);
|
|
22
37
|
}
|
|
23
38
|
exitFunctionNameCreate(ctx) {
|
|
24
|
-
this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE
|
|
39
|
+
this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE, [
|
|
40
|
+
{
|
|
41
|
+
attrName: AttrName.comment,
|
|
42
|
+
endContextList: [CreateFunctionContext.name],
|
|
43
|
+
},
|
|
44
|
+
]);
|
|
25
45
|
}
|
|
26
46
|
exitColumnNameCreate(ctx) {
|
|
27
|
-
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE
|
|
47
|
+
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [
|
|
48
|
+
{
|
|
49
|
+
attrName: AttrName.comment,
|
|
50
|
+
endContextList: [CreateDefinitionContext.name],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
attrName: AttrName.colType,
|
|
54
|
+
endContextList: [CreateDefinitionContext.name],
|
|
55
|
+
},
|
|
56
|
+
]);
|
|
28
57
|
}
|
|
29
58
|
/** ===== Statement begin */
|
|
30
59
|
enterSingleStatement(ctx) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ErrorListener, ParseErrorListener } from '../common/parseErrorListener';
|
|
2
|
+
import { Parser, Token } from 'antlr4ng';
|
|
3
|
+
import { LOCALE_TYPE } from '../common/types';
|
|
4
|
+
export declare class MysqlErrorListener extends ParseErrorListener {
|
|
5
|
+
private preferredRules;
|
|
6
|
+
private objectNames;
|
|
7
|
+
constructor(errorListener: ErrorListener, preferredRules: Set<number>, locale: LOCALE_TYPE);
|
|
8
|
+
getExpectedText(parser: Parser, token: Token): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CodeCompletionCore } from 'antlr4-c3';
|
|
2
|
+
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
3
|
+
import { MySqlParser } from '../../lib/mysql/MySqlParser';
|
|
4
|
+
export class MysqlErrorListener extends ParseErrorListener {
|
|
5
|
+
constructor(errorListener, preferredRules, locale) {
|
|
6
|
+
super(errorListener, locale);
|
|
7
|
+
this.objectNames = new Map([
|
|
8
|
+
[MySqlParser.RULE_databaseName, 'database'],
|
|
9
|
+
[MySqlParser.RULE_databaseNameCreate, 'database'],
|
|
10
|
+
[MySqlParser.RULE_tableName, 'table'],
|
|
11
|
+
[MySqlParser.RULE_tableNameCreate, 'table'],
|
|
12
|
+
[MySqlParser.RULE_viewName, 'view'],
|
|
13
|
+
[MySqlParser.RULE_viewNameCreate, 'view'],
|
|
14
|
+
[MySqlParser.RULE_functionName, 'function'],
|
|
15
|
+
[MySqlParser.RULE_functionNameCreate, 'function'],
|
|
16
|
+
[MySqlParser.RULE_columnName, 'column'],
|
|
17
|
+
[MySqlParser.RULE_columnNameCreate, 'column'],
|
|
18
|
+
]);
|
|
19
|
+
this.preferredRules = preferredRules;
|
|
20
|
+
}
|
|
21
|
+
getExpectedText(parser, token) {
|
|
22
|
+
var _a;
|
|
23
|
+
let expectedText = '';
|
|
24
|
+
let currentContext = (_a = parser.context) !== null && _a !== void 0 ? _a : undefined;
|
|
25
|
+
while (currentContext === null || currentContext === void 0 ? void 0 : currentContext.parent) {
|
|
26
|
+
currentContext = currentContext.parent;
|
|
27
|
+
}
|
|
28
|
+
const core = new CodeCompletionCore(parser);
|
|
29
|
+
core.preferredRules = this.preferredRules;
|
|
30
|
+
const candidates = core.collectCandidates(token.tokenIndex, currentContext);
|
|
31
|
+
if (candidates.rules.size) {
|
|
32
|
+
const result = [];
|
|
33
|
+
// get expectedText as collect rules first
|
|
34
|
+
for (const candidate of candidates.rules) {
|
|
35
|
+
const [ruleType] = candidate;
|
|
36
|
+
const name = this.objectNames.get(ruleType);
|
|
37
|
+
switch (ruleType) {
|
|
38
|
+
case MySqlParser.RULE_databaseName:
|
|
39
|
+
case MySqlParser.RULE_tableName:
|
|
40
|
+
case MySqlParser.RULE_functionName:
|
|
41
|
+
case MySqlParser.RULE_viewName:
|
|
42
|
+
case MySqlParser.RULE_columnName: {
|
|
43
|
+
result.push(`{existing}${name}`);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case MySqlParser.RULE_databaseNameCreate:
|
|
47
|
+
case MySqlParser.RULE_tableNameCreate:
|
|
48
|
+
case MySqlParser.RULE_functionNameCreate:
|
|
49
|
+
case MySqlParser.RULE_viewNameCreate:
|
|
50
|
+
case MySqlParser.RULE_columnNameCreate: {
|
|
51
|
+
result.push(`{new}${name}`);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
expectedText = result.join(`{or}`);
|
|
57
|
+
}
|
|
58
|
+
if (candidates.tokens.size) {
|
|
59
|
+
expectedText += expectedText ? '{orKeyword}' : '{keyword}';
|
|
60
|
+
}
|
|
61
|
+
return expectedText;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -6,12 +6,15 @@ import { Suggestions } from '../common/types';
|
|
|
6
6
|
import { BasicSQL } from '../common/basicSQL';
|
|
7
7
|
import { PostgreSqlEntityCollector } from './postgreEntityCollector';
|
|
8
8
|
import { PostgreSqlSplitListener } from './postgreSplitListener';
|
|
9
|
+
import { ErrorListener } from '../common/parseErrorListener';
|
|
10
|
+
import { PostgreSqlErrorListener } from './postgreErrorListener';
|
|
9
11
|
export { PostgreSqlEntityCollector, PostgreSqlSplitListener };
|
|
10
12
|
export declare class PostgreSQL extends BasicSQL<PostgreSqlLexer, ProgramContext, PostgreSqlParser> {
|
|
11
13
|
protected createLexerFromCharStream(charStreams: CharStream): PostgreSqlLexer;
|
|
12
14
|
protected createParserFromTokenStream(tokenStream: CommonTokenStream): PostgreSqlParser;
|
|
13
15
|
protected preferredRules: Set<number>;
|
|
14
16
|
protected get splitListener(): PostgreSqlSplitListener;
|
|
17
|
+
protected createErrorListener(_errorListener: ErrorListener): PostgreSqlErrorListener;
|
|
15
18
|
protected createEntityCollector(input: string, caretTokenIndex?: number): PostgreSqlEntityCollector;
|
|
16
19
|
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
17
20
|
}
|
|
@@ -4,6 +4,7 @@ import { EntityContextType } from '../common/types';
|
|
|
4
4
|
import { BasicSQL } from '../common/basicSQL';
|
|
5
5
|
import { PostgreSqlEntityCollector } from './postgreEntityCollector';
|
|
6
6
|
import { PostgreSqlSplitListener } from './postgreSplitListener';
|
|
7
|
+
import { PostgreSqlErrorListener } from './postgreErrorListener';
|
|
7
8
|
export { PostgreSqlEntityCollector, PostgreSqlSplitListener };
|
|
8
9
|
export class PostgreSQL extends BasicSQL {
|
|
9
10
|
constructor() {
|
|
@@ -34,6 +35,9 @@ export class PostgreSQL extends BasicSQL {
|
|
|
34
35
|
get splitListener() {
|
|
35
36
|
return new PostgreSqlSplitListener();
|
|
36
37
|
}
|
|
38
|
+
createErrorListener(_errorListener) {
|
|
39
|
+
return new PostgreSqlErrorListener(_errorListener, this.preferredRules, this.locale);
|
|
40
|
+
}
|
|
37
41
|
createEntityCollector(input, caretTokenIndex) {
|
|
38
42
|
return new PostgreSqlEntityCollector(input, caretTokenIndex);
|
|
39
43
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AltertablestmtContext, type ColumnCreateTableContext, type ColumnNameCreateContext, type CreateDatabaseContext, type CreateForeignTableContext, type CreatefunctionstmtContext, type CreateMaterializedViewContext, type CreatePartitionForeignTableContext, type CreateViewContext, type DatabaseNameContext, type DatabaseNameCreateContext, type FunctionNameCreateContext, type InsertStatementContext, type ProcedureNameContext, type ProcedureNameCreateContext, type QueryCreateTableContext, type SelectStatementContext, type SingleStmtContext, type TableNameContext, type TableNameCreateContext, type ViewNameContext, type ViewNameCreateContext } 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 {
|
|
@@ -11,6 +11,8 @@ export declare class PostgreSqlEntityCollector extends EntityCollector implement
|
|
|
11
11
|
exitViewNameCreate(ctx: ViewNameCreateContext): void;
|
|
12
12
|
exitFunctionNameCreate(ctx: FunctionNameCreateContext): void;
|
|
13
13
|
exitColumnNameCreate(ctx: ColumnNameCreateContext): void;
|
|
14
|
+
exitProcedureName(ctx: ProcedureNameContext): void;
|
|
15
|
+
exitProcedureNameCreate(ctx: ProcedureNameCreateContext): void;
|
|
14
16
|
/** ===== Statement begin */
|
|
15
17
|
enterSingleStatement(ctx: SingleStmtContext): void;
|
|
16
18
|
exitSingleStatement(ctx: SingleStmtContext): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Column_defContext, Table_refContext, } from '../../lib/postgresql/PostgreSqlParser';
|
|
2
|
+
import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector';
|
|
1
3
|
import { EntityContextType } from '../common/types';
|
|
2
|
-
import { StmtContextType, EntityCollector } from '../common/entityCollector';
|
|
3
4
|
export class PostgreSqlEntityCollector extends EntityCollector {
|
|
4
5
|
/** ====== Entity Begin */
|
|
5
6
|
exitDatabaseName(ctx) {
|
|
@@ -9,13 +10,31 @@ export class PostgreSqlEntityCollector extends EntityCollector {
|
|
|
9
10
|
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE);
|
|
10
11
|
}
|
|
11
12
|
exitTableName(ctx) {
|
|
12
|
-
|
|
13
|
+
var _a;
|
|
14
|
+
const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT;
|
|
15
|
+
this.pushEntity(ctx, EntityContextType.TABLE, needCollectAttr
|
|
16
|
+
? [
|
|
17
|
+
{
|
|
18
|
+
attrName: AttrName.alias,
|
|
19
|
+
endContextList: [Table_refContext.name],
|
|
20
|
+
},
|
|
21
|
+
]
|
|
22
|
+
: undefined);
|
|
13
23
|
}
|
|
14
24
|
exitTableNameCreate(ctx) {
|
|
15
25
|
this.pushEntity(ctx, EntityContextType.TABLE_CREATE);
|
|
16
26
|
}
|
|
17
27
|
exitViewName(ctx) {
|
|
18
|
-
|
|
28
|
+
var _a;
|
|
29
|
+
const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT;
|
|
30
|
+
this.pushEntity(ctx, EntityContextType.VIEW, needCollectAttr
|
|
31
|
+
? [
|
|
32
|
+
{
|
|
33
|
+
attrName: AttrName.alias,
|
|
34
|
+
endContextList: [Table_refContext.name],
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
: undefined);
|
|
19
38
|
}
|
|
20
39
|
exitViewNameCreate(ctx) {
|
|
21
40
|
this.pushEntity(ctx, EntityContextType.VIEW_CREATE);
|
|
@@ -24,7 +43,22 @@ export class PostgreSqlEntityCollector extends EntityCollector {
|
|
|
24
43
|
this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE);
|
|
25
44
|
}
|
|
26
45
|
exitColumnNameCreate(ctx) {
|
|
27
|
-
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE
|
|
46
|
+
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [
|
|
47
|
+
{
|
|
48
|
+
attrName: AttrName.comment,
|
|
49
|
+
endContextList: [Column_defContext.name],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
attrName: AttrName.colType,
|
|
53
|
+
endContextList: [Column_defContext.name],
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
exitProcedureName(ctx) {
|
|
58
|
+
this.pushEntity(ctx, EntityContextType.PROCEDURE);
|
|
59
|
+
}
|
|
60
|
+
exitProcedureNameCreate(ctx) {
|
|
61
|
+
this.pushEntity(ctx, EntityContextType.PROCEDURE_CREATE);
|
|
28
62
|
}
|
|
29
63
|
/** ===== Statement begin */
|
|
30
64
|
enterSingleStatement(ctx) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ErrorListener, ParseErrorListener } from '../common/parseErrorListener';
|
|
2
|
+
import { Parser, Token } from 'antlr4ng';
|
|
3
|
+
import { LOCALE_TYPE } from '../common/types';
|
|
4
|
+
export declare class PostgreSqlErrorListener extends ParseErrorListener {
|
|
5
|
+
private preferredRules;
|
|
6
|
+
private objectNames;
|
|
7
|
+
constructor(errorListener: ErrorListener, preferredRules: Set<number>, locale: LOCALE_TYPE);
|
|
8
|
+
getExpectedText(parser: Parser, token: Token): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { CodeCompletionCore } from 'antlr4-c3';
|
|
2
|
+
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
3
|
+
import { PostgreSqlParser } from '../../lib/postgresql/PostgreSqlParser';
|
|
4
|
+
export class PostgreSqlErrorListener extends ParseErrorListener {
|
|
5
|
+
constructor(errorListener, preferredRules, locale) {
|
|
6
|
+
super(errorListener, locale);
|
|
7
|
+
this.objectNames = new Map([
|
|
8
|
+
[PostgreSqlParser.RULE_database_name, 'database'],
|
|
9
|
+
[PostgreSqlParser.RULE_database_name_create, 'database'],
|
|
10
|
+
[PostgreSqlParser.RULE_table_name, 'table'],
|
|
11
|
+
[PostgreSqlParser.RULE_table_name_create, 'table'],
|
|
12
|
+
[PostgreSqlParser.RULE_view_name, 'view'],
|
|
13
|
+
[PostgreSqlParser.RULE_view_name_create, 'view'],
|
|
14
|
+
[PostgreSqlParser.RULE_function_name, 'function'],
|
|
15
|
+
[PostgreSqlParser.RULE_function_name_create, 'function'],
|
|
16
|
+
[PostgreSqlParser.RULE_column_name, 'column'],
|
|
17
|
+
[PostgreSqlParser.RULE_column_name_create, 'column'],
|
|
18
|
+
[PostgreSqlParser.RULE_schema_name_create, 'schema'],
|
|
19
|
+
[PostgreSqlParser.RULE_schema_name, 'schema'],
|
|
20
|
+
[PostgreSqlParser.RULE_procedure_name_create, 'procedure'],
|
|
21
|
+
[PostgreSqlParser.RULE_procedure_name, 'procedure'],
|
|
22
|
+
]);
|
|
23
|
+
this.preferredRules = preferredRules;
|
|
24
|
+
}
|
|
25
|
+
getExpectedText(parser, token) {
|
|
26
|
+
var _a;
|
|
27
|
+
let expectedText = '';
|
|
28
|
+
let currentContext = (_a = parser.context) !== null && _a !== void 0 ? _a : undefined;
|
|
29
|
+
while (currentContext === null || currentContext === void 0 ? void 0 : currentContext.parent) {
|
|
30
|
+
currentContext = currentContext.parent;
|
|
31
|
+
}
|
|
32
|
+
const core = new CodeCompletionCore(parser);
|
|
33
|
+
core.preferredRules = this.preferredRules;
|
|
34
|
+
const candidates = core.collectCandidates(token.tokenIndex, currentContext);
|
|
35
|
+
if (candidates.rules.size) {
|
|
36
|
+
const result = [];
|
|
37
|
+
// get expectedText as collect rules first
|
|
38
|
+
for (const candidate of candidates.rules) {
|
|
39
|
+
const [ruleType] = candidate;
|
|
40
|
+
const name = this.objectNames.get(ruleType);
|
|
41
|
+
switch (ruleType) {
|
|
42
|
+
case PostgreSqlParser.RULE_table_name:
|
|
43
|
+
case PostgreSqlParser.RULE_function_name:
|
|
44
|
+
case PostgreSqlParser.RULE_schema_name:
|
|
45
|
+
case PostgreSqlParser.RULE_view_name:
|
|
46
|
+
case PostgreSqlParser.RULE_database_name:
|
|
47
|
+
case PostgreSqlParser.RULE_procedure_name:
|
|
48
|
+
case PostgreSqlParser.RULE_column_name: {
|
|
49
|
+
result.push(`{existing}${name}`);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case PostgreSqlParser.RULE_table_name_create:
|
|
53
|
+
case PostgreSqlParser.RULE_function_name_create:
|
|
54
|
+
case PostgreSqlParser.RULE_schema_name_create:
|
|
55
|
+
case PostgreSqlParser.RULE_view_name_create:
|
|
56
|
+
case PostgreSqlParser.RULE_database_name_create:
|
|
57
|
+
case PostgreSqlParser.RULE_procedure_name_create:
|
|
58
|
+
case PostgreSqlParser.RULE_column_name_create: {
|
|
59
|
+
result.push(`{new}${name}`);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
expectedText = result.join('{or}');
|
|
65
|
+
}
|
|
66
|
+
if (candidates.tokens.size) {
|
|
67
|
+
expectedText += expectedText ? '{orKeyword}' : '{keyword}';
|
|
68
|
+
}
|
|
69
|
+
return expectedText;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -6,12 +6,15 @@ import { BasicSQL } from '../common/basicSQL';
|
|
|
6
6
|
import { Suggestions } from '../common/types';
|
|
7
7
|
import { SparkSqlSplitListener } from './sparkSplitListener';
|
|
8
8
|
import { SparkEntityCollector } from './sparkEntityCollector';
|
|
9
|
+
import { SparkErrorListener } from './sparkErrorListener';
|
|
10
|
+
import { ErrorListener } from '../common/parseErrorListener';
|
|
9
11
|
export { SparkSqlSplitListener, SparkEntityCollector };
|
|
10
12
|
export declare class SparkSQL extends BasicSQL<SparkSqlLexer, ProgramContext, SparkSqlParser> {
|
|
11
13
|
protected createLexerFromCharStream(charStreams: CharStream): SparkSqlLexer;
|
|
12
14
|
protected createParserFromTokenStream(tokenStream: CommonTokenStream): SparkSqlParser;
|
|
13
15
|
protected preferredRules: Set<number>;
|
|
14
16
|
protected get splitListener(): SparkSqlSplitListener;
|
|
17
|
+
protected createErrorListener(_errorListener: ErrorListener): SparkErrorListener;
|
|
15
18
|
protected createEntityCollector(input: string, caretTokenIndex?: number): SparkEntityCollector;
|
|
16
19
|
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
17
20
|
}
|
|
@@ -4,6 +4,7 @@ import { BasicSQL } from '../common/basicSQL';
|
|
|
4
4
|
import { EntityContextType } from '../common/types';
|
|
5
5
|
import { SparkSqlSplitListener } from './sparkSplitListener';
|
|
6
6
|
import { SparkEntityCollector } from './sparkEntityCollector';
|
|
7
|
+
import { SparkErrorListener } from './sparkErrorListener';
|
|
7
8
|
export { SparkSqlSplitListener, SparkEntityCollector };
|
|
8
9
|
export class SparkSQL extends BasicSQL {
|
|
9
10
|
constructor() {
|
|
@@ -30,6 +31,9 @@ export class SparkSQL extends BasicSQL {
|
|
|
30
31
|
get splitListener() {
|
|
31
32
|
return new SparkSqlSplitListener();
|
|
32
33
|
}
|
|
34
|
+
createErrorListener(_errorListener) {
|
|
35
|
+
return new SparkErrorListener(_errorListener, this.preferredRules, this.locale);
|
|
36
|
+
}
|
|
33
37
|
createEntityCollector(input, caretTokenIndex) {
|
|
34
38
|
return new SparkEntityCollector(input, caretTokenIndex);
|
|
35
39
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ColumnNameCreateContext, CreateFunctionContext, CreateNamespaceContext, CreateTableContext, CreateTableLikeContext, CreateTempViewUsingContext, CreateViewContext, FunctionNameCreateContext, InsertFromQueryContext, MultipleInsertContext, NamespaceNameContext, NamespaceNameCreateContext, QueryStatementContext, ReplaceTableContext, SingleStatementContext, 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 {
|
|
@@ -1,30 +1,67 @@
|
|
|
1
|
+
import { CreateNamespaceContext, CreateOrReplaceTableColTypeContext, CreateTableContext, CreateViewContext, IdentifierCommentContext, RelationPrimaryContext, } from '../../lib/spark/SparkSqlParser';
|
|
2
|
+
import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector';
|
|
1
3
|
import { EntityContextType } from '../common/types';
|
|
2
|
-
import { StmtContextType, EntityCollector } from '../common/entityCollector';
|
|
3
4
|
export class SparkEntityCollector extends EntityCollector {
|
|
4
5
|
/** ====== Entity Begin */
|
|
5
6
|
exitNamespaceName(ctx) {
|
|
6
7
|
this.pushEntity(ctx, EntityContextType.DATABASE);
|
|
7
8
|
}
|
|
8
9
|
exitNamespaceNameCreate(ctx) {
|
|
9
|
-
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE
|
|
10
|
+
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE, [
|
|
11
|
+
{
|
|
12
|
+
attrName: AttrName.comment,
|
|
13
|
+
endContextList: [CreateNamespaceContext.name],
|
|
14
|
+
},
|
|
15
|
+
]);
|
|
10
16
|
}
|
|
11
17
|
exitTableName(ctx) {
|
|
12
|
-
|
|
18
|
+
var _a;
|
|
19
|
+
const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT;
|
|
20
|
+
this.pushEntity(ctx, EntityContextType.TABLE, needCollectAttr
|
|
21
|
+
? [
|
|
22
|
+
{
|
|
23
|
+
attrName: AttrName.alias,
|
|
24
|
+
endContextList: [RelationPrimaryContext.name],
|
|
25
|
+
},
|
|
26
|
+
]
|
|
27
|
+
: undefined);
|
|
13
28
|
}
|
|
14
29
|
exitTableNameCreate(ctx) {
|
|
15
|
-
this.pushEntity(ctx, EntityContextType.TABLE_CREATE
|
|
30
|
+
this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [
|
|
31
|
+
{
|
|
32
|
+
attrName: AttrName.comment,
|
|
33
|
+
endContextList: [CreateTableContext.name],
|
|
34
|
+
},
|
|
35
|
+
]);
|
|
16
36
|
}
|
|
17
37
|
exitViewName(ctx) {
|
|
18
38
|
this.pushEntity(ctx, EntityContextType.VIEW);
|
|
19
39
|
}
|
|
20
40
|
exitViewNameCreate(ctx) {
|
|
21
|
-
this.pushEntity(ctx, EntityContextType.VIEW_CREATE
|
|
41
|
+
this.pushEntity(ctx, EntityContextType.VIEW_CREATE, [
|
|
42
|
+
{
|
|
43
|
+
attrName: AttrName.comment,
|
|
44
|
+
endContextList: [CreateViewContext.name],
|
|
45
|
+
},
|
|
46
|
+
]);
|
|
22
47
|
}
|
|
23
48
|
exitFunctionNameCreate(ctx) {
|
|
24
49
|
this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE);
|
|
25
50
|
}
|
|
26
51
|
exitColumnNameCreate(ctx) {
|
|
27
|
-
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE
|
|
52
|
+
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [
|
|
53
|
+
{
|
|
54
|
+
attrName: AttrName.comment,
|
|
55
|
+
endContextList: [
|
|
56
|
+
CreateOrReplaceTableColTypeContext.name,
|
|
57
|
+
IdentifierCommentContext.name,
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
attrName: AttrName.colType,
|
|
62
|
+
endContextList: [CreateOrReplaceTableColTypeContext.name],
|
|
63
|
+
},
|
|
64
|
+
]);
|
|
28
65
|
}
|
|
29
66
|
/** ===== Statement begin */
|
|
30
67
|
enterSingleStatement(ctx) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ErrorListener, ParseErrorListener } from '../common/parseErrorListener';
|
|
2
|
+
import { Parser, Token } from 'antlr4ng';
|
|
3
|
+
import { LOCALE_TYPE } from '../common/types';
|
|
4
|
+
export declare class SparkErrorListener extends ParseErrorListener {
|
|
5
|
+
private preferredRules;
|
|
6
|
+
private objectNames;
|
|
7
|
+
constructor(errorListener: ErrorListener, preferredRules: Set<number>, locale: LOCALE_TYPE);
|
|
8
|
+
getExpectedText(parser: Parser, token: Token): string;
|
|
9
|
+
}
|