clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

Unsupported data type: JSON

Open aarcha123 opened this issue 3 years ago • 3 comments

Using the below snippet results in "Unsupported data type: JSON:" using 0.3.2.patch11

PreparedStatement pstmt = connection.prepareStatement("INSERT INTO json_demo SELECT id,details from INPUT('id UInt8, details JSON')"); `
    pstmt.setInt(1, 20);
pstmt.setObject(2, "{\"type\": \"Region\"}");
pstmt.addBatch();
pstmt.executeBatch();

Table definition

CREATE TABLE json_demo
( id UInt8,
details JSON)
ENGINE = MergeTree()
PRIMARY KEY (id)

Stack trace:

Exception in thread "main" java.lang.IllegalArgumentException: Unsupported data type: JSON
	at com.clickhouse.client.data.ClickHouseRowBinaryProcessor$MappedFunctions.serialize(ClickHouseRowBinaryProcessor.java:484)
	at com.clickhouse.jdbc.internal.InputBasedPreparedStatement.addBatch(InputBasedPreparedStatement.java:333)

aarcha123 avatar Jul 29 '22 05:07 aarcha123

Hi @aarcha123, thanks for the report. It looks like now ClickHouse supports string format JSON object, which is way better than constructing a complex object in client. I'll update data type mapping accordingly in next release. Meanwhile, the workaround is simply change JSON to String in your insert query.

zhicwu avatar Jul 29 '22 06:07 zhicwu

Thank you @zhicwu

aarcha123 avatar Jul 29 '22 14:07 aarcha123