ClickHouseRowMetadata index should start at 0
Describe the bug
ClickHouseRowMetadata is starting the index at 1, but the index should be starting at 0, according to the spec.
Expected behaviour
Should work according to spec. Index should start at 0.
Code example
for (int i = 0; i < rowMetadata.getColumnMetadatas().size(); i++) {
String name = rowMetadata.getColumnMetadata(i).getName(); // failing at 0.. i + 1 works
Object value = row.get(i); // works fine
map.put(name, value);
}
Error log
java.lang.IllegalArgumentException: -1
at java.util.stream.ReferencePipeline.skip(ReferencePipeline.java:575) ~[?:?]
at com.clickhouse.r2dbc.ClickHouseRowMetadata.getColumnMetadata(ClickHouseRowMetadata.java:24) ~[clickhouse-r2dbc-0.4.6.jar:clickhouse-r2dbc 0.4.6 (revision: dd91e17)]
...
Configuration
Environment
- clickhouse-jdbc version: 0.4.6
Thank you @murzart for the reporting the issue. Will raise a PR to fix this.
If additional information helps to find out the bug location, there's a more detailed error (I was creating a new issue, but I found out this one)
As of today in the current implementation of the jdbc driver as of 0.8.6 seems not to be working as expected, for an unknown reason the jdbc driver is using 1-index column indexes instead of 0-index that confuses the Spring DataClassRowMapper
I tried to workaround it by manually summing +1 to the index, but unfortunately, the DataClassRowMapper is not using a protected method to find out the index, so I would have to manually create a bigger wrapper that wraps the entire for loop
Error:
Note that counts returns 0 index (should return 1)
One interesting thing is that the error occurs when finding out the column by name "counts" but, the TableSchema class seems to have correct indexing, on the column data instance return the
my workaround fixed the method reader.getSchema().getColumnByIndex() which works like 1 index, sample, but still couldn't fix the getColumnByName("counts").getColumnIndex()
Fixed in 0.9.0 https://github.com/ClickHouse/clickhouse-java/pull/2376