Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set an array of doubles #1102

Closed
chrix75 opened this issue Oct 7, 2022 · 2 comments
Closed

Can't set an array of doubles #1102

chrix75 opened this issue Oct 7, 2022 · 2 comments
Labels

Comments

@chrix75
Copy link

chrix75 commented Oct 7, 2022

I've got a table with a column that has type Array(Nullable(Float64)).

In my Java code, I do something like:

  Double[] values = {1.0};
  preparedStatement.setArray(1, preparedStatement.getConnection().createArrayOf("DOUBLE", values));

When the statement is executed, I get a cast exception: class [Ljava.lang.Double; cannot be cast to class [D ([Ljava.lang.Double; and [D are in module java.base of loader 'bootstrap')

I read the code and the cause comes from the class ClickHouseRowBinaryProcessor.MappedFunctions in the method writeArray.
We have this line: double[] array = (double[])value.asObject();
But the result type of value.asObject() is Double[], it can't be cast to double[]

@zhicwu
Copy link
Contributor

zhicwu commented Oct 7, 2022

Thanks @chrix75, it does look like a bug. I'm in the middle of refactoring to better support unsigned types as well as arrays and tuples. I'll definitely fix this and add tests accordingly.

@zhicwu zhicwu added the bug label Oct 7, 2022
@zhicwu
Copy link
Contributor

zhicwu commented May 19, 2023

Fixed in PR #1124. It is strongly recommended to use preparedStatement.setObject(<index>, new double[] {1.0D}) rather than createArrayOf to prevent unnecessary overhead from the creation of additional objects.

@zhicwu zhicwu closed this as completed May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants