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.
Files changed (74) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/lib/flink/FlinkSqlParser.d.ts +168 -171
  3. package/dist/lib/flink/FlinkSqlParser.js +2341 -2426
  4. package/dist/lib/flink/FlinkSqlParserListener.d.ts +0 -11
  5. package/dist/lib/flink/FlinkSqlParserVisitor.d.ts +0 -7
  6. package/dist/lib/hive/HiveSqlParser.d.ts +5 -1
  7. package/dist/lib/hive/HiveSqlParser.js +145 -130
  8. package/dist/lib/impala/ImpalaSqlParser.d.ts +121 -105
  9. package/dist/lib/impala/ImpalaSqlParser.js +3303 -3225
  10. package/dist/lib/impala/ImpalaSqlParserListener.d.ts +22 -0
  11. package/dist/lib/impala/ImpalaSqlParserVisitor.d.ts +14 -0
  12. package/dist/lib/mysql/MySqlParser.d.ts +4 -0
  13. package/dist/lib/mysql/MySqlParser.js +4 -4
  14. package/dist/lib/postgresql/PostgreSqlParser.d.ts +3 -0
  15. package/dist/lib/postgresql/PostgreSqlParser.js +1500 -1492
  16. package/dist/lib/spark/SparkSqlParser.d.ts +16 -13
  17. package/dist/lib/spark/SparkSqlParser.js +49 -49
  18. package/dist/lib/spark/SparkSqlParserListener.d.ts +10 -10
  19. package/dist/lib/spark/SparkSqlParserVisitor.d.ts +6 -6
  20. package/dist/lib/trino/TrinoSqlParser.d.ts +13 -5
  21. package/dist/lib/trino/TrinoSqlParser.js +23 -23
  22. package/dist/locale/locale.d.ts +41 -0
  23. package/dist/locale/locale.js +43 -0
  24. package/dist/parser/common/basicSQL.d.ts +7 -2
  25. package/dist/parser/common/basicSQL.js +5 -5
  26. package/dist/parser/common/entityCollector.d.ts +58 -11
  27. package/dist/parser/common/entityCollector.js +140 -17
  28. package/dist/parser/common/parseErrorListener.d.ts +6 -3
  29. package/dist/parser/common/parseErrorListener.js +83 -2
  30. package/dist/parser/common/textAndWord.d.ts +6 -9
  31. package/dist/parser/common/textAndWord.js +9 -20
  32. package/dist/parser/common/transform.d.ts +8 -0
  33. package/dist/parser/common/transform.js +11 -0
  34. package/dist/parser/common/types.d.ts +1 -0
  35. package/dist/parser/flink/flinkEntityCollector.js +40 -6
  36. package/dist/parser/flink/flinkErrorListener.d.ts +9 -0
  37. package/dist/parser/flink/flinkErrorListener.js +67 -0
  38. package/dist/parser/flink/index.d.ts +3 -0
  39. package/dist/parser/flink/index.js +4 -0
  40. package/dist/parser/hive/hiveEntityCollector.js +40 -6
  41. package/dist/parser/hive/hiveErrorListener.d.ts +9 -0
  42. package/dist/parser/hive/hiveErrorListener.js +65 -0
  43. package/dist/parser/hive/index.d.ts +3 -0
  44. package/dist/parser/hive/index.js +4 -0
  45. package/dist/parser/impala/ImpalaErrorListener.d.ts +9 -0
  46. package/dist/parser/impala/ImpalaErrorListener.js +63 -0
  47. package/dist/parser/impala/impalaEntityCollector.js +51 -6
  48. package/dist/parser/impala/index.d.ts +3 -0
  49. package/dist/parser/impala/index.js +4 -0
  50. package/dist/parser/mysql/index.d.ts +3 -0
  51. package/dist/parser/mysql/index.js +4 -0
  52. package/dist/parser/mysql/mysqlEntityCollector.d.ts +1 -1
  53. package/dist/parser/mysql/mysqlEntityCollector.js +34 -5
  54. package/dist/parser/mysql/mysqlErrorListener.d.ts +9 -0
  55. package/dist/parser/mysql/mysqlErrorListener.js +63 -0
  56. package/dist/parser/postgresql/index.d.ts +3 -0
  57. package/dist/parser/postgresql/index.js +4 -0
  58. package/dist/parser/postgresql/postgreEntityCollector.d.ts +3 -1
  59. package/dist/parser/postgresql/postgreEntityCollector.js +38 -4
  60. package/dist/parser/postgresql/postgreErrorListener.d.ts +9 -0
  61. package/dist/parser/postgresql/postgreErrorListener.js +71 -0
  62. package/dist/parser/spark/index.d.ts +3 -0
  63. package/dist/parser/spark/index.js +4 -0
  64. package/dist/parser/spark/sparkEntityCollector.d.ts +1 -1
  65. package/dist/parser/spark/sparkEntityCollector.js +43 -6
  66. package/dist/parser/spark/sparkErrorListener.d.ts +9 -0
  67. package/dist/parser/spark/sparkErrorListener.js +63 -0
  68. package/dist/parser/trino/index.d.ts +3 -0
  69. package/dist/parser/trino/index.js +4 -0
  70. package/dist/parser/trino/trinoEntityCollector.d.ts +1 -1
  71. package/dist/parser/trino/trinoEntityCollector.js +34 -5
  72. package/dist/parser/trino/trinoErrorListener.d.ts +9 -0
  73. package/dist/parser/trino/trinoErrorListener.js +65 -0
  74. package/package.json +5 -3
@@ -0,0 +1,63 @@
1
+ import { CodeCompletionCore } from 'antlr4-c3';
2
+ import { ParseErrorListener } from '../common/parseErrorListener';
3
+ import { SparkSqlParser } from '../../lib/spark/SparkSqlParser';
4
+ export class SparkErrorListener extends ParseErrorListener {
5
+ constructor(errorListener, preferredRules, locale) {
6
+ super(errorListener, locale);
7
+ this.objectNames = new Map([
8
+ [SparkSqlParser.RULE_namespaceName, 'namespace'],
9
+ [SparkSqlParser.RULE_namespaceNameCreate, 'namespace'],
10
+ [SparkSqlParser.RULE_tableName, 'table'],
11
+ [SparkSqlParser.RULE_tableNameCreate, 'table'],
12
+ [SparkSqlParser.RULE_viewName, 'view'],
13
+ [SparkSqlParser.RULE_viewNameCreate, 'view'],
14
+ [SparkSqlParser.RULE_functionName, 'function'],
15
+ [SparkSqlParser.RULE_functionNameCreate, 'function'],
16
+ [SparkSqlParser.RULE_columnName, 'column'],
17
+ [SparkSqlParser.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 SparkSqlParser.RULE_namespaceName:
39
+ case SparkSqlParser.RULE_tableName:
40
+ case SparkSqlParser.RULE_viewName:
41
+ case SparkSqlParser.RULE_functionName:
42
+ case SparkSqlParser.RULE_columnName: {
43
+ result.push(`{existing}${name}`);
44
+ break;
45
+ }
46
+ case SparkSqlParser.RULE_namespaceNameCreate:
47
+ case SparkSqlParser.RULE_tableNameCreate:
48
+ case SparkSqlParser.RULE_functionNameCreate:
49
+ case SparkSqlParser.RULE_viewNameCreate:
50
+ case SparkSqlParser.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,11 +6,14 @@ import { BasicSQL } from '../common/basicSQL';
6
6
  import { Suggestions } from '../common/types';
7
7
  import { TrinoSqlSplitListener } from './trinoSplitListener';
8
8
  import { TrinoEntityCollector } from './trinoEntityCollector';
9
+ import { ErrorListener } from '../common/parseErrorListener';
10
+ import { TrinoErrorListener } from './trinoErrorListener';
9
11
  export { TrinoSqlSplitListener, TrinoEntityCollector };
10
12
  export declare class TrinoSQL extends BasicSQL<TrinoSqlLexer, ProgramContext, TrinoSqlParser> {
11
13
  protected createLexerFromCharStream(charStreams: CharStream): TrinoSqlLexer;
12
14
  protected createParserFromTokenStream(tokenStream: CommonTokenStream): TrinoSqlParser;
13
15
  protected get splitListener(): TrinoSqlSplitListener;
16
+ protected createErrorListener(_errorListener: ErrorListener): TrinoErrorListener;
14
17
  protected createEntityCollector(input: string, caretTokenIndex?: number): TrinoEntityCollector;
15
18
  protected preferredRules: Set<number>;
16
19
  protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
@@ -4,6 +4,7 @@ import { BasicSQL } from '../common/basicSQL';
4
4
  import { EntityContextType } from '../common/types';
5
5
  import { TrinoSqlSplitListener } from './trinoSplitListener';
6
6
  import { TrinoEntityCollector } from './trinoEntityCollector';
7
+ import { TrinoErrorListener } from './trinoErrorListener';
7
8
  export { TrinoSqlSplitListener, TrinoEntityCollector };
8
9
  export class TrinoSQL extends BasicSQL {
9
10
  constructor() {
@@ -32,6 +33,9 @@ export class TrinoSQL extends BasicSQL {
32
33
  get splitListener() {
33
34
  return new TrinoSqlSplitListener();
34
35
  }
36
+ createErrorListener(_errorListener) {
37
+ return new TrinoErrorListener(_errorListener, this.preferredRules, this.locale);
38
+ }
35
39
  createEntityCollector(input, caretTokenIndex) {
36
40
  return new TrinoEntityCollector(input, caretTokenIndex);
37
41
  }
@@ -1,5 +1,5 @@
1
- import type { CatalogNameCreateContext, CatalogRefContext, ColumnNameCreateContext, CreateMaterializedViewContext, CreateSchemaContext, CreateTableAsSelectContext, CreateTableContext, CreateViewContext, InsertIntoContext, SchemaNameCreateContext, SchemaRefContext, SingleStatementContext, TableNameCreateContext, TableRefContext, ViewNameCreateContext, ViewRefContext, QueryStatementContext } from '../../lib/trino/TrinoSqlParser';
2
1
  import type { TrinoSqlListener } from '../../lib/trino/TrinoSqlListener';
2
+ import { CatalogNameCreateContext, CatalogRefContext, ColumnNameCreateContext, CreateMaterializedViewContext, CreateSchemaContext, CreateTableAsSelectContext, CreateTableContext, CreateViewContext, InsertIntoContext, QueryStatementContext, SchemaNameCreateContext, SchemaRefContext, SingleStatementContext, 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 */
@@ -1,5 +1,6 @@
1
+ import { AliasedRelationContext, ColumnDefinitionContext, CreateMaterializedViewContext, CreateTableAsSelectContext, CreateTableContext, CreateViewContext, } from '../../lib/trino/TrinoSqlParser';
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 TrinoEntityCollector extends EntityCollector {
4
5
  /** ====== Entity Begin */
5
6
  exitCatalogRef(ctx) {
@@ -15,19 +16,47 @@ export class TrinoEntityCollector extends EntityCollector {
15
16
  this.pushEntity(ctx, EntityContextType.DATABASE_CREATE);
16
17
  }
17
18
  exitTableRef(ctx) {
18
- this.pushEntity(ctx, EntityContextType.TABLE);
19
+ var _a;
20
+ const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT;
21
+ this.pushEntity(ctx, EntityContextType.TABLE, needCollectAttr
22
+ ? [
23
+ {
24
+ attrName: AttrName.alias,
25
+ endContextList: [AliasedRelationContext.name],
26
+ },
27
+ ]
28
+ : undefined);
19
29
  }
20
30
  exitTableNameCreate(ctx) {
21
- this.pushEntity(ctx, EntityContextType.TABLE_CREATE);
31
+ this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [
32
+ {
33
+ attrName: AttrName.comment,
34
+ endContextList: [CreateTableContext.name, CreateTableAsSelectContext.name],
35
+ },
36
+ ]);
22
37
  }
23
38
  exitViewRef(ctx) {
24
39
  this.pushEntity(ctx, EntityContextType.VIEW);
25
40
  }
26
41
  exitViewNameCreate(ctx) {
27
- this.pushEntity(ctx, EntityContextType.VIEW_CREATE);
42
+ this.pushEntity(ctx, EntityContextType.VIEW_CREATE, [
43
+ {
44
+ attrName: AttrName.comment,
45
+ endContextList: [CreateMaterializedViewContext.name, CreateViewContext.name],
46
+ },
47
+ ]);
28
48
  }
29
49
  exitColumnNameCreate(ctx) {
30
- this.pushEntity(ctx, EntityContextType.COLUMN_CREATE);
50
+ this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [
51
+ {
52
+ attrName: AttrName.colType,
53
+ endContextList: [ColumnDefinitionContext.name],
54
+ },
55
+ {
56
+ attrName: AttrName.comment,
57
+ endContextList: [ColumnDefinitionContext.name],
58
+ },
59
+ ]);
31
60
  }
32
61
  /** ===== Statement begin */
33
62
  enterSingleStatement(ctx) {
@@ -0,0 +1,9 @@
1
+ import { Parser, Token } from 'antlr4ng';
2
+ import { ErrorListener, ParseErrorListener } from '../common/parseErrorListener';
3
+ import { LOCALE_TYPE } from '../common/types';
4
+ export declare class TrinoErrorListener 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,65 @@
1
+ import { CodeCompletionCore } from 'antlr4-c3';
2
+ import { TrinoSqlParser } from '../../lib/trino/TrinoSqlParser';
3
+ import { ParseErrorListener } from '../common/parseErrorListener';
4
+ export class TrinoErrorListener extends ParseErrorListener {
5
+ constructor(errorListener, preferredRules, locale) {
6
+ super(errorListener, locale);
7
+ this.objectNames = new Map([
8
+ [TrinoSqlParser.RULE_catalogRef, 'catalog'],
9
+ [TrinoSqlParser.RULE_catalogNameCreate, 'catalog'],
10
+ [TrinoSqlParser.RULE_tableRef, 'table'],
11
+ [TrinoSqlParser.RULE_tableNameCreate, 'table'],
12
+ [TrinoSqlParser.RULE_viewRef, 'view'],
13
+ [TrinoSqlParser.RULE_viewNameCreate, 'view'],
14
+ [TrinoSqlParser.RULE_schemaRef, 'schema'],
15
+ [TrinoSqlParser.RULE_schemaNameCreate, 'schema'],
16
+ [TrinoSqlParser.RULE_functionName, 'function'],
17
+ [TrinoSqlParser.RULE_columnRef, 'column'],
18
+ [TrinoSqlParser.RULE_columnNameCreate, 'column'],
19
+ ]);
20
+ this.preferredRules = preferredRules;
21
+ }
22
+ getExpectedText(parser, token) {
23
+ var _a;
24
+ let expectedText = '';
25
+ let currentContext = (_a = parser.context) !== null && _a !== void 0 ? _a : undefined;
26
+ while (currentContext === null || currentContext === void 0 ? void 0 : currentContext.parent) {
27
+ currentContext = currentContext.parent;
28
+ }
29
+ const core = new CodeCompletionCore(parser);
30
+ core.preferredRules = this.preferredRules;
31
+ const candidates = core.collectCandidates(token.tokenIndex, currentContext);
32
+ if (candidates.rules.size) {
33
+ const result = [];
34
+ // get expectedText as collect rules first
35
+ for (const candidate of candidates.rules) {
36
+ const [ruleType] = candidate;
37
+ const name = this.objectNames.get(ruleType);
38
+ switch (ruleType) {
39
+ case TrinoSqlParser.RULE_catalogRef:
40
+ case TrinoSqlParser.RULE_schemaRef:
41
+ case TrinoSqlParser.RULE_tableRef:
42
+ case TrinoSqlParser.RULE_viewRef:
43
+ case TrinoSqlParser.RULE_functionName:
44
+ case TrinoSqlParser.RULE_columnRef: {
45
+ result.push(`{existing}${name}`);
46
+ break;
47
+ }
48
+ case TrinoSqlParser.RULE_catalogNameCreate:
49
+ case TrinoSqlParser.RULE_tableNameCreate:
50
+ case TrinoSqlParser.RULE_schemaNameCreate:
51
+ case TrinoSqlParser.RULE_viewNameCreate:
52
+ case TrinoSqlParser.RULE_tableNameCreate: {
53
+ result.push(`{new}${name}`);
54
+ break;
55
+ }
56
+ }
57
+ }
58
+ expectedText = result.join('{or}');
59
+ }
60
+ if (candidates.tokens.size) {
61
+ expectedText += expectedText ? '{orKeyword}' : '{keyword}';
62
+ }
63
+ return expectedText;
64
+ }
65
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-sql-parser",
3
- "version": "4.0.3-beta.0",
3
+ "version": "4.0.3-beta.1",
4
4
  "authors": "DTStack Corporation",
5
5
  "description": "SQL Parsers for BigData, built with antlr4",
6
6
  "keywords": [
@@ -70,7 +70,7 @@
70
70
  },
71
71
  "repository": {
72
72
  "type": "git",
73
- "url": "https://github.com/DTStack/dt-sql-parser.git"
73
+ "url": "https://github.com/DTStack/dt-sql-parser.git"
74
74
  },
75
75
  "publishConfig": {
76
76
  "registry": "https://registry.npmjs.org/"
@@ -89,6 +89,8 @@
89
89
  "*": [
90
90
  "prettier --write --ignore-unknown"
91
91
  ],
92
- "*.g4": ["antlr-format -c ./antlr.format.json -v"]
92
+ "*.g4": [
93
+ "antlr-format -c ./antlr.format.json -v"
94
+ ]
93
95
  }
94
96
  }