See the following reproducer with explanations. Inner type is reported as SMALLINT, whereas it should be Array(INTEGER) again. Leads to errors down stream. Run with java -ea …
import java.sql.DriverManager;
import java.sql.JDBCType;
import java.sql.SQLException;
import java.util.Properties;
public class App2 {
public static void main(String... a) throws SQLException {
var properties = new Properties();
properties.setProperty("user", "username");
properties.setProperty("password", "password");
try (var con = DriverManager.getConnection("jdbc:clickhouse://localhost:18123", properties);
var stmt = con.createStatement()) {
var rs = stmt.executeQuery("SELECT [1,2,3]");
var meta = rs.getMetaData();
assert meta.getColumnType(1) == JDBCType.ARRAY.getVendorTypeNumber();
rs.next();
var array = rs.getArray(1);
assert array.getBaseType() == JDBCType.SMALLINT.getVendorTypeNumber();
rs.close();
rs = stmt.executeQuery("SELECT [[1,2,3]]");
meta = rs.getMetaData();
assert meta.getColumnType(1) == JDBCType.ARRAY.getVendorTypeNumber();
rs.next();
array = rs.getArray(1);
// This should not hold true, it's an array again and actually materialized as array
assert array.getBaseType() == JDBCType.SMALLINT.getVendorTypeNumber();
var arrayResult = array.getResultSet();
arrayResult.next();
// get the actual array
System.out.println(arrayResult.getObject(2));
// but our system is lured onto the wrong path and fails
System.out.println(arrayResult.getInt(2));
}
}
}
Error:
Exception in thread "main" java.sql.SQLException: Value of class [Ljava.lang.Short; cannot be converted to class java.lang.Integer
at com.clickhouse.jdbc.types.ArrayResultSet.convertValue(ArrayResultSet.java:146)
at com.clickhouse.jdbc.types.ArrayResultSet.getValueAsObject(ArrayResultSet.java:168)
at com.clickhouse.jdbc.types.ArrayResultSet.getInt(ArrayResultSet.java:234)
at App2.main(App2.java:36)
See the following reproducer with explanations. Inner type is reported as
SMALLINT, whereas it should beArray(INTEGER)again. Leads to errors down stream. Run withjava -ea …Error: