dt-sql-parser 4.5.0-beta.2 → 4.5.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 +2 -1
- package/dist/lib/SQLParserBase.d.ts +13 -1
- package/dist/lib/SQLParserBase.js +40 -5
- package/dist/lib/flink/FlinkSqlLexer.d.ts +399 -397
- package/dist/lib/flink/FlinkSqlLexer.js +2504 -2489
- package/dist/lib/flink/FlinkSqlParser.d.ts +773 -578
- package/dist/lib/flink/FlinkSqlParser.js +5657 -3651
- package/dist/lib/flink/FlinkSqlParserListener.d.ts +123 -0
- package/dist/lib/flink/FlinkSqlParserVisitor.d.ts +78 -0
- package/dist/lib/hive/HiveSqlParser.d.ts +274 -228
- package/dist/lib/hive/HiveSqlParser.js +6304 -5912
- package/dist/lib/hive/HiveSqlParserListener.d.ts +33 -0
- package/dist/lib/hive/HiveSqlParserVisitor.d.ts +21 -0
- package/dist/lib/impala/ImpalaSqlParser.d.ts +145 -103
- package/dist/lib/impala/ImpalaSqlParser.js +3687 -3320
- package/dist/lib/impala/ImpalaSqlParserListener.d.ts +33 -0
- package/dist/lib/impala/ImpalaSqlParserVisitor.d.ts +21 -0
- package/dist/lib/mysql/MySqlParser.d.ts +161 -94
- package/dist/lib/mysql/MySqlParser.js +9959 -9499
- package/dist/lib/mysql/MySqlParserListener.d.ts +79 -5
- package/dist/lib/mysql/MySqlParserVisitor.d.ts +49 -3
- package/dist/lib/postgresql/PostgreSqlParser.d.ts +108 -71
- package/dist/lib/postgresql/PostgreSqlParser.js +13330 -10388
- package/dist/lib/postgresql/PostgreSqlParserListener.d.ts +48 -0
- package/dist/lib/postgresql/PostgreSqlParserVisitor.d.ts +30 -0
- package/dist/lib/spark/SparkSqlParser.d.ts +186 -146
- package/dist/lib/spark/SparkSqlParser.js +5368 -5095
- package/dist/lib/spark/SparkSqlParserListener.d.ts +33 -0
- package/dist/lib/spark/SparkSqlParserVisitor.d.ts +21 -0
- package/dist/lib/trino/TrinoSqlLexer.d.ts +297 -296
- package/dist/lib/trino/TrinoSqlLexer.js +1451 -1445
- package/dist/lib/trino/TrinoSqlListener.d.ts +13 -0
- package/dist/lib/trino/TrinoSqlParser.d.ts +308 -297
- package/dist/lib/trino/TrinoSqlParser.js +2381 -2300
- package/dist/lib/trino/TrinoSqlVisitor.d.ts +8 -0
- package/dist/parser/common/basicSQL.d.ts +17 -5
- package/dist/parser/common/basicSQL.js +74 -3
- package/dist/parser/common/entityCollector.js +14 -2
- package/dist/parser/flink/index.js +5 -2
- package/dist/parser/generic/genericEntityCollector.d.ts +1 -0
- package/dist/parser/generic/genericEntityCollector.js +14 -1
- package/dist/parser/mysql/index.js +3 -1
- package/dist/parser/mysql/mysqlEntityCollector.d.ts +2 -1
- package/dist/parser/mysql/mysqlEntityCollector.js +13 -3
- package/dist/parser/mysql/mysqlErrorListener.js +2 -0
- package/dist/parser/postgresql/postgreEntityCollector.d.ts +3 -1
- package/dist/parser/postgresql/postgreEntityCollector.js +13 -0
- package/dist/parser/spark/index.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ Additionally, it provides advanced features such as **SQL Validation**, **Code C
|
|
|
26
26
|
- PostgreSQL
|
|
27
27
|
- Trino
|
|
28
28
|
- Impala
|
|
29
|
+
- GenericSQL
|
|
29
30
|
|
|
30
31
|
>[!TIP]
|
|
31
32
|
>This project is the default for Typescript target, also you can try to compile it to other languages if you need.
|
|
@@ -53,7 +54,7 @@ yarn add dt-sql-parser
|
|
|
53
54
|
## Usage
|
|
54
55
|
We recommend learning the fundamentals usage before continuing. The dt-sql-parser library provides SQL classes for different types of SQL.
|
|
55
56
|
```javascript
|
|
56
|
-
import { MySQL, FlinkSQL, SparkSQL, HiveSQL, PostgreSQL, TrinoSQL, ImpalaSQL } from 'dt-sql-parser';
|
|
57
|
+
import { MySQL, FlinkSQL, SparkSQL, HiveSQL, PostgreSQL, TrinoSQL, ImpalaSQL, GenericSQL } from 'dt-sql-parser';
|
|
57
58
|
```
|
|
58
59
|
|
|
59
60
|
Before using syntax validation, code completion, and other features, it is necessary to instantiate the Parser of the relevant SQL type.
|
|
@@ -4,5 +4,17 @@ export declare abstract class SQLParserBase<T = antlr.ParserRuleContext> extends
|
|
|
4
4
|
abstract program(): T;
|
|
5
5
|
caretTokenIndex: number;
|
|
6
6
|
entityCollecting: boolean;
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Semantic predicate to determine whether to match empty column.
|
|
9
|
+
*
|
|
10
|
+
* Key design:
|
|
11
|
+
* 1. Only match empty column in entityCollecting mode
|
|
12
|
+
* 2. Check if caret position is at the empty column position
|
|
13
|
+
* 3. In validate mode (entityCollecting=false), this predicate returns false
|
|
14
|
+
* and reports an error to ensure incomplete SQL is caught
|
|
15
|
+
*
|
|
16
|
+
* IMPORTANT: This predicate should be used carefully to avoid affecting
|
|
17
|
+
* prediction in non-entity-collecting contexts.
|
|
18
|
+
*/
|
|
19
|
+
shouldMatchEmpty(ruleName?: string): boolean;
|
|
8
20
|
}
|
|
@@ -5,10 +5,45 @@ export class SQLParserBase extends antlr.Parser {
|
|
|
5
5
|
this.caretTokenIndex = -1;
|
|
6
6
|
this.entityCollecting = false;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Semantic predicate to determine whether to match empty column.
|
|
10
|
+
*
|
|
11
|
+
* Key design:
|
|
12
|
+
* 1. Only match empty column in entityCollecting mode
|
|
13
|
+
* 2. Check if caret position is at the empty column position
|
|
14
|
+
* 3. In validate mode (entityCollecting=false), this predicate returns false
|
|
15
|
+
* and reports an error to ensure incomplete SQL is caught
|
|
16
|
+
*
|
|
17
|
+
* IMPORTANT: This predicate should be used carefully to avoid affecting
|
|
18
|
+
* prediction in non-entity-collecting contexts.
|
|
19
|
+
*/
|
|
20
|
+
shouldMatchEmpty(ruleName) {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
// Only match in entityCollecting mode or when caret position is specified (suggestion mode)
|
|
23
|
+
if (this.entityCollecting || this.caretTokenIndex >= 0) {
|
|
24
|
+
// If no caret position specified, match all empty columns
|
|
25
|
+
if (this.caretTokenIndex < 0) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
// Check if caret is at the position where empty column would be
|
|
29
|
+
const prevTokenIndex = (_a = this.tokenStream.LT(-1)) === null || _a === void 0 ? void 0 : _a.tokenIndex;
|
|
30
|
+
const nextTokenIndex = (_b = this.tokenStream.LT(1)) === null || _b === void 0 ? void 0 : _b.tokenIndex;
|
|
31
|
+
// Match if caret is between previous and next token
|
|
32
|
+
if (prevTokenIndex !== undefined && nextTokenIndex !== undefined) {
|
|
33
|
+
return prevTokenIndex <= this.caretTokenIndex && nextTokenIndex >= this.caretTokenIndex;
|
|
34
|
+
}
|
|
35
|
+
// If only previous token exists, match if caret is after it
|
|
36
|
+
if (prevTokenIndex !== undefined) {
|
|
37
|
+
return prevTokenIndex <= this.caretTokenIndex;
|
|
38
|
+
}
|
|
39
|
+
// If only next token exists, match if caret is before it
|
|
40
|
+
if (nextTokenIndex !== undefined) {
|
|
41
|
+
return nextTokenIndex >= this.caretTokenIndex;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
// In pure validate mode, don't match empty columns
|
|
46
|
+
// This allows ANTLR to report errors naturally
|
|
47
|
+
return false;
|
|
13
48
|
}
|
|
14
49
|
}
|