dt-sql-parser 4.1.0-beta.6 → 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.
- package/README.md +51 -0
- package/dist/lib/flink/FlinkSqlParser.d.ts +2 -6
- package/dist/lib/flink/FlinkSqlParser.js +1232 -1289
- package/dist/parser/common/basicSQL.d.ts +31 -1
- package/dist/parser/common/basicSQL.js +67 -22
- package/dist/parser/common/parseErrorListener.d.ts +5 -3
- package/dist/parser/common/parseErrorListener.js +6 -2
- package/dist/parser/common/semanticContextCollector.d.ts +51 -0
- package/dist/parser/common/semanticContextCollector.js +202 -0
- package/dist/parser/common/types.d.ts +25 -0
- package/dist/parser/common/types.js +7 -0
- package/dist/parser/flink/flinkErrorListener.d.ts +1 -4
- package/dist/parser/flink/flinkErrorListener.js +14 -5
- package/dist/parser/flink/flinkSemanticContextCollector.d.ts +9 -0
- package/dist/parser/flink/flinkSemanticContextCollector.js +14 -0
- package/dist/parser/flink/index.d.ts +3 -1
- package/dist/parser/flink/index.js +7 -2
- package/dist/parser/hive/hiveErrorListener.d.ts +1 -4
- package/dist/parser/hive/hiveErrorListener.js +14 -5
- package/dist/parser/hive/hiveSemanticContextCollector.d.ts +9 -0
- package/dist/parser/hive/hiveSemanticContextCollector.js +14 -0
- package/dist/parser/hive/index.d.ts +3 -1
- package/dist/parser/hive/index.js +7 -2
- package/dist/parser/impala/ImpalaErrorListener.d.ts +1 -4
- package/dist/parser/impala/ImpalaErrorListener.js +14 -5
- package/dist/parser/impala/impalaSemanticContextCollector.d.ts +9 -0
- package/dist/parser/impala/impalaSemanticContextCollector.js +14 -0
- package/dist/parser/impala/index.d.ts +3 -1
- package/dist/parser/impala/index.js +7 -2
- package/dist/parser/mysql/index.d.ts +3 -1
- package/dist/parser/mysql/index.js +7 -2
- package/dist/parser/mysql/mysqlErrorListener.d.ts +1 -4
- package/dist/parser/mysql/mysqlErrorListener.js +14 -5
- package/dist/parser/mysql/mysqlSemanticContextCollector.d.ts +9 -0
- package/dist/parser/mysql/mysqlSemanticContextCollector.js +14 -0
- package/dist/parser/postgresql/index.d.ts +3 -1
- package/dist/parser/postgresql/index.js +7 -2
- package/dist/parser/postgresql/postgreErrorListener.d.ts +1 -4
- package/dist/parser/postgresql/postgreErrorListener.js +14 -5
- package/dist/parser/postgresql/postgreSemanticContextCollector.d.ts +9 -0
- package/dist/parser/postgresql/postgreSemanticContextCollector.js +14 -0
- package/dist/parser/spark/index.d.ts +3 -1
- package/dist/parser/spark/index.js +7 -2
- package/dist/parser/spark/sparkErrorListener.d.ts +1 -4
- package/dist/parser/spark/sparkErrorListener.js +14 -5
- package/dist/parser/spark/sparkSemanticContextCollector.d.ts +9 -0
- package/dist/parser/spark/sparkSemanticContextCollector.js +14 -0
- package/dist/parser/trino/index.d.ts +3 -1
- package/dist/parser/trino/index.js +7 -2
- package/dist/parser/trino/trinoErrorListener.d.ts +1 -4
- package/dist/parser/trino/trinoErrorListener.js +14 -5
- package/dist/parser/trino/trinoSemanticContextCollector.d.ts +9 -0
- package/dist/parser/trino/trinoSemanticContextCollector.js +14 -0
- 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,14 +1420,12 @@ 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;
|
|
1423
1424
|
columnName(): ColumnNameContext[];
|
|
1424
1425
|
columnName(i: number): ColumnNameContext | null;
|
|
1425
1426
|
columnType(): ColumnTypeContext[];
|
|
1426
1427
|
columnType(i: number): ColumnTypeContext | null;
|
|
1427
|
-
|
|
1428
|
-
LESS_SYMBOL(): antlr.TerminalNode | null;
|
|
1429
|
-
RR_BRACKET(): antlr.TerminalNode | null;
|
|
1430
|
-
GREATER_SYMBOL(): antlr.TerminalNode | null;
|
|
1428
|
+
GREATER_SYMBOL(): antlr.TerminalNode;
|
|
1431
1429
|
COMMA(): antlr.TerminalNode[];
|
|
1432
1430
|
COMMA(i: number): antlr.TerminalNode | null;
|
|
1433
1431
|
get ruleIndex(): number;
|
|
@@ -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;
|