Skip to content

fix(jdbc-v2): accept SQL Date in RowBinary inserts - #3401

Open
XSY-28 wants to merge 1 commit into
ClickHouse:mainfrom
XSY-28:fix/jdbc-rowbinary-sql-date-3386
Open

XSY-28 wants to merge 1 commit into
ClickHouse:mainfrom
XSY-28:fix/jdbc-rowbinary-sql-date-3386

Conversation

@XSY-28

@XSY-28 XSY-28 commented Nov 23, 2026 •

Copy link
Copy Markdown

Summary

With beta.row_binary_for_simple_insert=true, binding a java.sql.Date via PreparedStatement.setObject fails when the writer adds a row to the batch. Use the existing setDate calendar conversion for Date and Date32 when the placeholders are known to follow the table's writable column order.

The beta writer sends RowBinary without a target column list and skips generated columns. Unresolved or reordered lists and generated fields within the bound positions retain their existing date-binding behavior.

Closes #3386.

Verification

  • Reproduced the reported addBatch() failure on 75063012. The JDBC regression now reads the expected Date, pre-epoch Date32, nullable date and following integer from ClickHouse.
  • Verified a known in-order ANTLR4 list. Reordered lists with two same-type date columns retain rejection under JavaCC and both ANTLR modes. A date before a skipped generated field also retains rejection before later numeric values can shift.
  • Passed 2,029 JDBC unit cases and 145 integration cases from JDBCDateTimeTests, WriterStatementImplTest and PreparedStatementTest on ClickHouse 26.12.1.263 and Corretto JDK 17.0.21.1, both using UTC.
  • A clean clickhouse-jdbc-all build passed. The packaged driver stored the expected date and following integer. Its reordered-list and generated-column probes produced the same results as the base driver.
  • The unfiltered reactor stops at ClickHouseStringValueTest#testValue. The same assertion fails when running the unchanged clickhouse-data module on its own.

Checklist

AI assistance

OpenAI Codex prepared the patch and ran the listed checks.


Note

Medium Risk
Changes prepared-insert parameter encoding for a beta RowBinary path and ties it to SQL parser metadata; wrong gating could mis-bind dates or mask unsafe column orders.

Overview
Fixes jdbc-v2 RowBinary simple inserts (beta.row_binary_for_simple_insert) so PreparedStatement.setObject(..., java.sql.Date) works when placeholders align with the table's writable column order, using the same conversion as setDate(...) for Date and Date32.

WriterStatementImpl now tracks whether binding order is trusted (usesTableColumnOrder): resolved insert columns, table-order inserts without generated/default columns in the bound prefix, and no parser-flagged unresolved column list. Only then does setObject special-case java.sql.Date; reordered column lists and inserts before skipped materialized columns keep the prior failure behavior.

The JavaCC parser records unresolved insert column lists via ParsedPreparedStatement.hasUnresolvedInsertColumns(). Docs and a changelog note the RowBinary date behavior; integration tests cover in-order success and rejected reorder/generated-column cases across parser backends.

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

Reuse setDate conversion for Date and Date32 when the bound parameters follow the writable table order. Keep existing binding for unresolved and reordered column lists and for generated columns in the bound range.

Refs ClickHouse#3386
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 rejects java.sql.Date passed through setObject

1 participant