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

JDBC-V2: ResultSet inferred type for arrays is always `Object[]`

Open jnd77 opened this issue 6 months ago • 0 comments

Description

When retrieving a column, whose type is array, the inferred type is always Object[]; for example, it should be Long[] for Array(Int64).

Steps to reproduce

See code below.

Error Log or Exception StackTrace

See failing test below.

Expected Behaviour

Test should pass.

Code Example

  @Test
  void required_testJdbcWithArray() throws Exception {
    final String url = "jdbc:ch://localhost:8123";

    final Properties info = new Properties();
    info.put("user", "default");
    info.put("password", "");

    try (final Connection conn = DriverManager.getConnection(url, info)) {
      conn.prepareStatement("CREATE TABLE test_array_table"
          + " (id Int64, array_field Array(Int64)) ENGINE = MergeTree() ORDER BY id").execute();
      conn.prepareStatement("INSERT INTO test_array_table VALUES (1, [1,2,3])").execute();
      try (final Statement tableStatement = conn.createStatement();
      final ResultSet resultSet = tableStatement.executeQuery("SELECT `array_field` FROM `test_array_table`")) {
        resultSet.next();
        final Array columnValue = resultSet.getArray(1);
        // The 2 assertions below should pass: instead we retrieve Object[]
        Assertions.assertThat(columnValue.getArray()).isExactlyInstanceOf(Long[].class);
        Assertions.assertThat(JDBCType.valueOf(columnValue.getBaseType())).isEqualTo(JDBCType.BIGINT);
      }
    }
  }

Configuration

Client Configuration

See above.

Environment

  • [ ] Cloud
  • Client version:
  • Language version:
  • OS:

ClickHouse Server

  • ClickHouse Server version: 25.3.3.42
  • ClickHouse Server non-default settings, if any:
  • CREATE TABLE statements for tables involved:
  • Sample data for all these tables, use clickhouse-obfuscator if necessary

jnd77 avatar Jun 16 '25 12:06 jnd77