dt-sql-parser 4.1.2-beta.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +51 -0
  2. package/dist/lib/flink/FlinkSqlLexer.d.ts +5 -5
  3. package/dist/lib/flink/FlinkSqlLexer.js +1991 -1992
  4. package/dist/lib/flink/FlinkSqlParser.d.ts +240 -230
  5. package/dist/lib/flink/FlinkSqlParser.js +3036 -2978
  6. package/dist/lib/flink/FlinkSqlParserListener.d.ts +81 -70
  7. package/dist/lib/flink/FlinkSqlParserVisitor.d.ts +49 -42
  8. package/dist/lib/hive/HiveSqlParser.d.ts +251 -231
  9. package/dist/lib/hive/HiveSqlParser.js +6264 -5674
  10. package/dist/lib/hive/HiveSqlParserListener.d.ts +32 -10
  11. package/dist/lib/hive/HiveSqlParserVisitor.d.ts +20 -6
  12. package/dist/lib/impala/ImpalaSqlLexer.d.ts +2 -2
  13. package/dist/lib/impala/ImpalaSqlLexer.js +587 -588
  14. package/dist/lib/impala/ImpalaSqlParser.d.ts +151 -113
  15. package/dist/lib/impala/ImpalaSqlParser.js +3464 -3250
  16. package/dist/lib/impala/ImpalaSqlParserListener.d.ts +49 -5
  17. package/dist/lib/impala/ImpalaSqlParserVisitor.d.ts +31 -3
  18. package/dist/lib/mysql/MySqlLexer.d.ts +2 -2
  19. package/dist/lib/mysql/MySqlLexer.js +3515 -3516
  20. package/dist/lib/mysql/MySqlParser.d.ts +138 -138
  21. package/dist/lib/mysql/MySqlParser.js +511 -511
  22. package/dist/lib/mysql/MySqlParserListener.d.ts +105 -105
  23. package/dist/lib/mysql/MySqlParserVisitor.d.ts +63 -63
  24. package/dist/lib/postgresql/PostgreSqlLexer.d.ts +14 -15
  25. package/dist/lib/postgresql/PostgreSqlLexer.js +2077 -2092
  26. package/dist/lib/postgresql/PostgreSqlParser.d.ts +2860 -2980
  27. package/dist/lib/postgresql/PostgreSqlParser.js +20155 -20660
  28. package/dist/lib/postgresql/PostgreSqlParserListener.d.ts +2110 -2181
  29. package/dist/lib/postgresql/PostgreSqlParserVisitor.d.ts +1261 -1301
  30. package/dist/lib/spark/SparkSqlLexer.d.ts +2 -2
  31. package/dist/lib/spark/SparkSqlLexer.js +949 -950
  32. package/dist/lib/spark/SparkSqlParser.d.ts +413 -645
  33. package/dist/lib/spark/SparkSqlParser.js +6840 -8200
  34. package/dist/lib/spark/SparkSqlParserListener.d.ts +68 -356
  35. package/dist/lib/spark/SparkSqlParserVisitor.d.ts +42 -225
  36. package/dist/lib/trino/TrinoSqlLexer.d.ts +2 -2
  37. package/dist/lib/trino/TrinoSqlLexer.js +319 -321
  38. package/dist/lib/trino/TrinoSqlListener.d.ts +67 -23
  39. package/dist/lib/trino/TrinoSqlParser.d.ts +210 -181
  40. package/dist/lib/trino/TrinoSqlParser.js +4854 -4695
  41. package/dist/lib/trino/TrinoSqlVisitor.d.ts +42 -14
  42. package/dist/parser/common/basicSQL.d.ts +43 -9
  43. package/dist/parser/common/basicSQL.js +147 -40
  44. package/dist/parser/common/semanticContextCollector.d.ts +50 -0
  45. package/dist/parser/common/semanticContextCollector.js +202 -0
  46. package/dist/parser/common/tokenUtils.d.ts +12 -0
  47. package/dist/parser/common/tokenUtils.js +38 -0
  48. package/dist/parser/common/types.d.ts +25 -0
  49. package/dist/parser/common/types.js +7 -0
  50. package/dist/parser/flink/flinkErrorListener.js +14 -2
  51. package/dist/parser/flink/flinkSemanticContextCollector.d.ts +9 -0
  52. package/dist/parser/flink/flinkSemanticContextCollector.js +14 -0
  53. package/dist/parser/flink/index.d.ts +4 -2
  54. package/dist/parser/flink/index.js +22 -14
  55. package/dist/parser/hive/hiveErrorListener.js +9 -3
  56. package/dist/parser/hive/hiveSemanticContextCollector.d.ts +9 -0
  57. package/dist/parser/hive/hiveSemanticContextCollector.js +14 -0
  58. package/dist/parser/hive/index.d.ts +4 -2
  59. package/dist/parser/hive/index.js +29 -14
  60. package/dist/parser/impala/ImpalaErrorListener.js +8 -2
  61. package/dist/parser/impala/impalaSemanticContextCollector.d.ts +9 -0
  62. package/dist/parser/impala/impalaSemanticContextCollector.js +14 -0
  63. package/dist/parser/impala/index.d.ts +4 -2
  64. package/dist/parser/impala/index.js +21 -14
  65. package/dist/parser/mysql/index.d.ts +4 -2
  66. package/dist/parser/mysql/index.js +10 -14
  67. package/dist/parser/mysql/mysqlErrorListener.js +6 -2
  68. package/dist/parser/mysql/mysqlSemanticContextCollector.d.ts +9 -0
  69. package/dist/parser/mysql/mysqlSemanticContextCollector.js +14 -0
  70. package/dist/parser/postgresql/index.d.ts +4 -2
  71. package/dist/parser/postgresql/index.js +51 -42
  72. package/dist/parser/postgresql/postgreEntityCollector.d.ts +5 -5
  73. package/dist/parser/postgresql/postgreEntityCollector.js +7 -7
  74. package/dist/parser/postgresql/postgreErrorListener.js +36 -30
  75. package/dist/parser/postgresql/postgreSemanticContextCollector.d.ts +9 -0
  76. package/dist/parser/postgresql/postgreSemanticContextCollector.js +14 -0
  77. package/dist/parser/spark/index.d.ts +4 -2
  78. package/dist/parser/spark/index.js +26 -14
  79. package/dist/parser/spark/sparkErrorListener.js +9 -3
  80. package/dist/parser/spark/sparkSemanticContextCollector.d.ts +9 -0
  81. package/dist/parser/spark/sparkSemanticContextCollector.js +14 -0
  82. package/dist/parser/trino/index.d.ts +4 -2
  83. package/dist/parser/trino/index.js +22 -14
  84. package/dist/parser/trino/trinoErrorListener.js +9 -3
  85. package/dist/parser/trino/trinoSemanticContextCollector.d.ts +9 -0
  86. package/dist/parser/trino/trinoSemanticContextCollector.js +14 -0
  87. package/package.json +2 -1
package/README.md CHANGED
@@ -357,6 +357,57 @@ Call the `getAllEntities` method on the SQL instance, and pass in the sql text a
357
357
 
358
358
  Position is not required, if the position is passed, then in the collected entities, if the entity is located under the statement where the corresponding position is located, then the statement object to which the entity belongs will be marked with `isContainCaret`, which can help you quickly filter out the required entities when combined with the code completion function.
359
359
 
360
+ ### Get semantic context information
361
+
362
+ Call the `getSemanticContextAtCaretPosition` method on the SQL instance, passing in the sql text and the line and column numbers at the specified position, for example:
363
+
364
+ ```typescript
365
+ import { HiveSQL } from 'dt-sql-parser';
366
+
367
+ const hive = new HiveSQL();
368
+ const sql = 'SELECT * FROM tb;';
369
+ const pos = { lineNumber: 1, column: 18 }; // after 'tb;'
370
+ const semanticContext = hive.getSemanticContextAtCaretPosition(sql, pos);
371
+
372
+ console.log(semanticContext);
373
+ ```
374
+
375
+ *output*
376
+
377
+ ```typescript
378
+ /*
379
+ {
380
+ isStatementBeginning: true,
381
+ }
382
+ */
383
+ ```
384
+
385
+ Currently, the semantic context information that can be collected is as follows. If there are more requirements, please submit an [issue](https://github.com/DTStack/dt-sql-parser/issues).
386
+
387
+ - `isStatementBeginning` Whether the current input position is the beginning of a statement
388
+
389
+ The **default strategy** for `isStatementBeginning` is `SqlSplitStrategy.STRICT`
390
+
391
+ There are two optional strategies:
392
+ - `SqlSplitStrategy.STRICT` Strict strategy, only the statement delimiter `;` is used as the identifier for the end of the previous statement
393
+ - `SqlSplitStrategy.LOOSE` Loose strategy, based on the syntax parsing tree to split SQL
394
+
395
+ The difference between the two strategies:
396
+ For example, if the input SQL is:
397
+ ```sql
398
+ CREATE TABLE tb (id INT)
399
+
400
+ SELECT
401
+ ```
402
+ In the `SqlSplitStrategy.STRICT` strategy, `isStatementBeginning` is `false`, because the CREATE statement is not terminated by a semicolon.
403
+
404
+ In the `SqlSplitStrategy.LOOSE` strategy, `isStatementBeginning` is `true`, because the syntax parsing tree splits the SQL into two independent statements: CREATE and SELECT.
405
+
406
+ You can set the strategy through the third `options` parameter:
407
+ ```typescript
408
+ hive.getSemanticContextAtCaretPosition(sql, pos, { splitSqlStrategy: SqlSplitStrategy.LOOSE });
409
+ ```
410
+
360
411
  ### Other API
361
412
 
362
413
  - `createLexer` Create an instance of Antlr4 Lexer and return it;
@@ -1,7 +1,7 @@
1
1
  import * as antlr from "antlr4ng";
2
2
  export declare class FlinkSqlLexer extends antlr.Lexer {
3
- static readonly SPACE = 1;
4
- static readonly COMMENT_INPUT = 2;
3
+ static readonly WHITE_SPACE = 1;
4
+ static readonly BRACKETED_COMMENT = 2;
5
5
  static readonly LINE_COMMENT = 3;
6
6
  static readonly KW_ABS = 4;
7
7
  static readonly KW_ALL = 5;
@@ -529,11 +529,11 @@ export declare class FlinkSqlLexer extends antlr.Lexer {
529
529
  static readonly COLON_SYMB = 527;
530
530
  static readonly ASTERISK_SIGN = 528;
531
531
  static readonly UNDERLINE_SIGN = 529;
532
- static readonly HYPNEN_SIGN = 530;
532
+ static readonly HYPHEN_SIGN = 530;
533
533
  static readonly ADD_SIGN = 531;
534
- static readonly PENCENT_SIGN = 532;
534
+ static readonly PERCENT_SIGN = 532;
535
535
  static readonly DOUBLE_VERTICAL_SIGN = 533;
536
- static readonly DOUBLE_HYPNEN_SIGN = 534;
536
+ static readonly DOUBLE_HYPHEN_SIGN = 534;
537
537
  static readonly SLASH_SIGN = 535;
538
538
  static readonly QUESTION_MARK_SIGN = 536;
539
539
  static readonly DOUBLE_RIGHT_ARROW = 537;