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.
- package/README.md +51 -0
- package/dist/lib/flink/FlinkSqlLexer.d.ts +5 -5
- package/dist/lib/flink/FlinkSqlLexer.js +1991 -1992
- package/dist/lib/flink/FlinkSqlParser.d.ts +240 -230
- package/dist/lib/flink/FlinkSqlParser.js +3036 -2978
- package/dist/lib/flink/FlinkSqlParserListener.d.ts +81 -70
- package/dist/lib/flink/FlinkSqlParserVisitor.d.ts +49 -42
- package/dist/lib/hive/HiveSqlParser.d.ts +251 -231
- package/dist/lib/hive/HiveSqlParser.js +6264 -5674
- package/dist/lib/hive/HiveSqlParserListener.d.ts +32 -10
- package/dist/lib/hive/HiveSqlParserVisitor.d.ts +20 -6
- package/dist/lib/impala/ImpalaSqlLexer.d.ts +2 -2
- package/dist/lib/impala/ImpalaSqlLexer.js +587 -588
- package/dist/lib/impala/ImpalaSqlParser.d.ts +151 -113
- package/dist/lib/impala/ImpalaSqlParser.js +3464 -3250
- package/dist/lib/impala/ImpalaSqlParserListener.d.ts +49 -5
- package/dist/lib/impala/ImpalaSqlParserVisitor.d.ts +31 -3
- package/dist/lib/mysql/MySqlLexer.d.ts +2 -2
- package/dist/lib/mysql/MySqlLexer.js +3515 -3516
- package/dist/lib/mysql/MySqlParser.d.ts +138 -138
- package/dist/lib/mysql/MySqlParser.js +511 -511
- package/dist/lib/mysql/MySqlParserListener.d.ts +105 -105
- package/dist/lib/mysql/MySqlParserVisitor.d.ts +63 -63
- package/dist/lib/postgresql/PostgreSqlLexer.d.ts +14 -15
- package/dist/lib/postgresql/PostgreSqlLexer.js +2077 -2092
- package/dist/lib/postgresql/PostgreSqlParser.d.ts +2860 -2980
- package/dist/lib/postgresql/PostgreSqlParser.js +20155 -20660
- package/dist/lib/postgresql/PostgreSqlParserListener.d.ts +2110 -2181
- package/dist/lib/postgresql/PostgreSqlParserVisitor.d.ts +1261 -1301
- package/dist/lib/spark/SparkSqlLexer.d.ts +2 -2
- package/dist/lib/spark/SparkSqlLexer.js +949 -950
- package/dist/lib/spark/SparkSqlParser.d.ts +413 -645
- package/dist/lib/spark/SparkSqlParser.js +6840 -8200
- package/dist/lib/spark/SparkSqlParserListener.d.ts +68 -356
- package/dist/lib/spark/SparkSqlParserVisitor.d.ts +42 -225
- package/dist/lib/trino/TrinoSqlLexer.d.ts +2 -2
- package/dist/lib/trino/TrinoSqlLexer.js +319 -321
- package/dist/lib/trino/TrinoSqlListener.d.ts +67 -23
- package/dist/lib/trino/TrinoSqlParser.d.ts +210 -181
- package/dist/lib/trino/TrinoSqlParser.js +4854 -4695
- package/dist/lib/trino/TrinoSqlVisitor.d.ts +42 -14
- package/dist/parser/common/basicSQL.d.ts +43 -9
- package/dist/parser/common/basicSQL.js +147 -40
- package/dist/parser/common/semanticContextCollector.d.ts +50 -0
- package/dist/parser/common/semanticContextCollector.js +202 -0
- package/dist/parser/common/tokenUtils.d.ts +12 -0
- package/dist/parser/common/tokenUtils.js +38 -0
- package/dist/parser/common/types.d.ts +25 -0
- package/dist/parser/common/types.js +7 -0
- package/dist/parser/flink/flinkErrorListener.js +14 -2
- package/dist/parser/flink/flinkSemanticContextCollector.d.ts +9 -0
- package/dist/parser/flink/flinkSemanticContextCollector.js +14 -0
- package/dist/parser/flink/index.d.ts +4 -2
- package/dist/parser/flink/index.js +22 -14
- package/dist/parser/hive/hiveErrorListener.js +9 -3
- package/dist/parser/hive/hiveSemanticContextCollector.d.ts +9 -0
- package/dist/parser/hive/hiveSemanticContextCollector.js +14 -0
- package/dist/parser/hive/index.d.ts +4 -2
- package/dist/parser/hive/index.js +29 -14
- package/dist/parser/impala/ImpalaErrorListener.js +8 -2
- package/dist/parser/impala/impalaSemanticContextCollector.d.ts +9 -0
- package/dist/parser/impala/impalaSemanticContextCollector.js +14 -0
- package/dist/parser/impala/index.d.ts +4 -2
- package/dist/parser/impala/index.js +21 -14
- package/dist/parser/mysql/index.d.ts +4 -2
- package/dist/parser/mysql/index.js +10 -14
- package/dist/parser/mysql/mysqlErrorListener.js +6 -2
- package/dist/parser/mysql/mysqlSemanticContextCollector.d.ts +9 -0
- package/dist/parser/mysql/mysqlSemanticContextCollector.js +14 -0
- package/dist/parser/postgresql/index.d.ts +4 -2
- package/dist/parser/postgresql/index.js +51 -42
- package/dist/parser/postgresql/postgreEntityCollector.d.ts +5 -5
- package/dist/parser/postgresql/postgreEntityCollector.js +7 -7
- package/dist/parser/postgresql/postgreErrorListener.js +36 -30
- package/dist/parser/postgresql/postgreSemanticContextCollector.d.ts +9 -0
- package/dist/parser/postgresql/postgreSemanticContextCollector.js +14 -0
- package/dist/parser/spark/index.d.ts +4 -2
- package/dist/parser/spark/index.js +26 -14
- package/dist/parser/spark/sparkErrorListener.js +9 -3
- package/dist/parser/spark/sparkSemanticContextCollector.d.ts +9 -0
- package/dist/parser/spark/sparkSemanticContextCollector.js +14 -0
- package/dist/parser/trino/index.d.ts +4 -2
- package/dist/parser/trino/index.js +22 -14
- package/dist/parser/trino/trinoErrorListener.js +9 -3
- package/dist/parser/trino/trinoSemanticContextCollector.d.ts +9 -0
- package/dist/parser/trino/trinoSemanticContextCollector.js +14 -0
- 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
|
|
4
|
-
static readonly
|
|
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
|
|
532
|
+
static readonly HYPHEN_SIGN = 530;
|
|
533
533
|
static readonly ADD_SIGN = 531;
|
|
534
|
-
static readonly
|
|
534
|
+
static readonly PERCENT_SIGN = 532;
|
|
535
535
|
static readonly DOUBLE_VERTICAL_SIGN = 533;
|
|
536
|
-
static readonly
|
|
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;
|