JSON column cant use the string type to write
Describe the bug
When we use the ps.setString("json_val") insert JSON column to the clickhouse server, we will have the below error.
because the jdbc-diver uses select * from the table where 0 to read all columns from the clickhouse server, but the server returns a tuple type for this JSON type, so it used incorrect serializer com.clickhouse.data.format.ClickHouseRowBinaryProcessor$TupleSerializer.serialize(ClickHouseRowBinaryProcessor.java:243)
Steps to reproduce
Expected behaviour
It should use the desc table xxx to get the factly type, then it will get the correct serializer
``
Code example
Error log
Caused by: java.lang.NumberFormatException: For input string: "{"a": 1, "b": { "c": 2, "d": [1, 2, 3] }}"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.base/java.lang.Integer.parseInt(Integer.java:652)
at com.clickhouse.data.value.UnsignedByte.valueOf(UnsignedByte.java:78)
at com.clickhouse.data.value.UnsignedByte.valueOf(UnsignedByte.java:61)
at com.clickhouse.data.value.ClickHouseByteValue$UnsignedByteValue.update(ClickHouseByteValue.java:93)
at com.clickhouse.data.value.ClickHouseByteValue$UnsignedByteValue.update(ClickHouseByteValue.java:16)
at com.clickhouse.data.ClickHouseValue.update(ClickHouseValue.java:1236)
at com.clickhouse.data.value.ClickHouseByteValue.update(ClickHouseByteValue.java:408)
at com.clickhouse.data.value.ClickHouseByteValue$UnsignedByteValue.update(ClickHouseByteValue.java:16)
at com.clickhouse.data.format.ClickHouseRowBinaryProcessor$TupleSerializer.serialize(ClickHouseRowBinaryProcessor.java:243)
at com.clickhouse.data.ClickHouseDataProcessor.write(ClickHouseDataProcessor.java:593)
at com.clickhouse.jdbc.internal.InputBasedPreparedStatement.addBatch(InputBasedPreparedStatement.java:350)
Configuration
Environment
- Client version: 0.6
- Language version:
- OS:
ClickHouse server
- ClickHouse Server version:
- ClickHouse Server non-default settings, if any:
CREATE TABLEstatements for tables involved:- Sample data for all these tables, use clickhouse-obfuscator if necessary
Hi @zhicwu , How do you think it?
Client-v2 allows writing JSON as string. https://github.com/ClickHouse/clickhouse-java/pull/1909