Skip to content

Commit 107ba2d

Browse files
authored
feat: add generic SQL language support (#469)
* fix(generic): fix INTERSECT/EXCEPT support, trim keywords to ~90 - Add INTERSECT and EXCEPT to queryNoWith rule for set operations - Remove 173 unused KW_* lexer rules for removed features (views, indexes, grants, transactions, stored procedures, window functions, triggers, etc.) - Trim nonReserved list to only keywords actually used in parser rules - Remove unused UNICODE_STRING and DIGIT_IDENTIFIER lexer rules - Keyword count reduced from 263 to 90 (close to ~100 target) - All 197 test suites pass (5627 tests) * fix(generic): reserve core structural keywords and add DIGIT_IDENTIFIER - Remove core structural keywords from nonReserved so they cannot be used as identifiers: SELECT, FROM, WHERE, CREATE, TABLE, INSERT, UPDATE, DELETE, DROP, ALTER, SET, JOIN, GROUP, HAVING, ORDER, ON, UNION, INTERSECT, EXCEPT, INTO, NOT, AND, OR, IN, BETWEEN, LIKE, IS, EXISTS, CASE, WHEN, THEN, ELSE, END, CAST, AS, DISTINCT, PRIMARY, CONSTRAINT, REFERENCES, COLUMN, UNIQUE, CHECK, FOREIGN, RENAME, RECURSIVE, WITH, NULL, ESCAPE, NULLIF - Add DIGIT_IDENTIFIER lexer token for identifiers starting with a digit (e.g. 123abc, 1st_column) - Include DIGIT_IDENTIFIER in identifier rule alternatives * fix(generic): add missing Listener/Visitor exports and diagnostics option - Add GenericSqlListener and GenericSqlVisitor exports to src/index.ts - Add GenericSQLOptions interface with configurable diagnostics flag - Override validate() to return empty array when diagnostics disabled - Export GenericSQLOptions type from src/index.ts * fix(generic): add QUERY_RESULT and SELECT column entity collection - Add exitQuerySpecification for QUERY_RESULT entity tracking - Add exitSelectItem for column entity collection in SELECT clauses - Track wildcard columns (ColumnDeclareType.ALL) for * and table.* - Track expression columns with alias support (ColumnDeclareType.EXPRESSION) - Stage previously untracked files (errorListener, splitListener, semanticContextCollector) * test: add GenericSQL tests * test: ensure all dialect tests pass with GenericSQL * test(generic): add more sql test - Add comprehensive syntax tests for all supported statement types - Add context collect tests for entity and semantic collectors - Add suggestion tests for token, syntax, and multi-statement scenarios - Add error strategy, listener, visitor, and validation tests - Fix entity collector to distinguish simple columns from expressions
1 parent 0041ed2 commit 107ba2d

62 files changed

Lines changed: 15600 additions & 4 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README-zh_CN.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dt-sql-parser 是一个基于 [ANTLR4](https://github.com/antlr/antlr4) 开发
2626
- PostgreSQL
2727
- Trino
2828
- Impala
29+
- GenericSQL
2930

3031
> 提示:当前所有的 SQL Parser 是 `Typescript` 语言版本,如果有需要,可以尝试编译 Grammar 文件到其他目标语言。
3132
@@ -51,7 +52,7 @@ yarn add dt-sql-parser
5152
## 使用
5253
在开始使用前,需要先了解基本用法。`dt-sql-parser` 为不同类型的 SQL 分别提供相应的 SQL 类:
5354
```typescript
54-
import { MySQL, FlinkSQL, SparkSQL, HiveSQL, PostgreSQL, TrinoSQL, ImpalaSQL } from 'dt-sql-parser';
55+
import { MySQL, FlinkSQL, SparkSQL, HiveSQL, PostgreSQL, TrinoSQL, ImpalaSQL, GenericSQL } from 'dt-sql-parser';
5556
```
5657

5758
在使用语法校验,自动补全等功能之前,需要先实例化对应 SQL 类,以 `MySQL` 为例:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Additionally, it provides advanced features such as **SQL Validation**, **Code C
2626
- PostgreSQL
2727
- Trino
2828
- Impala
29+
- GenericSQL
2930

3031
>[!TIP]
3132
>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
5354
## Usage
5455
We recommend learning the fundamentals usage before continuing. The dt-sql-parser library provides SQL classes for different types of SQL.
5556
```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';
5758
```
5859

5960
Before using syntax validation, code completion, and other features, it is necessary to instantiate the Parser of the relevant SQL type.

0 commit comments

Comments
 (0)