Skip to content

[jdbc-v2] getArray and getObject throw NullPointerException for Array(Ring), Array(Geometry) and other arrays of geo types #3378

Open

Description

@Indian-boult

Description

ResultSet#getArray and ResultSet#getObject throw SQLException for a column that is an array of a geo type. The cause is a NullPointerException in the constructor of com.clickhouse.jdbc.types.Array.

JdbcUtils.convert takes the element class from convertToJavaClass(baseType). For every geo type this is java.sql.Array, because the geo types map to JDBCType.ARRAY. JdbcUtils.convertList then converts each element with convert(value, java.sql.Array.class), which has no column. For an element that is a Java array, convert calls new Array(null, ...), and the constructor calls column.getArrayNestedLevel().

On ClickHouse 26.10 this happens for arrays of Ring, LineString, MultiPoint, Polygon, MultiLineString, MultiPolygon, Geometry and Nullable(Point), and for the same types one level deeper, for example Array(Array(Ring)). ClickHouse 25.8 gives the same error for Array(Ring), Array(LineString), Array(Polygon), Array(MultiLineString), Array(MultiPolygon) and Array(Array(Ring)). getObject(column, Object.class) works and returns the raw List. Arrays of Tuple(Ring, Int32), Map(String, Ring), Variant(Ring, String) and Dynamic are not affected.

Array(Point) and Array(Array(Point)) fail earlier, in client-v2 BinaryStreamReader, with array element type mismatch. That is a separate bug.

Commit 84f9e7e changed the geo types from JDBCType.OTHER to JDBCType.ARRAY. It is first in v0.9.3. In the code before that commit, the element class of a geo type was a double array class, so convertList kept the elements as read.

Steps to reproduce

  1. Connect with jdbc-v2 to ClickHouse 26.10.
  2. Run SELECT [[(1.5, 2.5), (3.5, 4.5)]]::Array(Ring) AS rings.
  3. Call rs.getArray("rings") or rs.getObject("rings").

Error Log or Exception StackTrace

Exception in thread "main" java.sql.SQLException: Method: getObject("rings", interface java.sql.Array) encountered an exception.
	at com.clickhouse.jdbc.internal.ExceptionUtils.toSqlState(ExceptionUtils.java:75)
	at com.clickhouse.jdbc.ResultSetImpl.getObjectImpl(ResultSetImpl.java:1565)
	at com.clickhouse.jdbc.ResultSetImpl.getObject(ResultSetImpl.java:1515)
	at com.clickhouse.jdbc.ResultSetImpl.getArray(ResultSetImpl.java:1042)
	at GeoArrayRead.main(GeoArrayRead.java:15)
Caused by: java.lang.NullPointerException: Cannot invoke "com.clickhouse.data.ClickHouseColumn.getArrayNestedLevel()" because "this.column" is null
	at com.clickhouse.jdbc.types.Array.<init>(Array.java:44)
	at com.clickhouse.jdbc.internal.JdbcUtils.convert(JdbcUtils.java:342)
	at com.clickhouse.jdbc.internal.JdbcUtils.convert(JdbcUtils.java:299)
	at com.clickhouse.jdbc.internal.JdbcUtils.convert(JdbcUtils.java:295)
	at com.clickhouse.jdbc.internal.JdbcUtils.convertList(JdbcUtils.java:480)
	at com.clickhouse.jdbc.internal.JdbcUtils.convert(JdbcUtils.java:331)
	at com.clickhouse.jdbc.ResultSetImpl.getObjectImpl(ResultSetImpl.java:1559)
	at com.clickhouse.jdbc.ResultSetImpl.getObject(ResultSetImpl.java:1515)
	at com.clickhouse.jdbc.ResultSetImpl.getArray(ResultSetImpl.java:1042)
	at GeoArrayRead.main(GeoArrayRead.java:15)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:484)
	at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:208)
	at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:135)

Expected Behaviour

getArray and getObject return a java.sql.Array. getBaseTypeName() is Ring and getBaseType() is Types.ARRAY. getArray() has one element for each ring, and each element is the double[][] that getObject returns for a Ring column.

Code Example

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

public class GeoArrayRead {
    public static void main(String[] args) throws Exception {
        Properties props = new Properties();
        props.setProperty("user", "default");
        props.setProperty("password", "");
        try (Connection conn = new com.clickhouse.jdbc.Driver().connect("jdbc:clickhouse://127.0.0.1:8123/default", props);
             Statement stmt = conn.createStatement();
             ResultSet rs = stmt.executeQuery("SELECT [[(1.5, 2.5), (3.5, 4.5)]]::Array(Ring) AS rings")) {
            rs.next();
            java.sql.Array rings = rs.getArray("rings");
            System.out.println(rings.getBaseTypeName());
        }
    }
}

Configuration

Client Configuration

// default connection properties

Environment

  • Cloud
  • Client version: jdbc-v2 0.12.0-rc1-SNAPSHOT, main at 7506301
  • Language version: Java 21
  • OS: macOS

ClickHouse Server

  • ClickHouse Server version: 26.10.4.207, also 25.8.33.6
  • ClickHouse Server non-default settings, if any: none
  • CREATE TABLE statements for tables involved: none, the query reads a literal
  • Sample data for all these tables: none

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions