Skip to content

Conversation

@dolfinus
Copy link
Contributor

@dolfinus dolfinus commented Oct 29, 2025

Summary

I've faced an issue when reading Array(Decimal) with clickhouse-jdbc 0.9.2 and Spark 3.5.7 - instead of converting values to Spark's DecimalType, it failed with exception:

Exception java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class [Ljava.math.BigDecimal; ([Ljava.lang.Object; and [Ljava.math.BigDecimal; are in module java.base of loader 'bootstrap')

This is because JdbcUtils.convert(value, java.math.BigDecimal.class, column) returns Object[], and Java doesn't allow casts like those:

(java.math.BigDecimal[]) new Object[]{};

Even if each item of array is actually a BigDecimal.

Now this method returns BigDecimal[] for these arguments. This requires some reflection usage to construct T[] with T known only in runtime.

I haven't run integration tests on this yet.

Checklist

Delete items not relevant to your PR:

@CLAassistant
Copy link

CLAassistant commented Oct 29, 2025

CLA assistant check
All committers have signed the CLA.

@dolfinus dolfinus changed the title [jdbc-v2] ResultSetImpl.getObject() returns T[] instead of Object[] for array columns [jdbc-v2] ResultSetImpl.getObject() returns T[] instead of Object[] for array columns Oct 29, 2025
Copy link

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 🤙

💡 To request another review, post a new comment with "/windsurf-review".

@dolfinus dolfinus force-pushed the bugfix/object-array branch from f5d3319 to e117cb3 Compare October 29, 2025 13:27
@chernser
Copy link
Contributor

Good day, @dolfinus !
Thank you for contributing!

However getObject() by default should return Array object for all arrays.
Defined in 8.9.3 JDBC Types Mapped to Java Object Types

There is a java.sql.ResultSet#getObject(int, java.util.Map<java.lang.String,java.lang.Class<?>>) that should be used in case user wants stripped array.

@dolfinus
Copy link
Contributor Author

dolfinus commented Oct 29, 2025

master branch already contains clause:

else if (type != java.sql.Array.class && value instanceof List<?>

The only thing changed there is that generic Object[] replaced with T[].
If PR title is misleading, I can update it.

@chernser
Copy link
Contributor

@dolfinus
I'll review this week.

@dolfinus dolfinus changed the title [jdbc-v2] ResultSetImpl.getObject() returns T[] instead of Object[] for array columns [jdbc-v2] Convert Clickhouse Array(T) to Java T[] instead of Object[] Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants