dt-sql-parser 4.1.0-beta.7 → 4.1.0-beta.8

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 (38) hide show
  1. package/README.md +51 -0
  2. package/dist/lib/flink/FlinkSqlParser.d.ts +2 -6
  3. package/dist/lib/flink/FlinkSqlParser.js +2122 -2211
  4. package/dist/parser/common/basicSQL.d.ts +14 -1
  5. package/dist/parser/common/basicSQL.js +14 -0
  6. package/dist/parser/common/semanticContextCollector.d.ts +51 -0
  7. package/dist/parser/common/semanticContextCollector.js +202 -0
  8. package/dist/parser/common/types.d.ts +25 -0
  9. package/dist/parser/common/types.js +7 -0
  10. package/dist/parser/flink/flinkSemanticContextCollector.d.ts +9 -0
  11. package/dist/parser/flink/flinkSemanticContextCollector.js +14 -0
  12. package/dist/parser/flink/index.d.ts +3 -1
  13. package/dist/parser/flink/index.js +5 -1
  14. package/dist/parser/hive/hiveSemanticContextCollector.d.ts +9 -0
  15. package/dist/parser/hive/hiveSemanticContextCollector.js +14 -0
  16. package/dist/parser/hive/index.d.ts +3 -1
  17. package/dist/parser/hive/index.js +5 -1
  18. package/dist/parser/impala/impalaSemanticContextCollector.d.ts +9 -0
  19. package/dist/parser/impala/impalaSemanticContextCollector.js +14 -0
  20. package/dist/parser/impala/index.d.ts +3 -1
  21. package/dist/parser/impala/index.js +5 -1
  22. package/dist/parser/mysql/index.d.ts +3 -1
  23. package/dist/parser/mysql/index.js +5 -1
  24. package/dist/parser/mysql/mysqlSemanticContextCollector.d.ts +9 -0
  25. package/dist/parser/mysql/mysqlSemanticContextCollector.js +14 -0
  26. package/dist/parser/postgresql/index.d.ts +3 -1
  27. package/dist/parser/postgresql/index.js +5 -1
  28. package/dist/parser/postgresql/postgreSemanticContextCollector.d.ts +9 -0
  29. package/dist/parser/postgresql/postgreSemanticContextCollector.js +14 -0
  30. package/dist/parser/spark/index.d.ts +3 -1
  31. package/dist/parser/spark/index.js +5 -1
  32. package/dist/parser/spark/sparkSemanticContextCollector.d.ts +9 -0
  33. package/dist/parser/spark/sparkSemanticContextCollector.js +14 -0
  34. package/dist/parser/trino/index.d.ts +3 -1
  35. package/dist/parser/trino/index.js +5 -1
  36. package/dist/parser/trino/trinoSemanticContextCollector.d.ts +9 -0
  37. package/dist/parser/trino/trinoSemanticContextCollector.js +14 -0
  38. package/package.json +1 -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;
@@ -1420,16 +1420,14 @@ export declare class MapTypeDimensionContext extends antlr.ParserRuleContext {
1420
1420
  }
1421
1421
  export declare class RowTypeDimensionContext extends antlr.ParserRuleContext {
1422
1422
  constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
1423
- LESS_SYMBOL(): antlr.TerminalNode | null;
1423
+ LESS_SYMBOL(): antlr.TerminalNode;
1424
1424
  columnName(): ColumnNameContext[];
1425
1425
  columnName(i: number): ColumnNameContext | null;
1426
1426
  columnType(): ColumnTypeContext[];
1427
1427
  columnType(i: number): ColumnTypeContext | null;
1428
- GREATER_SYMBOL(): antlr.TerminalNode | null;
1428
+ GREATER_SYMBOL(): antlr.TerminalNode;
1429
1429
  COMMA(): antlr.TerminalNode[];
1430
1430
  COMMA(i: number): antlr.TerminalNode | null;
1431
- LR_BRACKET(): antlr.TerminalNode | null;
1432
- RR_BRACKET(): antlr.TerminalNode | null;
1433
1431
  get ruleIndex(): number;
1434
1432
  enterRule(listener: FlinkSqlParserListener): void;
1435
1433
  exitRule(listener: FlinkSqlParserListener): void;
@@ -2488,8 +2486,6 @@ export declare class PartitionByClauseContext extends antlr.ParserRuleContext {
2488
2486
  KW_BY(): antlr.TerminalNode;
2489
2487
  columnName(): ColumnNameContext[];
2490
2488
  columnName(i: number): ColumnNameContext | null;
2491
- primaryExpression(): PrimaryExpressionContext[];
2492
- primaryExpression(i: number): PrimaryExpressionContext | null;
2493
2489
  COMMA(): antlr.TerminalNode[];
2494
2490
  COMMA(i: number): antlr.TerminalNode | null;
2495
2491
  get ruleIndex(): number;