ClickHouse / clickhouse-java

ClickHouse Java Clients & JDBC Driver
https://clickhouse.com
Apache License 2.0
1.42k stars 526 forks source link

ClickHouseRowMetadata index should start at 0 #1378

Open murzart opened 1 year ago

murzart commented 1 year ago

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

zhicwu commented 1 year ago

Thank you @murzart for the reporting the issue. Will raise a PR to fix this.