Skip to content

Report a missing delimiter in Values as a missing delimiter - #116877

Merged
alexey-milovidov merged 5 commits into
masterfrom
improve-values-format-error-messages
Aug 29, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
improve-values-format-error-messages

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

Related: #116806
Related: #116809
Related: #116812
Related: #116815
Related: #116817
Related: #116871
Related: #116872

Extending the survey of error messages for mistakes in SQL queries to the data-loading path turned this up. A row with fewer values than the table has columns was reported as if the last value it did read were at fault:

CREATE TABLE t (id UInt32, name String, d Date, e Enum8('a' = 1, 'b' = 2)) ORDER BY id;
INSERT INTO t FORMAT Values (1, 'Alice')
Code: 62. DB::Exception: Cannot parse expression of type String here: 'Alice') (SYNTAX_ERROR)

'Alice' is a perfectly good String — what is missing is the comma after it. ValuesBlockInputFormat::parseExpression folds two different outcomes into one flag:

parsed = parser.parse(*token_iterator, ast, expected);

/// Consider delimiter after value (',' or ')') as part of expression
if (column_idx + 1 != num_columns)
    parsed &= (*token_iterator)->type == TokenType::Comma;
else
    parsed &= (*token_iterator)->type == TokenType::ClosingRoundBracket;

if (!parsed)
    throw Exception(ErrorCodes::SYNTAX_ERROR, "Cannot parse expression of type {} here: {}", ...);

so a good value followed by the wrong delimiter gets the message written for a value that does not parse. Telling them apart:

input before after
(1, 'Alice') — too few values Cannot parse expression of type String here: 'Alice') Expected ',' after the value of column name of type String here: 'Alice')
(1, 'Alice', '2020-01-02', 'a' — no closing bracket Cannot parse expression of type Enum8('a' = 1, 'b' = 2) here: 'a' Expected ')' after the value of column e of type Enum8('a' = 1, 'b' = 2) here: 'a'
(1 'Alice', ...) — comma missing Cannot parse expression of type UInt32 here: 1 'Alice', ... Expected ',' after the value of column id of type UInt32 here: 1 'Alice', ...
(1, 'Alice', '2020-01-02', 'a', 'extra') — too many values Cannot parse expression of type Enum8(...) here: 'a', 'extra') Expected ')' after the value of column e of type Enum8(...) here: 'a', 'extra')

An expression that genuinely does not parse (notafunction(2), *) still gets exactly the message it had, and the path where the tokenizer itself fails is untouched.

The 53 stateless tests that use FORMAT Values or ValuesBlockInputFormat were run; the failures are unrelated environment ones (no ZooKeeper, and async_insert on in the local setup), and no failure diff mentions either the old or the new message.

Changelog category (leave one):

  • Improvement

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

A row in the Values format whose values are fine but whose , or ) is missing or misplaced — most often a row with fewer or more values than the table has columns — now reports the missing delimiter and the column it should follow, instead of claiming that the last value could not be parsed as its own type.


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

Version info

  • Merged into: 26.9.1.327 (included in 26.9 and later)

Extending the error-message survey to the data-loading path turned this
up. A row with fewer values than the table has columns was reported as if
the last value it did read were at fault:

    INSERT INTO t (id UInt32, name String, d Date, e Enum8('a' = 1, 'b' = 2))
        FORMAT Values (1, 'Alice')
    Cannot parse expression of type String here: 'Alice')

`'Alice'` is a perfectly good String; what is missing is the comma after
it. `ValuesBlockInputFormat::parseExpression` folds two different
outcomes into one flag - the expression not parsing, and the expression
parsing but not being followed by the expected `,` or `)` - and reports
both with the message for the first. Tell them apart:

    Expected ',' after the value of column `name` of type String here: 'Alice')

The same shape covers a row that lost its closing bracket (`Expected ')'
after the value of column `e` ...`), a row with a comma missing between
two values, and a row with more values than there are columns. An
expression that genuinely does not parse still gets the message it had.
@clickhouse-gh

clickhouse-gh Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [66538e8]

Summary: ✅


AI Review

Summary

This PR teaches ValuesBlockInputFormat to distinguish “the expression did not parse” from “the value parsed but the row delimiter after it is wrong,” and it also brings the slow expression path in line with the existing optional trailing-comma behavior for the last column. I checked the changed parser path, its interaction with template deduction, the new shell regression test, and the prior discussion thread; I did not find any remaining correctness or coverage issues in the current version of the patch.

Final Verdict

✅ No blocking issues found in the current PR state.

LLVM Coverage Report

Measured on commit 66538e8.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 80.70% 80.80% +0.10%

Changed lines: Changed C/C++ lines covered: 39/39 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 28, 2026
`Fast test` produced no error lines at all for the four failing inserts,
while the same inserts fail as expected locally, so the test depended on
something about how the client reports an insert error under the settings
that CI randomizes. The message is the whole point of the test, and the
HTTP interface returns it in one piece, so use that and pin
`async_insert` while at it.
`Fast test` produced no error lines at all for the four failing inserts,
and the same happens locally about one run in three once `clickhouse-test`
randomizes settings: with `async_insert = 1` and `wait_for_async_insert =
0` an insert returns an empty successful response and the parse error is
only logged.

The test is about the message a format produces, so run the format
directly - `format(Values, ...)` in `clickhouse-local` uses the same
reader, with no table, no server and no insert settings to depend on.
@clickhouse-gh

clickhouse-gh Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 66538e816 with master 617af45cc (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 710.07 MiB 707.02 MiB -3.06 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

Review pointed out that `checkDelimiterAfterValue` accepts an optional
trailing comma before `)` for the last column, and
`03153_trailing_comma_in_values_list_in_insert` documents it, while this
path accepted only `)`. So

    INSERT INTO t (a, b, c) VALUES (1, 2, 3,)                    -- works
    INSERT INTO t (a, b, c) VALUES (1, 2, toDate('2020-01-02'),)  -- fails

purely because the last value needs the expression parser rather than the
streaming one. Accept it here too, only when the comma is immediately
followed by `)`, so that nothing else changes.

@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.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Aug 29, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 29, 2026
Merged via the queue into master with commit f0989fe Aug 29, 2026
174 checks passed
@alexey-milovidov
alexey-milovidov deleted the improve-values-format-error-messages branch August 29, 2026 12:49
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants