Repository navigation
Description
Description
With beta.row_binary_for_simple_insert=true, PreparedStatement.setObject(i, java.sql.Date) on a Date column fails at addBatch() with IllegalArgumentException: Cannot convert 2013-07-15 to Long. The same value works through setDate(i, date), and it works through setObject when the property is off.
WriterStatementImpl.setObject passes the value straight to RowBinaryFormatWriter.setValue, and SerializerUtils.writeDate only accepts LocalDate, ZonedDateTime and OffsetDateTime. setDate converts with DataTypeUtils.toLocalDate first, so the two setters disagree. Both are unchanged on main at 7506301.
This matters more once #3328 makes the RowBinary writer the default. jdbc-v2's own ResultSet.getObject returns java.sql.Date for a Date column, so an app that reads rows with getObject and re-inserts them with setObject works today and would fail after upgrading. We hit it doing exactly that in an internal benchmark suite's JDBC insert arms.
Expected: setObject with a java.sql.Date behaves like setDate on the RowBinary writer path, as it does on the default path.
Related writer gaps: #3334, #2619.
Steps to reproduce
- jdbc-v2 0.11.2, ClickHouse 26.6.8.7, Java 21.
- Run the program below as
java Repro <database> defaultandjava Repro <database> rowbinary. The second setsbeta.row_binary_for_simple_insert=true.
import java.sql.*;
import java.util.Properties;
// clickhouse-java jdbc-v2: RowBinary writer and java.sql.Date via setObject.
// Run once per mode: "default" (text VALUES path) or "rowbinary" (beta writer).
public class Repro {
public static void main(String[] args) throws Exception {
String url = "jdbc:clickhouse://localhost:8123/" + args[0];
boolean rowBinary = "rowbinary".equals(args[1]);
Properties p = new Properties();
p.setProperty("user", "default");
p.setProperty("password", "");
if (rowBinary) {
p.setProperty("beta.row_binary_for_simple_insert", "true");
}
java.sql.Date date = java.sql.Date.valueOf("2013-07-15");
try (Connection c = DriverManager.getConnection(url, p)) {
try (Statement s = c.createStatement()) {
s.execute("CREATE OR REPLACE TABLE repro_date (d Date) ENGINE = Memory");
}
System.out.println("driver " + c.getMetaData().getDriverVersion() + ", mode " + args[1]);
try (PreparedStatement ps = c.prepareStatement("INSERT INTO repro_date VALUES (?)")) {
System.out.println("statement class: " + ps.getClass().getName());
run("setDate ", () -> { ps.setDate(1, date); ps.addBatch(); ps.executeBatch(); });
run("setObject", () -> { ps.setObject(1, date); ps.addBatch(); ps.executeBatch(); });
}
try (Statement s = c.createStatement(); ResultSet rs = s.executeQuery("SELECT groupArray(d) FROM repro_date")) {
rs.next();
System.out.println("table contents: " + rs.getString(1));
}
}
}
interface Step { void run() throws Exception; }
static void run(String name, Step step) {
try {
step.run();
System.out.println(name + " -> ok");
} catch (Exception e) {
Throwable root = e;
while (root.getCause() != null) root = root.getCause();
System.out.println(name + " -> " + e.getClass().getName() + ": " + e.getMessage()
+ (root != e ? " (root: " + root.getClass().getName() + ": " + root.getMessage() + ")" : ""));
}
}
}Error Log or Exception StackTrace
Output of both runs, verbatim:
driver 0.11.2, mode default
statement class: com.clickhouse.jdbc.PreparedStatementImpl
setDate -> ok
setObject -> ok
table contents: [2013-07-15, 2013-07-15]
driver 0.11.2, mode rowbinary
statement class: com.clickhouse.jdbc.WriterStatementImpl
setDate -> ok
setObject -> java.sql.SQLException: java.lang.IllegalArgumentException: Cannot convert 2013-07-15 to Long (root: java.lang.IllegalArgumentException: Cannot convert 2013-07-15 to Long)
table contents: [2013-07-15]
Activity
jdbc-v2: changelog for the setObject(java.sql.Date) RowBinary fix (#3386
jdbc-v2: cover Map(String, Date32) in the setObject(java.sql.Date) te…