[jdbc-v2] RowBinary writer: setObject with an InputStream or Reader stores the object's toString() instead of the data
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- Ein halber Tag
- Anfängerfreundlichkeit
- 65/100
Rechercherichtung
Start in jdbc-v2/src/main/java/com/clickhouse/jdbc/WriterStatementImpl.java at setObject(int, Object) (around lines 436-439), and compare it with how PreparedStatementImpl.encodeObject reads Reader and InputStream values (around lines 850-853). Run the reproduction program with the writer on and off to confirm the stored value. Done means the writer-on run stores abc for String and FixedString columns, matching the writer-off run.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
With beta.row_binary_for_simple_insert=true (WriterStatementImpl), PreparedStatement.setObject(int, Object) with a java.io.InputStream or java.io.Reader value does not store the data of the stream. The driver does not read the stream:
String,Nullable(String),LowCardinality(String): the column gets thetoString()text of the object, for examplejava.io.ByteArrayInputStream@1b7cc17c. The insert succeeds with no error.FixedString(3):executeUpdate()fails withIllegalArgumentException: length of byte array value is 37, which should NOT longer than 3.- A
java.sql.Bloborjava.sql.Clobobject (SerialBlob,SerialClob) given tosetObjectalso stores itstoString()text in aStringcolumn.
With the writer off (PreparedStatementImpl), the same InputStream and Reader values store abc in all four column types.
Steps to reproduce
CREATE TABLE t_obj_stream (id Int32, s String, tail Int32) ENGINE = MergeTree ORDER BY id- With the writer on,
INSERT INTO t_obj_stream VALUES (?, ?, ?): row 1 withsetObject(2, new ByteArrayInputStream("abc".getBytes())), row 2 withsetObject(2, new StringReader("abc")), oneexecuteUpdate()for each row. SELECT id, s, tail FROM t_obj_stream ORDER BY id- The code example does steps 1–3 again with the writer off.
Error Log or Exception StackTrace
writer=true: 1, java.io.ByteArrayInputStream@1b7cc17c, 7
writer=true: 2, java.io.StringReader@409bf450, 7
writer=false: 1, abc, 7
writer=false: 2, abc, 7
Expected Behaviour
The column gets abc, the data of the stream, in both rows, as with the writer off: PreparedStatementImpl.encodeObject reads Reader and InputStream values (jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java:850-853).
Root cause
WriterStatementImpl.setObject(int, Object) (jdbc-v2/src/main/java/com/clickhouse/jdbc/WriterStatementImpl.java:436-439) gives the object to RowBinaryFormatWriter.setValue without a conversion. For String and FixedString columns, SerializerUtils.serializeData (client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/SerializerUtils.java:717, :726) then writes String.valueOf(value) for each value that is not a byte[] or a StringValue.
The fix is small. A maintainer can choose where the stream is read: in WriterStatementImpl.setObject (as PR #3414 does for the stream setters), or in client-v2 together with #3336. Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related:
- #3336: client-v2
setInputStream/setReaderstore a holder'stoString(); same symptom, other entry point. - PR #3414: fixes the stream setters of
WriterStatementImpl, notsetObject. - #3408: if the typed
setObjectoverloads callsetObject(int, Object), they get this defect too.
Code Example
Reproduction program (Java, 34 lines)
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.sql.*;
import java.util.Properties;
public class Minimal {
public static void main(String[] args) throws Exception {
for (String writer : new String[] {"true", "false"}) {
Properties p = new Properties();
p.setProperty("user", "default");
p.setProperty("password", args[0]);
p.setProperty("beta.row_binary_for_simple_insert", writer);
try (Connection c = new com.clickhouse.jdbc.Driver().connect("jdbc:clickhouse://localhost:8123/default", p);
Statement s = c.createStatement()) {
s.execute("CREATE OR REPLACE TABLE t_obj_stream (id Int32, s String, tail Int32) ENGINE = MergeTree ORDER BY id");
try (PreparedStatement ps = c.prepareStatement("INSERT INTO t_obj_stream VALUES (?, ?, ?)")) {
Object[] values = {new ByteArrayInputStream("abc".getBytes(StandardCharsets.UTF_8)), new StringReader("abc")};
for (int i = 0; i < values.length; i++) {
ps.setInt(1, i + 1);
ps.setObject(2, values[i]);
ps.setInt(3, 7);
ps.executeUpdate();
}
}
try (ResultSet rs = s.executeQuery("SELECT id, s, tail FROM t_obj_stream ORDER BY id")) {
while (rs.next()) {
System.out.println("writer=" + writer + ": " + rs.getInt(1) + ", " + rs.getString(2) + ", " + rs.getInt(3));
}
}
}
}
}
}
Configuration
Client Configuration
p.setProperty("beta.row_binary_for_simple_insert", "true");
Environment
- Cloud
- Client version: jdbc-v2
0.12.0-rc1-SNAPSHOT, built from main051a7ecfd - Language version: Java 17.0.21
- OS: Linux (Docker)
ClickHouse Server
- ClickHouse Server version: 26.10.4.207
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: see "Steps to reproduce"- Sample data for all these tables: the code example inserts it
Classification: impact: Data integrity · area: Data types & formats (String, RowBinary)
Found by automated analysis (Polyglot AI) while working on #3406. Verified against a live server.
- Vorherrschende Sprache
- Java
- Sterne
- 1.6k
- Forks
- 657
- Ø Merge
- 2 T. 6 Std.
- Gemergte PRs (30 T.)
- 36
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus ClickHouse/clickhouse-java
-
api-diagnostics bug jdbc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
ClickHouse/clickhouse-java#3464 ·
Maintainer antworten meist innerhalb von 1 Tag
-
tests
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
ClickHouse/clickhouse-java#3452 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug jdbc performance queries sql-parser
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
ClickHouse/clickhouse-java#3451 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug jdbc legacy queries
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
ClickHouse/clickhouse-java#3444 ·
Maintainer antworten meist innerhalb von 1 Tag
-
api-diagnostics bug client jdbc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
ClickHouse/clickhouse-java#3439 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in ClickHouse/clickhouse-java
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 60/100
quelea-projection/Quelea#749 ·
Maintainer antworten meist innerhalb von 1 Tag
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 92/100
erkamyaman/rust-anything#963 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 76/100
-
Deferred
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Sanne/incus-spawn#2768 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
morluto/rea#15041 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag