Skip to content

Add /dialect, /lang, /language client commands - #114568

Merged
alexey-milovidov merged 52 commits into
masterfrom
client-dialect-command
Oct 4, 2026
Merged

alexey-milovidov merged 52 commits into
masterfrom
client-dialect-command

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

Adds client-side /dialect, /lang and /language commands - an equivalent of SET dialect = '...' that is handled before parsing, so it also works when the current dialect cannot express a SET query (for example, to leave kusto or promql). The active non-default dialect is shown in the prompt, and a plain SET dialect = '...' keeps the prompt in sync.

Implementation notes:

  • The prompt is rendered by getPrompt on every line from a template that keeps the {display_name} placeholder: the current dialect is appended to the display name in parentheses (with a separating space if the display name is non-empty), and the :) smiley is appended at the end, preserving the previous behavior for the default dialect. A custom prompt without {display_name} gets the dialect appended at its end.
  • The command is interactive-only, and works in clickhouse-client, clickhouse-local, and the embedded client (SSH/web terminal). A noninteractive script is parsed as SQL from end to end, and the dialect for it is selected with the --dialect option or with a SET dialect = ... statement, as before.
  • A plain SQL SET query is now an escape hatch out of every non-ClickHouse dialect, not only out of clickhouse_json. It is recognized by actually parsing it with ParserSetQuery rather than by looking at the first token, so a valid query of the current dialect that merely starts with the word set (a PromQL metric named set) is not hijacked.
  • In a noninteractive clickhouse-local script the command is rejected with an explicit message ("available in interactive mode only") and is not suggested for a misspelled /-command; the other /-commands keep working there.
  • Documentation: a new "Switching the SQL dialect" section on the client page.
  • Test: 04892_client_dialect_command.expect.

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Added the interactive client commands /dialect, /lang, and /language to clickhouse-client and clickhouse-local, so you can switch the active SQL dialect before parsing - it also works when the current dialect cannot express a SET query, for example to leave kusto or promql. The current non-default dialect is now shown in the prompt, and a plain SET dialect = ... keeps the prompt in sync.


Workflow [PR]
Sync PR [sync-upstream/pr/114568]

Version info

  • Merged into: 26.10.1.1535-master (included in 26.10 and later)

The commands are equivalent to `SET dialect = '...'`, but are handled
on the client side before parsing, so they also work when the current
dialect cannot parse a `SET` query (for example, to leave `kusto` or
`promql`). Without an argument, `/dialect` prints the current dialect.

When the dialect is not `clickhouse`, it is displayed in the prompt
after the server display name in parentheses, with a separating space
if the display name is non-empty:

    clickhouse-cloud (polyglot) :)

Co-Authored-By: Claude Fable 5 <[email protected]>
@mintlify

mintlify Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Oct 2, 2026, 12:08 PM

@clickhouse-gh

clickhouse-gh Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [254f802]

Summary: ✅


AI Review

Summary

This revision adds interactive /dialect, /lang, and /language client commands, keeps the prompt synchronized with the active non-default dialect, generalizes the plain-SQL SET dialect = ... escape across client-side dialects, and pins parse-time settings so local/remote reparsing matches the text the client accepted. I re-read the current diff together with all prior discussion threads and did not find a remaining issue that still merits a new inline review comment.

Missing context / blind spots
  • ⚠️ I reviewed by source inspection and prior discussion only. I did not execute the interactive client binaries in this environment because there is no ready local build here; re-running 04892_client_dialect_command, 05076_ast_json_local_input_query_local_limits, 05077_client_local_slash_command_batch_mode, and 05153_client_query_local_dialect_setting would close that gap.
Final Verdict
  • ✅ No new inline findings for the current revision.

LLVM Coverage Report

Measured on commit 254f802.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 92.20% +0.10%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 205/213 (96.24%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 13, 2026
Comment thread src/Client/ClientBase.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 254f80279 with master b94acbe31 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 37a251ffa; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

14 object files changed (-71.35 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Server/ClientEmbedded/ClientEmbedded.cpp.o 298.84 KiB 145.71 KiB -153.12 KiB (-51.24%)
src/CMakeFiles/dbms.dir/Client/ClientBase.cpp.o 1.26 MiB 1.32 MiB +62.05 KiB (+4.83%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

95 translation units recompiled, 451 s compile time in total, 95 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.07 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +44.1 s (+11%) in total before that adjustment.

Job report

…name}`

`getPrompt` rendered the active dialect only through the `{display_name}`
placeholder, so a custom prompt such as `--prompt '{user}@{host}'` never
showed it. Append the indicator at the end of the prompt (before the
trailing `:) `, if any) when the prompt does not carry `{display_name}`,
and cover it with a test.

Also renumber the test to `04892_client_dialect_command` to avoid a
collision after merging `master`.
Comment thread src/Client/ClientBase.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114568&sha=4e206dd0fb7765d98b6f6e6717c4dd4ee16bad72&name_0=PR&name_1=Fast%20test and provide a fix in a separate PR. 04037_clickhouse_local_clear_command is unchanged from master and is outside this PR’s dialect-command changes. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

It is caused by this PR. The test file is unchanged from master, but the failing line goes through a path this diff adds.

The failing step is line 20, $CLICKHOUSE_LOCAL --queries-file "$qf", with clear\n in the file. On master clear is matched as a meta-command at the top of ClientBase::processQueryText (ClientBase.cpp:3593), and --queries-file for clickhouse-local routes the whole file text into processQueryText so text-level metas work. This PR inserts a new block before that matching (ClientBase.cpp:3603), guarded only by supportsLocalMetaCommands() && !is_interactive && text.contains('\n'). It line-splits the input, hands every non-/dialect line to executeMultiQuery, and returns at :3647 without reaching the meta-command matching, so clear is parsed as SQL: SELECT clear -> UNKNOWN_IDENTIFIER (47).

The only arming condition is a trailing newline, which the test's printf '%s\n' produces. That is why lines 11-14 (-q "clear", no newline) pass and only line 20 fails, matching the bashlog.

A/B with debug builds of 4e206dd0fb77 and of master, clickhouse-local --queries-file on a file holding one meta-command and a newline:

input master this PR
clear 0 47
ls 0 47
exit 0 47
quit 0 47
help 0 47

So it is not specific to clear: every text-level meta-command is broken for clickhouse-local script input ending in a newline. Control: the same file without the trailing newline exits 0 on this PR. CIDB over 180 days shows 8 failures of this test, all on client-dialect-command, none on master or any other branch.

The defect is inside this PR's own diff, so I am not opening a separate PR for it. The smallest fix I validated is to arm the new block only when the input actually contains a dialect-command line:

if (supportsLocalMetaCommands() && !is_interactive && text.contains('\n')
    && has_dialect_command_line(text))

with the existing is_dialect_command lambda hoisted above the if and a small has_dialect_command_line running it over each line. Measured: the five cases above return to 0 and the dialect splitting is unchanged, e.g.

SET allow_experimental_kusto_dialect=1;
SELECT 1;
/dialect kusto
print 2
/dialect clickhouse
SELECT 3;

prints 1, 2, 3 both with and without the patch.

Not addressed: a script mixing a text-level meta with a /dialect line still mishandles the meta, but master mishandles that input too (SYNTAX_ERROR), so it is pre-existing.

Tell me if you would rather have this as a PR against master for you to cherry-pick.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Addressed in 85ca0f7: the noninteractive clickhouse-local splitter now activates only when the script contains a standalone /dialect, /lang, or /language line. New coverage verifies that newline-terminated clear input retains its regular meta-command handling.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (one conflict in LocalConnection.cpp, master's new enable_trino_dialect parser flag now comes from the parse-time snapshot with the other parser flags) and fixed the two Fast test reds of the previous run, both with one root cause.

  • 04658_client_helper_queries_ignore_session_dialect (timeout) and 04758_distributed_dialect_forced_to_clickhouse (result differs) in a4b1c83e860f: pinOutboundDialect restored the pre-applySettingsFromQuery dialect whenever the live value differed from it, but applySettingsFromServerIfNeeded runs in between and applies the user's profile settings pushed by the server. For a user whose profile sets dialect = 'kusto', the pin forced dialect = 'clickhouse' back onto the outbound query and the server accepted SQL that the profile says must be parsed as KQL, so both positive controls (expected SYNTAX_ERROR) stopped firing. The pin now keeps only the values the query's own SETTINGS clause changed; values the query left alone are sent as the server set them, matching master. Both tests pass locally against a server built from this branch.
  • 05020_trino_dialect_errors (new on master) in 9c9f49b3901e: the clickhouse-local input() case with a query-local SETTINGS enable_trino_dialect = 0 failed with SUPPORT_IS_DISABLED because this branch overlays the client-sent settings on the local query context. enable_trino_dialect is now pinned like dialect and enable_json_ast_dialect.

Verified locally: 04348, 04349, 04658, 04758, 04892, 05019-05023 (trino), 05076, 05077, 05153, 05022_client_slash_command_hints and the 02366_kql_* family all pass.

alexey-milovidov and others added 2 commits September 23, 2026 17:46
`ParserTrinoQuery` handles every `SET` form itself, including the Trino
`SET SESSION name = value` and `SET ROLE`. The client-side escape checks only
for a valid `SET` prefix (`SET SESSION` reads as a boolean flag), so it sent
`SET SESSION max_block_size = 12345` to `ParserQuery` and failed with
`SYNTAX_ERROR`; the same statement was also pinned to `dialect = 'clickhouse'`
for the server. Exclude `trino` from both.

Fixes the `Fast test` red in `05153_trino_dialect_wrappers_and_set`:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114568&sha=a4b1c83e860f3160cbef5e28bfb55b57c51aaae8&name_0=PR&name_1=Fast%20test
PR: #114568

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (clean) and fixed the Fast test red in 10c333def9d3.

05153_trino_dialect_wrappers_and_set (a master test) failed on SET SESSION max_block_size = 12345 with SYNTAX_ERROR. This branch's client-side SQL SET escape only checks for a valid SET prefix, and SET SESSION reads as a boolean flag, so the whole statement went to ParserQuery instead of ParserTrinoQuery. The escape was also pinning dialect = 'clickhouse' on the outbound query. ParserTrinoQuery handles every SET form itself, so trino is now excluded from both the escape and the pin.

Local run: 05153_trino_dialect_wrappers_and_set, all trino/kql dialect tests, 04348/04349/04658/04758/04892/05022_client/05076/05077/05153_client pass.

Comment thread src/Client/ClientBase.cpp Resolved
alexey-milovidov and others added 3 commits October 2, 2026 11:29
# Conflicts:
#	src/Client/LocalConnection.cpp
…he other parse-time gates

The `logsql` dialect arrived from master with its own parse-time gate. A query-local
`SETTINGS allow_experimental_logsql_dialect = ...` must not change how this very query
text is parsed on the server, same as `enable_trino_dialect` and `enable_json_ast_dialect`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…to a single-command input

The diagnostic runs only when the whole input of `clickhouse-local` is the command, like the
`/`-commands themselves; inside a multi-statement script the text goes to `executeMultiQuery`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 2 commits October 4, 2026 11:04
…SET name`

The generic SQL `SET` escape probed the input with a default `ParserSetQuery`,
which accepts the shorthand `SET name` form. A `LogsQL` word filter such as
`set error | count()` or `set error` was then parsed as a SQL `SET`, failing
with a syntax error or with `Unknown setting 'error'`. The `LogsQL` parser
already has its own escape that keeps such word filters, so `logsql` is excluded
from the generic escape like `trino`, and the shorthand form is disabled in the
probe (it would also steal the KQL `set notruncation`).

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114568&sha=2b3f121b3be288818a00bf8d9efa86b50a0c2076&name_0=PR&name_1=Fast%20test
#114568

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok.

@alexey-milovidov alexey-milovidov self-assigned this Oct 4, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 4, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 4, 2026
Merged via the queue into master with commit 5d166ba Oct 4, 2026
149 checks passed
@alexey-milovidov
alexey-milovidov deleted the client-dialect-command branch October 4, 2026 20:29
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 4, 2026
alexey-milovidov added a commit to Onyx2406/ClickHouse that referenced this pull request Oct 12, 2026
…l` applying `SET profile`

The last step of the test checked that the Kusto profile was in effect for
the following queries by expecting `SELECT 1` to be rejected. Since
ClickHouse#114568, `clickhouse-local` does
not apply the settings of `SET profile` to later queries
(ClickHouse#123916, fix pending in
ClickHouse#125171), so `SELECT 1` succeeds
and the test times out in Fast test.

That step only guarded against the profile carrying nothing parser-shaping.
Check this on the profile definition in `system.settings_profile_elements`
instead, before `SET profile`, so the test holds both with and without the
`clickhouse-local` fix. The continuation assertion itself is unchanged.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101785&sha=9a99a51ef1b3008f00aff04d4b0a27d499db078d&name_0=PR&name_1=Fast%20test
PR: ClickHouse#101785

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit to groeneai/ClickHouse that referenced this pull request Oct 12, 2026
…khouse-local`

Since ClickHouse#114568, `LocalConnection::sendQuery` replaced the whole `Settings` of the
query context with the client's copy. The client does not track `profile` (its
`SET` bookkeeping skips it), so the settings a `SET profile` installed in the
session were dropped for every following query: `currentProfiles` reported the
profile, while `getSetting` showed the old values and a `readonly` profile did
not block writes. Apply only `changes` of the client settings, like `TCPHandler`.

Closes: ClickHouse#123916

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-cli clickhouse-client (interactive CLI) and client library. pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants