Skip to content

Nested arrays seem to be broken in 0.4.0 #1221

@slvrtrn

Description

@slvrtrn

Minimal reproducible scenario:

package ch;

import com.clickhouse.jdbc.ClickHouseDataSource;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Properties;

public class ArrayTest {
    public static void main(String[] args) {
        String url = "jdbc:ch:http://localhost:8123/default";
        Properties properties = new Properties();
        properties.setProperty("user", "default");
        properties.setProperty("password", "");
        try {
            ClickHouseDataSource ds = new ClickHouseDataSource(url, properties);
            Connection conn = ds.getConnection();
            Statement stmt = conn.createStatement();
            stmt.executeQuery("drop table if exists test_data_array_of_arrays");
            stmt.executeQuery("""
                      create table test_data_array_of_arrays
                      (id Int32, my_array_of_arrays Array(Array(String)))
                      engine MergeTree order by id
                    """);
            stmt.execute("""
                    insert into test_data_array_of_arrays values
                    (1, [['foo', 'bar'], ['qaz', 'qux']]),
                    (2, []);
                    """);
            ResultSet rs = stmt.executeQuery("select * from test_data_array_of_arrays");
            while (rs.next()) {
                Arrays.stream(((String[][]) rs.getArray(2).getArray())).toList().forEach((innerArray) -> {
                    System.out.println(Arrays.toString(innerArray));
                });
            }
            System.exit(0);
        } catch (Exception e) {
            Common.logException(e);
            System.exit(1);
        }

    }
}

0.3.2-patch11 correctly prints:

[foo, bar]
[qaz, qux]

0.4.0 incorrectly prints:

[qaz, qux]
[qaz, qux]

Found this purely by accident cause I have a weird "Arrays of Arrays" test in the Metabase plugin, and all of a sudden this method started to produce incorrect results after the upgrade to 0.4.0 (see the JUnit report)

Is it indeed something wrong with the ResultSet as of 0.4.0, or am I doing it incorrectly in the code?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions