Repository navigation
Conversation
ccoltx
force-pushed
the
lexer/6-format-before-settings
branch
from
October 21, 2026 16:08
3c036e8 to
c07bdb3
Compare
This was referenced Oct 21, 2026
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
ccoltx
force-pushed
the
lexer/6-format-before-settings
branch
from
October 21, 2026 16:19
c07bdb3 to
cfa3798
Compare
|
Docs drift check: this PR looks like it needs doc updates.
|
ccoltx
force-pushed
the
lexer/6-format-before-settings
branch
from
October 21, 2026 18:32
cfa3798 to
93dec69
Compare
…lause When the query ends with a top-level SETTINGS name = value list, query() now sends `... FORMAT x SETTINGS ...` instead of `... SETTINGS ... FORMAT x`, which some older servers reject (#970). SETTINGS inside brackets, strings or comments, a column named settings, and a SETTINGS clause followed by more of the query are left alone. Without sql_lexer nothing changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ccoltx
force-pushed
the
lexer/6-format-before-settings
branch
from
October 21, 2026 18:43
93dec69 to
5e17136
Compare
Contributor
Author
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Tracking issue: #1074. Stack: #1065 → #1066 → #1067 → #1068 → #1069 → #1070 → #1071 → #1072
Part 6 of the lexer stack. Depends on #1069. Addresses #970 for users who set
sql_lexer. Supersedes the hand-written scanner in #972 on this path.Why
query()always appendsFORMAT <format>at the end. When the user's query ends with aSETTINGSclause, the result is... SETTINGS k = v FORMAT JSON. Older servers (e.g. 23.3, forDESCRIBE format(...)) requireSETTINGSto come last and reject this. Current servers accept both orders (#970).What
In the lexer rewriter's
withFormat, FORMAT goes right before theSETTINGSkeyword when all of these hold:SETTINGS;name = value, ...list. A value may be several tokens, such as-1,'x',trueor[1, 2].Otherwise FORMAT is appended at the end as before. That's the case for:
settings;`SETTINGS`;... SETTINGS a = 1 UNION ALL SELECT 2;Also:
withFormattokenizes the query only once. New token kinds:equals,comma.sql_lexerJSDoc;query()JSDoc, which no longer says FORMAT always goes at the end;docs/howto/sql_lexer.md;Testing
sql_lexer_rewriter.test.ts: 8 cases where FORMAT moves before SETTINGS, including the [backfill: ClickHouse/clickhouse-js] client.query() unconditionally appends FORMAT after user SETTINGS clause, producing invalid SQL on older ClickHouse servers #970DESC format(...)reproduction, a line comment before SETTINGS, and a comment after it. Also 12 cases where it must stay at the end.sql_rewriting.test.ts: the [backfill: ClickHouse/clickhouse-js] client.query() unconditionally appends FORMAT after user SETTINGS clause, producing invalid SQL on older ClickHouse servers #970 rows show the old output without the lexer and the fixed output with it.headimage) in both Node and the browser. Full Node (316) and web (199) integration suites pass.CLICKHOUSE_VERSION=23.3), where the original [backfill: ClickHouse/clickhouse-js] client.query() unconditionally appends FORMAT after user SETTINGS clause, producing invalid SQL on older ClickHouse servers #970 failure happens. Current servers accept both orders, so the integration test only shows that the new order works.🤖 Generated with Claude Code