-
Notifications
You must be signed in to change notification settings - Fork 618
[JDBC] Simplified Parser #2742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chernser
wants to merge
9
commits into
main
Choose a base branch
from
02/09/26/jdbc_lightweight_parser
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[JDBC] Simplified Parser #2742
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6310ad2
Added simpler parser
chernser be0e9be
Merge branch 'main' into 02/09/26/jdbc_lightweight_parser
chernser 7dd04d5
base implementation of lightweight parser
chernser 68ccb84
fixed most failing tests with table names
chernser 210f615
fixed all tests with table name
chernser e6af963
unit tests passing
chernser 6a71e76
added tests for writer statement with lightweight parser
chernser bd2e3a8
Merge branch 'main' into 02/09/26/jdbc_lightweight_parser
chernser 8207129
Fixed tests
chernser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
489 changes: 489 additions & 0 deletions
489
jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/parser/antlr4_light/ClickHouseLexer.g4
Large diffs are not rendered by default.
Oops, something went wrong.
190 changes: 190 additions & 0 deletions
190
...src/main/antlr4/com/clickhouse/jdbc/internal/parser/antlr4_light/ClickHouseLightParser.g4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
|
|
||
| // Simplified ClickHouse SQL parser. | ||
| // | ||
| // Design goals: | ||
| // - Filter comments (handled by the lexer: /* */, --, #!, #) | ||
| // - Detect statement verb (SELECT, SHOW, INSERT, SET, EXPLAIN, etc.) | ||
| // - For INSERT: parse table name and optional column list | ||
| // - For SET: parse completely (key = value pairs) | ||
| // - For everything else: accept any tokens without detailed parsing | ||
|
|
||
| parser grammar ClickHouseLightParser; | ||
|
|
||
| options { | ||
| tokenVocab = ClickHouseLexer; | ||
| } | ||
|
|
||
| // Top-level entry point | ||
|
|
||
| queryStmt | ||
| : insertStmt SEMICOLON? EOF # InsertQueryStmt | ||
| | setStmt SEMICOLON? EOF # SetQueryStmt | ||
| | useStmt SEMICOLON? EOF # UseQueryStmt | ||
| | otherStmt SEMICOLON? EOF # OtherQueryStmt | ||
| ; | ||
|
|
||
| // INSERT - parse table identifier and optional column list, accept rest | ||
|
|
||
| insertStmt | ||
| : INSERT INTO TABLE? tableIdentifier columnsClause? dataClause restOfQuery # InsertTableStmt | ||
| | INSERT INTO FUNCTION identifier LPAREN functionArgs RPAREN columnsClause? dataClause restOfQuery # InsertFunctionStmt | ||
| ; | ||
|
|
||
| columnsClause | ||
| : LPAREN nestedIdentifier (COMMA nestedIdentifier)* RPAREN | ||
| ; | ||
|
|
||
| functionArgs | ||
| : (LPAREN functionArgs RPAREN | ~(LPAREN | RPAREN))* | ||
| ; | ||
|
|
||
| dataClause | ||
| : FORMAT identifier # DataClauseFormat | ||
| | VALUES assignmentValues (COMMA assignmentValues)* # DataClauseValues | ||
| | (WITH | SELECT) restOfQuery # DataClauseSelect | ||
| ; | ||
|
|
||
| assignmentValues | ||
| : LPAREN assignmentValue? (COMMA assignmentValue)* RPAREN | ||
| ; | ||
|
|
||
| assignmentValue | ||
| : literal # InsertRawValue | ||
| | JDBC_PARAM_PLACEHOLDER # InsertParameter | ||
| | identifier functionArgs # InsertParameterFuncExpr | ||
| | LPAREN? .* RPAREN? # InserParameterExpr | ||
| ; | ||
|
|
||
| // SET - fully parsed | ||
|
|
||
| setStmt | ||
| : SET settingExprList | ||
| ; | ||
|
|
||
| // USE - fully parsed | ||
|
|
||
| useStmt | ||
| : USE identifier | ||
| ; | ||
|
|
||
| settingExprList | ||
| : settingExpr (COMMA settingExpr)* | ||
| ; | ||
|
|
||
| settingExpr | ||
| : identifier EQ_SINGLE (literal | JDBC_PARAM_PLACEHOLDER) | ||
| ; | ||
|
|
||
| // Any other statement - capture first verb if present, accept rest | ||
|
|
||
| otherStmt | ||
| : statementVerb restOfQuery # OtherWithVerbStmt | ||
| | restOfQuery # OtherNoVerbStmt | ||
| ; | ||
|
|
||
| statementVerb | ||
| : keyword | ||
| | IDENTIFIER | ||
| ; | ||
|
|
||
| // Consume all remaining non-semicolon tokens | ||
|
|
||
| restOfQuery | ||
| : ~SEMICOLON* | ||
| ; | ||
|
|
||
| // Table and column identifiers | ||
|
|
||
| tableIdentifier | ||
| : identifier (DOT identifier)* | ||
| ; | ||
|
|
||
| nestedIdentifier | ||
| : identifier (DOT identifier)? | ||
| ; | ||
|
|
||
| // Literals | ||
|
|
||
| literal | ||
| : numberLiteral | ||
| | STRING_LITERAL | ||
| | NULL_SQL | ||
| | JSON_TRUE | ||
| | JSON_FALSE | ||
| ; | ||
|
|
||
| numberLiteral | ||
| : (PLUS | DASH)? ( | ||
| FLOATING_LITERAL | ||
| | OCTAL_LITERAL | ||
| | DECIMAL_LITERAL | ||
| | HEXADECIMAL_LITERAL | ||
| | INF | ||
| | NAN_SQL | ||
| ) | ||
| ; | ||
|
|
||
| // Identifiers - all keywords can be used as identifiers | ||
|
|
||
| identifier | ||
| : BACKTICK_ID | ||
| | QUOTED_IDENTIFIER | ||
| | IDENTIFIER | ||
| | keyword | ||
| ; | ||
|
|
||
| // All keywords (so they can appear as table names, column names, setting names, etc.) | ||
|
|
||
| keyword | ||
| : ACCESS | ADD | ADMIN | AFTER | ALIAS | ALL | ALLOW | ALTER | AND | ANTI | ANY | ||
| | ARBITRARY | ARRAY | AS | ASCENDING | ASOF | AST | ASYNC | ASYNCHRONOUS | ATTACH | ||
| | AZURE | ||
| | BACKUP | BCRYPT_HASH | BCRYPT_PASSWORD | BETWEEN | BLOCKING | BOTH | BY | ||
| | CACHE | CACHES | CANCEL | CASE | CAST | CHANGEABLE_IN_READONLY | CHANGED | CHECK | ||
| | CLEANUP | CLEAR | CLIENT | CLUSTER | CLUSTERS | CN | CODEC | COLLATE | COLLECTION | ||
| | COLLECTIONS | COLUMN | COLUMNS | COMMENT | COMPILED | CONDITION | CONFIG | CONNECTIONS | ||
| | CONST | CONSTRAINT | CREATE | CROSS | CUBE | CURRENT | CURRENT_USER | CUSTOM | ||
| | DATABASE | DATABASES | DATE | DAY | DEDUPLICATE | DEFAULT | DEFINER | DELAY | DELETE | ||
| | DESC | DESCENDING | DESCRIBE | DETACH | DICTIONARIES | DICTIONARY | DISK | DISTINCT | ||
| | DISTRIBUTED | DNS | DOUBLE_SHA1_HASH | DOUBLE_SHA1_PASSWORD | DROP | ||
| | ELSE | EMBEDDED | ENABLED | END | ENGINE | ENGINES | ESTIMATE | EVENTS | EXCEPT | ||
| | EXCHANGE | EXISTS | EXPLAIN | EXPRESSION | EXTENDED | EXTRACT | ||
| | FAILPOINT | FETCH | FETCHES | FILE | FILESYSTEM | FILTER | FINAL | FIRST | FLUSH | ||
| | FOLLOWING | FOR | FORMAT | FREEZE | FROM | FULL | FUNCTION | FUNCTIONS | FUZZER | ||
| | GLOBAL | GRANT | GRANTEES | GRANTS | GRANULARITY | GROUP | GRPC | ||
| | HAVING | HDFS | HIERARCHICAL | HIVE | HOST | HOUR | HTTP | HTTPS | ||
| | ID | IDENTIFIED | IF | ILIKE | IMPLICIT | IN | INDEX | INDEXES | INDICES | ||
| | INHERIT | INJECTIVE | INNER | INSERT | INTERVAL | INTO | INTROSPECTION | IP | IS | ||
| | IS_OBJECT_ID | ||
| | JDBC | JEMALLOC | JOIN | JSON_FALSE | JSON_TRUE | ||
| | KAFKA | KERBEROS | KEY | KEYED | KEYS | KILL | ||
| | LAST | LAYOUT | LDAP | LEADING | LEFT | LIFETIME | LIGHTWEIGHT | LIKE | LIMIT | LIMITS | ||
| | LISTEN | LIVE | LOAD | LOADING | LOCAL | LOG | LOGS | ||
| | MANAGEMENT | MARK | MATERIALIZE | MATERIALIZED | MAX | MERGES | METRICS | MIN | MINUTE | ||
| | MMAP | MODEL | MODIFY | MONGO | MONTH | MOVE | MOVES | MUTATION | MYSQL | ||
| | NAME | NAMED | NATS | NO | NONE | NOT | NO_PASSWORD | NULLS | NULL_SQL | ||
| | ODBC | OFFSET | ON | ONLY | OPTIMIZE | OPTION | OR | ORDER | OUTER | OUTFILE | OVER | ||
| | OVERRIDE | ||
| | PAGE | PART | PARTITION | PARTS | PERMISSIVE | PIPELINE | PLAINTEXT_PASSWORD | PLAN | ||
| | POLICIES | POLICY | POPULATE | POSTGRES | POSTGRESQL | PRECEDING | PREWHERE | PRIMARY | ||
| | PROCESSLIST | PROFILE | PROFILES | PROJECTION | PROMETHEUS | PROXY | PULL | PULLING | ||
| | QUARTER | QUERIES | QUERY | QUEUE | QUEUES | QUOTA | QUOTAS | ||
| | RABBITMQ | RANDOMIZED | RANGE | READINESS | READONLY | REALM | REDIS | REDUCE | REFRESH | ||
| | REGEXP | RELOAD | REMOTE | REMOVE | RENAME | REPLACE | REPLICA | REPLICAS | REPLICATED | ||
| | REPLICATION | RESOURCE | RESTART | RESTORE | RESTRICTIVE | REVOKE | RIGHT | ROLE | ROLES | ||
| | ROLLUP | ROW | ROWS | ||
| | S3 | SAMPLE | SCHEMA | SCRAM_SHA256_HASH | SCRAM_SHA256_PASSWORD | SECOND | SECRETS | ||
| | SECURE | SECURITY | SELECT | SEMI | SENDS | SERVER | SET | SETTING | SETTINGS | ||
| | SHA256_HASH | SHA256_PASSWORD | SHARD | SHARDS | SHOW | SHUTDOWN | SOURCE | SOURCES | ||
| | SQLITE | SQL | SSH_KEY | SSL_CERTIFICATE | START | STATISTICS | STOP | STRICT | ||
| | SUBSTRING | SYNC | SYNTAX | SYSTEM | ||
| | TABLE | TABLES | TAG | TCP | TEMPORARY | TEST | THEN | THREAD | TIES | TIMEOUT | ||
| | TIMESTAMP | TO | TOP | TOTALS | TRACKING | TRAILING | TRANSACTION | TREE | TRIM | ||
| | TRUNCATE | TTL | TYPE | ||
| | UNBOUNDED | UNCOMPRESSED | UNDROP | UNFREEZE | UNION | UNLOAD | UNTIL | UPDATE | URL | ||
| | USE | USER | USERS | USING | UUID | ||
| | VALID | VALUES | VIEW | VIEWS | VIRTUAL | VOLUME | ||
| | WAIT | WATCH | WEEK | WHEN | WHERE | WINDOW | WITH | WORKLOAD | WRITABLE | ||
| | YEAR | ZKPATH | ||
| | SUM | AVG | ||
| ; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.