Skip to content

[jdbc-v2] RowBinary writer: respect the INSERT column list - #3461

Open
saadfikri wants to merge 1 commit into
ClickHouse:mainfrom
saadfikri:fix/3422-writer-insert-column-list
Open

saadfikri wants to merge 1 commit into
ClickHouse:mainfrom
saadfikri:fix/3422-writer-insert-column-list

Conversation

@saadfikri

@saadfikri saadfikri commented Nov 28, 2026 •

Copy link
Copy Markdown

Summary

Closes #3422

With beta.row_binary_for_simple_insert=true, the writer ignores the
column list in the INSERT and writes values in table order. So
INSERT INTO t (b, a) VALUES (?, ?) puts param 1 into a, not b.
A column subset like INSERT INTO t (k, b) on a 3-column table has
the same problem — wrong columns get the data, or you get
CANNOT_READ_ALL_DATA depending on the parser backend.

Two things were wrong:

  1. The default parser (JavaCC) never extracted the column names from
    the INSERT. The grammar already tracked the positions but
    parsePreparedStatement() skipped them. ANTLR4 did extract them,
    so this was only broken on the default path.

  2. executeLargeUpdate() used the insert() overload without column
    names, so the server always got INSERT INTO t FORMAT RowBinary
    and read bytes in table order no matter what.

Fix: added column extraction in the JavaCC parser (same approach as
ANTLR4 — tokenize between ColumnsStart/ColumnsEnd, handle quoted and
nested identifiers), and wired the column names through to
Client.insert() so the server sees the right column list.

Tests added for reordering, subset, batch, and quoted names — each
across all 3 parser backends. Existing tests still pass (50/50).


Note

Medium Risk
Changes the insert data path when the RowBinary beta is enabled; incorrect column mapping previously caused silent data corruption, so reviewers should focus on parser edge cases and the insert API wiring.

Overview
Fixes #3422: with beta.row_binary_for_simple_insert=true, prepared INSERT statements that name or reorder columns no longer stream RowBinary values in full table column order.

The JavaCC parser now extracts the explicit column list (between ColumnsStart/ColumnsEnd), including quoted/nested identifiers, comments, and $ in names—bringing it in line with the ANTLR4 backends. WriterStatementImpl narrows the writer schema to those columns and passes enquoted column names into Client.insert() during executeLargeUpdate() (and thus batch), so bound parameters map to statement column order.

New integration tests cover reordering, column subsets, batch, and quoted columns across all three parser backends; parser unit tests now require every backend to return INSERT column names.

Reviewed by Cursor Bugbot for commit 6a4ec67. Bugbot is set up for automated code reviews on this repo. Configure here.

@saadfikri
saadfikri requested review from a team and mzitnik as code owners November 28, 2026 10:45

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 2064b84. Configure here.

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

AI review gate — AI review passed

Clean review from: Cursor Bugbot.

The JavaCC parser never extracted the column list from INSERT statements,
so the RowBinary writer always fell back to the full table schema. When
columns were reordered or a subset was used, values ended up in the wrong
columns or the server rejected the payload.

- JavaCCParser.extractInsertColumns() now reads the ColumnsStart/ColumnsEnd
  positions recorded by the grammar and tokenizes the column list, handling
  quoted identifiers, dollar signs, nested names, and inline comments.
- WriterStatementImpl passes the extracted column names to Client.insert(),
  quoting them with SQLUtils.enquoteIdentifier() so reserved words and
  special characters are safe.
- Added unit tests for edge cases (dollar signs, comments in column lists)
  and integration tests for column reordering, subsets, batch inserts, and
  quoted columns across all three parser backends.

Closes ClickHouse#3422
@saadfikri
saadfikri force-pushed the fix/3422-writer-insert-column-list branch from 2064b84 to 6a4ec67 Compare November 28, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[jdbc-v2] RowBinary writer ignores the INSERT column list and stores values in the wrong columns

1 participant