Skip to content

Ask for continuation in single-line mode when query is incomplete - #101785

Open
Onyx2406 wants to merge 60 commits into
ClickHouse:masterfrom
Onyx2406:feat/client-single-line-continuation
Open

Onyx2406 wants to merge 60 commits into
ClickHouse:masterfrom
Onyx2406:feat/client-single-line-continuation

Conversation

@Onyx2406

@Onyx2406 Onyx2406 commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

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 to ReplxxLineReader as a callback and consulted from the commit_action bound to Enter.

Closes: #64886

Changelog category (leave one):

  • Improvement

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

In single-line interactive mode, clickhouse-client now 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

  • Documentation is written (not required for this change)

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

Onyx2406 added 4 commits April 4, 2026 18:41
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
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.
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Apr 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4b95ed9]

Summary: ✅


AI Review

Summary

The PR keeps incomplete interactive queries in one editable buffer. Reviewing the current diff and all prior discussion, then probing head 4b95ed91f50e with its Fast test binary, found three remaining continuation errors. Request changes despite the green CI results.

Findings

⚠️ Majors

  • src/Client/ReplxxLineReader.cpp:665: Explicit continuation omits the accumulated query. With implicit_select=0, enter INSERT INTO t VALUES (1); SET dialect = 'kusto'; \, then print at :-] . The probe sees only print under SQL; the client submits the accumulated buffer, inserts a row, changes dialect, and reports the unfinished Kusto statement. The subsequent table count is 1. Include all pending text in the probe, or retain explicit continuations in the same edit buffer.
  • src/Client/ClientBase.cpp:4316: Backtracking limits accumulate across statements. With implicit_select=0 and max_parser_backtracks=100, thirty repetitions of SELECT (1); followed by unfinished SELECT submit and execute the prefixes. The shared IParser::Pos exhausts its cumulative budget before reaching the tail, although each statement fits the executor's fresh per-statement budget. Reset parser counters at every statement boundary, including raw-text/data restarts and mirrored SET transitions.
  • src/Client/ClientBase.cpp:4251: Mismatched closers hide terminal syntax errors. SELECT ([1)] and Kusto's print ([1)] keep inserting newlines on repeated Enter presses; ; finally reports the error. Breaking the scan leaves the opener stack nonempty, although additional input cannot repair the sequence. Return false for mismatched closers in both the SQL and Kusto scans.
Tests
  • ⚠️ Add focused interactive regressions for discarding an unfinished buffer after explicit \ continuation, an unfinished tail after several individually valid statements under a small backtracking limit, and immediate submission of mismatched brackets in SQL and Kusto. The current tests miss these reproduced failures.
Final Verdict

⚠️ Request changes. Preserve the complete pending query, use per-statement parser budgets, and distinguish mismatched brackets from missing input; cover these behaviors with interactive regressions.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Apr 5, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

This is interesting... But one thing bothers me: we should not ask for continuations with a new prompt, :-], because it prevents navigating and editing across different lines of the query. Compare to the case when you enter a new line by pressing "Alt+Enter" ("Option+Enter") - it is much cleaner.

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

Comment thread src/Client/LineReader.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member

This PR adds automatic continuation prompting (:-])

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.

alexey-milovidov and others added 3 commits June 18, 2026 23:51
… 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]>
Comment thread src/Client/ClientBase.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
…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]>
Comment thread src/Client/ClientBase.cpp Resolved
…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]>
Comment thread src/Client/ReplxxLineReader.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
…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]>
Comment thread src/Client/ClientBase.cpp Resolved
alexey-milovidov and others added 2 commits July 2, 2026 23:38
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Updated the branch: merged current master and fixed the root cause behind the failing interactive .expect tests and the AI review's "Request changes" finding.

Root cause. In queryNeedsContinuation, the ;-terminator scan 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 actually failed on an earlier token. As a result, any line that fails to parse from the start — for example exit, quit, or q — was treated as an incomplete query, so pressing Enter folded it into the edit buffer instead of committing it.

That is why every interactive .expect test timed out at 60s: they all end by sending exit (or quit/q), which was never committed, so exit_strings in processQueryText never ran and the client never exited.

Fix. Use a separate Tokens instance for the terminator scan so it no longer poisons the cursor the parser relies on (the primary option suggested in the review). Verified that a bare unparseable word reports its syntax error at the token itself (e.g. select 1) → "failed at position 9 ())"), not at end of input, so queryNeedsContinuation now correctly returns false for exit/quit/q and plain syntax errors, while genuinely incomplete input (e.g. SELECT, SELECT () still continues.

Both changed translation units (ClientBase.cpp, ReplxxLineReader.cpp) pass -fsyntax-only against current headers. Leaving the full interactive-test run to CI.

Comment thread src/Client/ClientBase.cpp Resolved
alexey-milovidov and others added 3 commits July 10, 2026 04:34
`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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (resolved a conflict in ParserPrometheusQuery.h, keeping both isIncompleteAtEOF and the new consumesRawText) and addressed both review threads. The only previous CI failures were Performance Comparison (arm_release) shards 2/6 and 5/6 (read_in_reverse_order_final, optimize_time_filter_with_preimage): server-side query timings, which this PR cannot affect since it changes only the interactive client continuation probe and dialect parser helpers.

Comment thread src/Client/ClientBase.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
alexey-milovidov and others added 3 commits October 10, 2026 08:31
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The only CI red, the Fast test failure of 04843_set_profile_continuation (https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101785&sha=9a99a51ef1b3008f00aff04d4b0a27d499db078d&name_0=PR&name_1=Fast%20test), is not caused by this PR. It comes from a master regression that came in with the last master merge: since #114568, clickhouse-local drops the settings of SET profile for the following queries (#123916). The test's last step expects the Kusto profile to be in effect, and it no longer is, so SELECT 1 succeeds and expect times out. The continuation assertion before it passes.

Fix: #125171. With it applied locally, 04843 and the other continuation .expect tests that run on clickhouse-local pass. Once it is merged, merging master here will clear the red. No change to this PR is needed.

alexey-milovidov and others added 2 commits October 12, 2026 06:10
…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

Copy link
Copy Markdown
Member

🕵 Merged current master and pushed fa28153 to stop the Fast test red in 04843_set_profile_continuation from depending on the open clickhouse-local fix (#125171 for #123916).

The test's last step checked that the Kusto profile was in effect by expecting SELECT 1 to be rejected after SET profile. With the clickhouse-local regression, SELECT 1 succeeds and expect times out. That step only made sure the profile actually carries a parser-shaping setting, so it now checks the profile definition in system.settings_profile_elements before SET profile. This works whether or not the clickhouse-local fix is merged. The continuation assertion itself is unchanged.

Ran locally on the merged tree against clickhouse-local: all 15 continuation .expect tests pass, except 05046_polyglot_no_continuation, which needs the Rust polyglot transpiler that my local build doesn't include (it passed in CI).

Comment thread src/Client/ClientBase.cpp Resolved
alexey-milovidov and others added 2 commits October 21, 2026 13:06
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]>
Comment thread src/Client/ClientBase.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
@bacek bacek mentioned this pull request Oct 22, 2026
1 task done
alexey-milovidov and others added 2 commits October 28, 2026 21:12
# 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]>
Comment thread src/Client/ClientBase.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
alexey-milovidov and others added 2 commits November 5, 2026 07:14
…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]>
Comment thread src/Client/ClientBase.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
alexey-milovidov and others added 2 commits November 13, 2026 09:41
…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]>
@clickhouse-gh clickhouse-gh Bot added manual approve Manual approve required to run CI submodule changed At least one submodule changed in this PR. labels Nov 13, 2026
Comment thread src/Client/ReplxxLineReader.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
alexey-milovidov and others added 2 commits November 23, 2026 19:52
# 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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged current master (one conflict in src/Parsers/LogsQL/LogsQLLexer.h: kept the end-of-input tracking of this PR together with the [[nodiscard]] attributes added on master) and addressed the three open review findings in 5729910: the probe now sees the lines accumulated before an explicit \ continuation, every statement gets its own max_parser_backtracks budget, and a mismatched closing bracket is submitted as a syntax error. Each has a new .expect regression test (05872, 05873, 05874).

Built clickhouse on the merged tree and ran all continuation .expect tests plus 01180_client_syntax_errors, 03014_invalid_utf8_client, 01293_*, 01599_* and a few other interactive client tests locally: all pass. The previous CI was green except CH Inc sync, which should re-run on the merged branch.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-cli clickhouse-client (interactive CLI) and client library. external Author is not a member of the ClickHouse organization manual approve Manual approve required to run CI pr-improvement Pull request with some product improvements submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In single-line interactive mode in clickhouse-client, ask for a continuation if the parser failed at the end of the query.

5 participants