Repository navigation
Conversation
In single-line interactive mode, if the parser fails at end-of-input (suggesting the query is incomplete), prompt for continuation with ":-] " instead of sending the incomplete query. The user can press Enter on an empty line to submit as-is, or Ctrl+C to abort. Fixes ClickHouse#64886
After continuation lines are collected, `readLine` has already recorded only the first line in history. Call `addStringToHistory` with the combined text so the user can recall the complete multi-line query with the up-arrow key. Also add an `expect`-based stateless test that verifies: - incomplete `SELECT`, `WHERE`, and unmatched parentheses trigger the continuation prompt - empty continuation line submits the query - history contains the full combined query
…id number collision with upstream master
checkUnmatchedParentheses returns tokens for both unclosed opening brackets AND excess closing brackets. Only unclosed opens indicate an incomplete query needing continuation. Excess closing brackets (e.g., SELECT )) are syntax errors that should be sent as-is.
|
Workflow [PR], commit [4b95ed9] Summary: ✅
AI ReviewSummaryThe PR keeps incomplete interactive queries in one editable buffer. Reviewing the current diff and all prior discussion, then probing head Findings
Tests
Final Verdict |
|
This is interesting... But one thing bothers me: we should not ask for continuations with a new prompt, Also, when you copy-paste the query, usually it copy-pastes cleanly, but sometimes (under some environments) it splits into multiple continuation prompts (which I don't like). If we can avoid the continuation prompt altogether (and remove it from the code base if possible), it will be better. CC @azat |
This should not be a separate prompt. Everything should be inside a single prompt, similarly to how it is if you press Alt+Enter instead of Enter. |
… separate prompt In single-line interactive mode, pressing <ENTER> on an incomplete query (one where the parser reaches the end of input still expecting more tokens) no longer submits it and shows a syntax error. Instead, a newline is inserted into the same `replxx` edit buffer, exactly like pressing Alt+Enter, so the whole query stays under a single prompt and arrow keys can navigate and edit across all of its lines. This replaces the earlier approach that printed a separate `:-] ` continuation prompt and read additional lines in `ClientBase::runInteractive`, which prevented cross-line editing and split pasted queries. The detection (`queryNeedsContinuation`) is now passed to `ReplxxLineReader` as a callback and consulted from the `commit_action` bound to <ENTER>; a trailing delimiter such as `;` still forces submission, which is how an intentionally incomplete query is submitted to see the syntax error. The now-unused `LineReader::readOneSingleLine` and `addStringToHistory` helpers are removed. The interactive client tests are updated for the new behavior: `01180_client_syntax_errors` and `03014_invalid_utf8_client` terminate their incomplete queries with `;` to keep asserting the syntax errors, and `04085_client_single_line_continuation` verifies the single-prompt continuation. Addresses review feedback: ClickHouse#101785 (comment) ClickHouse#101785 (comment) Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pressing Ctrl+C while editing a continued (incomplete) query discards it without submitting, and the client returns to a fresh prompt and keeps accepting queries. The earlier separate-prompt implementation mapped both `ABORT` and `RESET_LINE` to an empty string, which could submit the partial query on Ctrl+C; the in-buffer approach relies on `replxx`'s standard line editing, so this case is now correct. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ware, and multi-statement-aware Addresses three issues in `queryNeedsContinuation`, which runs from the `replxx` <ENTER> key binding (outside the `try`/`catch` around `processQueryText`): - It could throw and terminate the interactive session. Some parsers throw on invalid input (e.g. `ParserPRQLQuery`, `ParserPrometheusQuery`, and SQL validation exceptions). The whole probe is now wrapped in `try`/`catch` and returns false on any exception, so the line is committed and the regular query-processing path reports the error and returns to the prompt. - An unclosed opening parenthesis forced continuation even when the buffer ended with an explicit terminator. With `--highlight 0`, `ReplxxLineReader` never sets its delimiter flag, so `SELECT (;` or `SELECT (\G` could never be submitted. The check now treats a trailing `;` or `\G` as "submit now", independently of the highlighter. - It only inspected the first statement. For a buffer like `SELECT 1; SELECT` the first statement parsed, so the buffer was committed and `SELECT 1` was executed (with possible side effects) before the incomplete second statement errored. The check now parses statements one by one and only requests continuation when the last statement is incomplete at the end of input. `04085_client_single_line_continuation` gains coverage for the terminator and multi-statement cases. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…style check Two follow-ups to the continuation completeness check: - The unmatched-opening-bracket shortcut ran before the statement was parsed, so it applied SQL bracket rules to the inline data of an INSERT. For example `INSERT INTO t FORMAT CSV (` for a `String` table inserted a row whose value starts with `(`, but in single-line interactive mode Enter inserted another newline instead of submitting. The check now runs only after a failed parse and over the current statement's text, so a successfully parsed INSERT with inline data is submitted as usual; an unclosed bracket in actual SQL still triggers continuation, and an excess closing bracket is still a real syntax error. - The deliberate `catch (...)` (which commits the line and lets `processQueryText` report the error) tripped the `catch_all` style check; annotated it with an explanatory comment. Verified: `INSERT INTO t FORMAT CSV (` submits and inserts the row; `SELECT (1` still continues; `select 1)` still reports a syntax error. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…re comments Two more follow-ups to single-line continuation: - The continuation fold preempted the explicit trailing `\` line-extender: for `SELECT (\` the unclosed `(` made Enter insert a newline inside the buffer, keeping the backslash as literal SQL and turning a supported explicit continuation into a syntax error. `commit_action` now skips the fold when the (right-trimmed) buffer ends with a configured extender, letting `readLine` commit and strip it as before. - The explicit `;` terminator was detected only as the raw last non-space text, so `SELECT (; -- force submission` was not recognized as terminated (with `--highlight 0`) and kept inserting newlines. `queryNeedsContinuation` now finds the terminator from the token stream, so it is recognized even when followed by a comment. `04085_client_single_line_continuation` gains coverage for the extender and the terminator-before-comment cases. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…line-continuation # Conflicts: # src/Client/ReplxxLineReader.cpp
The `;` terminator scan in `queryNeedsContinuation` iterated the same `Tokens` instance that the parser probe uses. Scanning to `TokenType::EndOfStream` advances `Tokens::max_pos`, so the later `token_iterator.max().type == TokenType::EndOfStream` check was already true even when the parse failed on an earlier token. As a result any line that fails to parse -- for example `exit`, `quit`, or a plain syntax error such as `select 1 foo` -- was treated as an incomplete query, so pressing Enter inserted a newline instead of submitting. This is why every interactive `.expect` test timed out: they end by sending `exit`, which was folded into the edit buffer and never committed. Use a separate `Tokens` instance for the terminator scan so it does not poison the cursor the parser relies on. Addresses the AI review 'Request changes' finding at src/Client/ClientBase.cpp. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Updated the branch: merged current Root cause. In That is why every interactive Fix. Use a separate Both changed translation units ( |
…line-continuation
`ClientBase::queryNeedsContinuation` probes whether the interactive single-line buffer is an incomplete query by parsing it, before anything is submitted. In `Dialect::kusto` that parse is not side-effect-free: `ParserKQLStatement::parseImpl` records `let` bindings in a thread-local map (and clears it on `SET dialect = ...`). So probing e.g. `let x = 1; print (` -- a complete `let` followed by an incomplete statement, which continues on the next line -- would store `x` even though the query is never submitted. In `clickhouse-local`, where parsing and execution share the same process, aborting that buffer with Ctrl+C would then leak `x` into a subsequent `print x`. Snapshot and restore the thread-local bindings around the probe when the dialect is Kusto, so the probe leaves no observable state behind while the continuation feature keeps working for KQL. Real (submitted) queries re-establish their bindings during normal execution and are unaffected. Adds an interactive `clickhouse-local` regression test that aborts an incomplete Kusto buffer and checks a later query does not observe the `let` binding. Addresses the AI review 'Request changes' finding at src/Client/ClientBase.cpp. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The `04510_kusto_continuation_no_side_effects` interactive test failed in the Fast test check because it assumed pressing Ctrl+C would discard the continued buffer and return to the prompt. In `clickhouse-local` that is not what Ctrl+C does: it exits the client (prints `Bye.`) rather than clearing the line, so after folding `let x = 1; print (` the test hit EOF and timed out waiting for the next `:) ` prompt. Verified against a real binary that Ctrl+C exits `clickhouse-local` interactive, whereas erasing the buffer with backspaces (a backspace at the start of a continued line joins it with the previous one) empties the buffer while staying under the same prompt. Rewrite the test to discard the folded buffer with backspaces, which still exercises the same code path: pressing <ENTER> runs the side-effect-prone continuation probe over `let x = 1`, the buffer is then discarded without being submitted, and a later `print x` must report `Unknown expression identifier` rather than substituting `x` -> 1. Also correct the `Ctrl+C` mention in the `queryNeedsContinuation` comment accordingly. CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101785&sha=8357e67c052e8264935d626197312c1dd3c6cbec&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
🕵 Merged |
…line-continuation
…ONSetEscape` `isClickHouseJSONSetEscape` now takes `max_parser_depth` and `max_parser_backtracks` on master; update the call in `ClientBase::queryNeedsContinuation`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ical rules in the continuation probe - `queryNeedsContinuation` probed `logsql` statements with `ParserQuery`, so e.g. `error and` (an unfinished LogsQL filter) was committed instead of folded. Build `ParserLogsQLQuery` like `parseQuery` does, and on a thrown syntax error ask the new `ParserLogsQLQuery::isIncompleteAtEOF` whether the LogsQL parser failed at the end of input. - For `promql`, the SQL-token `;` checks could take a `;` inside a PromQL comment for a terminator. Skip them and find the statement end with `PromQLStatementEndFinder` (exposed as `ParserPrometheusQuery::findStatementEnd`) before consulting `ParserPrometheusQuery::isIncompleteAtEOF`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The only CI red, the Fast test failure of Fix: #125171. With it applied locally, |
…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]>
|
🕵 Merged current The test's last step checked that the Kusto profile was in effect by expecting Ran locally on the merged tree against |
Address review: the "submit on a trailing `;`" fast path keyed off the session dialect at the start of the buffer, so after a mid-buffer `SET dialect = 'logsql'` (or `'promql'`) a `;` inside a `#` comment of the new dialect still forced submission, e.g. `SET dialect = 'logsql'; error and #keep ;` executed the `SET` with the last statement unfinished. `queryNeedsContinuation` now applies the SQL terminator to the verdict of each statement under the dialect that statement is parsed with (after the `SET` mirroring), and `ReplxxLineReader` no longer short-circuits on a raw trailing delimiter before calling the probe, which already handles `;` and `\G` itself. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Client/ReplxxLineReader.cpp # src/Client/ReplxxLineReader.h
…ment boundaries in the continuation probe `ClientBase::queryNeedsContinuation` stopped at the inline data of an `INSERT` (the parser leaves the position at the data), so in `INSERT INTO t VALUES (1); SELECT` it never saw the unfinished `SELECT` and <ENTER> executed the `INSERT`. Skip the data like `analyzeMultiQueryText` does (the skipping is moved into shared helpers `getInsertWithInlineData` and `findInsertInlineDataEnd`) and go on probing the following statements. After a KQL statement (and a JSON object) the probe advanced the SQL tokens up to the boundary found by the KQL parser, but a SQL token can straddle it: in `print @'\'; print (` the SQL lexer swallows the rest of the buffer into one unterminated string, so the unfinished `print (` was skipped. Restart the token stream at the boundary instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n real missing input - With `implicit_select`, `ParserQuery` parses `SET max_threads =` as an implicit `SELECT SET AS max_threads` with the `=` left over. When a parse stops short of the end, repeat it without `implicit_select`, so the explicit statement that failed at the end of input keeps the buffer open instead of executing an `INSERT` before it. - The SQL `SET` path of `parseKQLQuery` now says `found end of query` when the statement ends too early, like `KQLParser::failAt`, so the Kusto probe sees it. - Probe Trino statements on the output of `translateTrinoSyntax`, so `SET SESSION max_threads =` is judged as the unfinished `SET max_threads =`. - `LogsQLLexer` records whether the end of input was examined as the current token since the lexer last moved. A syntax error counts as missing input only then, so a complete but invalid `re(a,b)` or `limit abc` is submitted. - Fix the build after merging master: `allow_experimental_polyglot_dialect` is now `enable_polyglot_dialect`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d PRQL open in the continuation probe - `ParserQuery` can succeed on a prefix of a statement after an optional suffix fails at the end of input, e.g. on the `SELECT 1` of `SELECT 1 UNION ALL` (or a dangling `LEFT JOIN` / `PARALLEL WITH`). Leftover tokens after a parsed SQL statement now keep the buffer open when the parser reached the end of input, both in the main loop and in `sql_needs_more_input` (used for Trino). - The SQL bracket scan of `has_unclosed_opener` no longer stops at the first lexer error like `checkUnmatchedParentheses`: it skips error tokens and goes on to the end, so `SELECT (1!)` is submitted with its lexical error instead of folding forever. - The LogsQL lexer throws `LogsQLUnexpectedEndOfInput` (an ordinary `SYNTAX_ERROR` otherwise) when the input ends inside a backtick-quoted string. `ParserLogsQLQuery::isIncompleteAtEOF` catches it by type, which also covers a failure in the constructor, where no parser exists to ask. - The PRQL wrapper discarded the `prqlc` diagnostics, so the `unexpected end of input` check never matched. `prql_to_sql` now returns `PRQL_INCOMPLETE_AT_END_OF_INPUT` when the compiler ran out of input, and `ParserPRQLQuery::isIncompleteAtEOF` checks that code. Also fix the PRQL wrapper's test helper to use `c_char` (it did not compile on aarch64). Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Parsers/LogsQL/LogsQLLexer.h
…acks, mismatched brackets Three findings of the AI review on the single-line continuation probe `ClientBase::queryNeedsContinuation`: - After an explicit line continuation (a trailing `\`), the earlier lines are held by `LineReader::readLine` and the edit buffer only continues them, so the probe judged the last line without its beginning and possibly under the wrong dialect. `readLine` now keeps the accumulated lines in the `pending_line` member, and the <ENTER> handler of `ReplxxLineReader` probes them together with the buffer. - The probe used one `IParser::Pos` for the whole buffer, so its backtracking counter accumulated across statements, while `executeMultiQuery` parses each statement with fresh counters. A run of valid statements could exhaust `max_parser_backtracks` and submit the buffer before its unfinished last statement was examined. The counter is now reset at every statement. - A closing bracket that does not match the innermost opener, e.g. in `SELECT ([1)]` or `SELECT (1]`, left the opener counted as unclosed, so <ENTER> kept inserting newlines for a statement no input can repair. Both the SQL and the Kusto scans now treat it as a syntax error to submit. Also make `05508_client_continuation_missing_input.expect` executable like the other `.expect` tests. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Merged current Built |
What this PR does
In single-line interactive mode, pressing Enter on an incomplete query (one where the parser reaches the end of input still expecting more tokens) no longer sends it and shows a syntax error. Instead, a newline is inserted into the same edit buffer, exactly like pressing Alt+Enter, so the whole query stays under a single prompt and the arrow keys can navigate and edit across all of its lines. A trailing
;still forces submission (for example, to deliberately submit an incomplete query and see its syntax error).This replaces the earlier approach that printed a separate
:-]continuation prompt and read additional lines, which prevented cross-line editing and could split pasted queries. The completeness check is now passed toReplxxLineReaderas a callback and consulted from thecommit_actionbound to Enter.Closes: #64886
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
In single-line interactive mode,
clickhouse-clientnow keeps an incomplete query under a single prompt and lets you continue it on the next line (like pressing Alt+Enter) instead of sending it immediately.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/101785]