Querying JSON field returns "Failed to read value for column data" or "Failed to read next row"
Description
When querying certain JSON column I get following errors.
Steps to reproduce
1.
Create a table with id and JSON as columns.
CREATE TABLE test (id UInt64, data JSON) ENGINE = MergeTree ORDER BY id;
Insert data.
INSERT INTO test (id, data) VALUES
(
1,
'{"FailedToReadValueForColumnData":{"bar":[{"field1":"value1","field2":"value2","field3":"value3","field4":"value4"},{"field1":"value5","field2":"value6","field3":"value7","field4":"value8"}]}}'
);
INSERT INTO test (id, data) VALUES
(
2,
'{"Works":"bye"}'
);
INSERT INTO test (id, data) VALUES
(
3,
'{"FailedReadNextRow":{"hi":[{"hi":"byyyyyyyyye"}]}}'
);
2. Query them
SELECT * from test where id=1;
SELECT * from test where id=2;
SELECT * from test where id=3;
3.
You'll see that id 1 gives error with message "Failed to read value for column data", id 2 works, id 3 gives error with message "Failed to read next row"
Error Log or Exception StackTrace
0 = {StackTraceElement@20265} "com.clickhouse.jdbc.internal.ExceptionUtils.toSqlState(ExceptionUtils.java:69)"
1 = {StackTraceElement@20266} "com.clickhouse.jdbc.internal.ExceptionUtils.toSqlState(ExceptionUtils.java:42)"
2 = {StackTraceElement@20267} "com.clickhouse.jdbc.ResultSetImpl.next(ResultSetImpl.java:118)"
Expected Behaviour
To get the full rows back
Configuration
Client Configuration
Using the JDBC driver version 0.9.2
@philip-dbvis thank you for the issue! We will fix it.
@philip-dbvis do you have stack trace for these errors?
@philip-dbvis do you have stack trace for these errors?
I added it in the ticket. Is it not sufficient?
0 = {StackTraceElement@20265} "com.clickhouse.jdbc.internal.ExceptionUtils.toSqlState(ExceptionUtils.java:69)"
1 = {StackTraceElement@20266} "com.clickhouse.jdbc.internal.ExceptionUtils.toSqlState(ExceptionUtils.java:42)"
2 = {StackTraceElement@20267} "com.clickhouse.jdbc.ResultSetImpl.next(ResultSetImpl.java:118)"
@philip-dbvis more information is better =) Currently I know what errors happen. It is enough to fix particular error. With complete stacktrace I would know more about root cause and may be will fix more.
@philip-dbvis more information is better =) Currently I know what errors happen. It is enough to fix particular error. With complete stacktrace I would know more about root cause and may be will fix more.
I see! I created a small program that runs the explained procedure above which prints out the full stack traces. Here's the repo : https://github.com/philip-dbvis/testing-clickhouse
@philip-dbvis
Thank you for the program! Will look into it.
Note: This is the problem with nested array of objects. For some reason len is 0.
Here is simplest example:
{ "array": [ { "nested": [ {"key": "value"} ] } ] }
While reading array key (what is the only in this case) we read length then. What is 0. So reading anything next fails.
If there are other paths to read - it will fail on same row, if there are other rows to read - then will fail on them.
Hi, @chernser! With 0.9.2, I'm getting this output
{a=[1, 2]}
{a=1}
{a=[]}
for this input data
insert into json (o) values ('{"a": [1, 2]}');
insert into json (o) values ('{"a": 1}');
insert into json (o) values ('{"a": [{ "b": [{"c": 1, "d": "value"}] }]}');
Do I get it right that this is precisely the issue you mentioned in the previous comment, and that it was fixed by #2601?
Also, with 0.8.6 I get
{a=com.clickhouse.client.api.data_formats.internal.BinaryStreamReader$ArrayValue@2b662a77}
Is it right that the behavior in 0.9.2 is actually the intended one and clients can rely on the result set containing standard Java collections instead of custom driver types?
Good day, @d-suvorov ! Yes, the fix is in #2601
Yes, driver should not return custom types in most cases.
Ideally for this case you should be able to getObject() what should return your object or an object of preferable JSON library (like Jakson). We are working in this direct.
Thank you!