You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "shahriyar-novruzov (via GitHub)" <gi...@apache.org> on 2026/10/20 09:58:11 UTC
[PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
shahriyar-novruzov opened a new pull request, #1378:
URL: https://github.com/apache/arrow-java/pull/1378
### Rationale for this change
`DecimalAvaticaParameterConverter.bindParameter` casts the local value to `BigDecimal`:
```java
BigDecimal value = (BigDecimal) typedValue.toLocal();
```
That cast only holds when the client called `setBigDecimal`. `TypedValue.toLocal()` returns a `Double` for `Rep.DOUBLE`, a `Float` for `Rep.FLOAT` and so on, so `setDouble` against a decimal parameter fails with:
```
Binding value of type DOUBLE is not yet supported for expected Arrow type Decimal(38, 3, 128)
```
JDBC allows `setDouble` on a DECIMAL column, and tools rely on it — a CSV import that infers a numeric column as DOUBLE cannot write to any decimal column.
### What changes are included in this PR?
`DecimalParameterNarrower` widens the Avatica rep to `BigDecimal` and scales it to the target vector; the converter calls it instead of casting.
Two details:
- `BigDecimal.valueOf(double)` rather than `new BigDecimal(double)`: the constructor keeps the binary expansion, so `0.1` would arrive as `0.1000000000000000055511151231257827`.
- The value is scaled to `DecimalVector.getScale()` with HALF_UP. `DecimalUtility.checkPrecisionAndScale` rejects any other scale, so a `BigDecimal` the client scaled differently fails today as well, even through `setBigDecimal`.
Same shape as #477, which fixed DATE(MILLISECOND) binding.
### Are these changes tested?
Yes. `DecimalAvaticaParameterConverterTest` covers DOUBLE, FLOAT, INTEGER, LONG and BigDecimal binding, rounding to the vector scale, and a non-decimal vector. Reverting the converter to the cast fails 8 of its 10 tests.
### Are there any user-facing changes?
`setDouble`, `setFloat`, `setInt` and `setLong` now bind to DECIMAL parameters, and `setBigDecimal` accepts a value whose scale differs from the column's.
* GitHub Issue: #1377
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "shahriyar-novruzov (via GitHub) via github" <gi...@arrow.apache.org>.
shahriyar-novruzov commented on PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#issuecomment-6851833231
Fixed the float precision point from the last review.
`toLocal()` does hand back a `Float` for `Rep.FLOAT`, so the branch was reachable. Widening it to a double first exposes the gap between the two binary formats: `1.0005f` arrives as `1.000499963760376` and rounds to `1.000` at scale 3, not the `1.001` the client sent. The coercer now reads a float through `Float.toString()`, which gives the shortest decimal that round-trips at float width, and keeps `BigDecimal.valueOf` for doubles.
`testBindFloatKeepsTheDigitsTheClientSent` covers it. The existing `2.5f` case can't, since 2.5 is exact in binary.
Also rebased on main, ran `mvn spotless:apply` for the formatting failure, and changed the issue line to `Closes #1377.` so the linked-issue check sees it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#discussion_r4324216035
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalParameterNarrower.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * Widens Avatica {@link TypedValue}s bound to DECIMAL parameters to {@link BigDecimal}, so calls
+ * like {@code setDouble} against an Arrow {@code Decimal} parameter bind instead of throwing.
+ */
+final class DecimalParameterNarrower {
+
+ private DecimalParameterNarrower() {}
+
+ /**
+ * Returns the {@link BigDecimal} value of a {@link TypedValue} bound to a DECIMAL parameter,
+ * scaled to what the target vector stores.
+ *
+ * <p>A value is scaled rather than rejected on a mismatch: the client sent the number it had, and
+ * the column's scale is what it has to fit. Rounding is HALF_UP, as {@code setBigDecimal} does.
+ */
+ static BigDecimal toBigDecimal(TypedValue typedValue, int scale) {
+ return widen(typedValue).setScale(scale, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * Converts the local value to a {@link BigDecimal}, keeping the digits the client sent.
+ *
+ * <p>{@code BigDecimal.valueOf} rather than {@code new BigDecimal(double)}: the constructor keeps
Review Comment:
This should be a brief code comment and not a doc comment, IMO
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#issuecomment-6297934720
<!-- label_helper_comment -->
Thank you for opening a pull request!
Please label the PR with one or more of:
- bug-fix
- chore
- dependencies
- documentation
- enhancement
Also, add the 'breaking-change' label if appropriate.
See [CONTRIBUTING.md](https://github.com/apache/arrow-java/blob/main/CONTRIBUTING.md) for details.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#discussion_r4324341699
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalParameterNarrower.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * Widens Avatica {@link TypedValue}s bound to DECIMAL parameters to {@link BigDecimal}, so calls
+ * like {@code setDouble} against an Arrow {@code Decimal} parameter bind instead of throwing.
+ */
+final class DecimalParameterNarrower {
+
+ private DecimalParameterNarrower() {}
+
+ /**
+ * Returns the {@link BigDecimal} value of a {@link TypedValue} bound to a DECIMAL parameter,
+ * scaled to what the target vector stores.
+ *
+ * <p>A value is scaled rather than rejected on a mismatch: the client sent the number it had, and
+ * the column's scale is what it has to fit. Rounding is HALF_UP, as {@code setBigDecimal} does.
+ */
+ static BigDecimal toBigDecimal(TypedValue typedValue, int scale) {
+ return widen(typedValue).setScale(scale, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * Converts the local value to a {@link BigDecimal}, keeping the digits the client sent.
+ *
+ * <p>{@code BigDecimal.valueOf} rather than {@code new BigDecimal(double)}: the constructor keeps
+ * the binary expansion, so 0.1 arrives as 0.1000000000000000055511151231257827.
+ */
+ private static BigDecimal widen(TypedValue typedValue) {
+ final Object local = typedValue.toLocal();
+ if (local instanceof BigDecimal) {
+ return (BigDecimal) local;
+ }
+ if (local instanceof Double || local instanceof Float) {
+ return BigDecimal.valueOf(((Number) local).doubleValue());
+ }
+ if (local instanceof Number) {
+ return BigDecimal.valueOf(((Number) local).longValue());
+ }
+ // Anything else keeps the upstream failure: a cast error the binder reports as unsupported.
+ return (BigDecimal) local;
Review Comment:
Using a forced cast as control flow for unsupported types makes failures harder to diagnose (the resulting `ClassCastException` won’t include intent/context like rep/type). Prefer an explicit, intentional failure mode here (e.g., throwing an `IllegalArgumentException` with details about `typedValue.type`/`local.getClass()`), or returning a sentinel that the caller can use to return `false` for unsupported bindings.
##########
flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalAvaticaParameterConverterTest.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.math.BigDecimal;
+import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestExtension;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.calcite.avatica.ColumnMetaData;
+import org.apache.calcite.avatica.remote.TypedValue;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+/**
+ * Tests for {@link DecimalAvaticaParameterConverter}.
+ *
+ * <p>Clients call {@code setDouble} on parameters whose Arrow type is {@code Decimal}. The
+ * converter must widen the Avatica reps to BigDecimal and scale them to the vector instead of
+ * throwing.
+ */
+public class DecimalAvaticaParameterConverterTest {
+
+ @RegisterExtension
+ public static RootAllocatorTestExtension rootAllocatorTestExtension =
+ new RootAllocatorTestExtension();
+
+ private static final int PRECISION = 38;
+ private static final int SCALE = 3;
+
+ private DecimalVector vector;
+ private DecimalAvaticaParameterConverter converter;
+
+ @BeforeEach
+ public void setUp() {
+ vector =
+ new DecimalVector(
+ "decimal_param", rootAllocatorTestExtension.getRootAllocator(), PRECISION, SCALE);
+ vector.allocateNew(5);
+ converter = new DecimalAvaticaParameterConverter(new ArrowType.Decimal(PRECISION, SCALE, 128));
+ }
+
+ @AfterEach
+ public void tearDown() {
+ vector.close();
+ }
+
+ @Test
+ public void testBindDouble() {
+ // The reported shape: setDouble of 123.456 against a DECIMAL(38,3) parameter.
+ TypedValue typedValue = TypedValue.ofLocal(ColumnMetaData.Rep.DOUBLE, 123.456d);
+
+ boolean result = converter.bindParameter(vector, typedValue, 0);
+
+ assertTrue(result);
+ assertThat(vector.getObject(0), is(new BigDecimal("123.456")));
Review Comment:
These tests read from an Arrow vector via `getObject(0)` without setting `valueCount`. Arrow vectors commonly require `setValueCount(...)` to define the readable range, and relying on implicit behavior can make tests brittle across Arrow versions/implementations. Consider setting `vector.setValueCount(1)` (or matching the allocated size) before asserting on `getObject(...)`, or updating the test setup to establish a value count consistently.
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalParameterNarrower.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * Widens Avatica {@link TypedValue}s bound to DECIMAL parameters to {@link BigDecimal}, so calls
+ * like {@code setDouble} against an Arrow {@code Decimal} parameter bind instead of throwing.
+ */
+final class DecimalParameterNarrower {
Review Comment:
The class name `DecimalParameterNarrower` is potentially misleading given the implementation and Javadoc emphasize *widening* values to `BigDecimal` and then scaling/rounding. If there isn’t an existing project convention driving this name, consider renaming to something that reflects coercion/scaling (e.g., `DecimalParameterCoercer` or `DecimalParameterScaler`) to reduce confusion for future maintainers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "shahriyar-novruzov (via GitHub)" <gi...@apache.org>.
shahriyar-novruzov commented on PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#issuecomment-6290827359
Thanks — renamed the class to `DecimalParameterCoercer`, it widens and scales rather than narrows.
On the other two:
**The cast on unsupported types.** `AvaticaParameterBinder` already catches `ClassCastException` from the converters and rethrows it with the context this suggests adding:
```
Binding value of type DOUBLE is not yet supported for expected Arrow type Decimal(38, 3, 128)
```
It names both the Avatica rep and the Arrow type. Throwing `IllegalArgumentException` here instead would escape that catch, so the caller would get a less specific error, not a better one. Returning a sentinel would mean every converter grows a second failure path for the same outcome. Left the cast so an unsupported rep keeps failing exactly as it does today.
**`setValueCount` in the tests.** The converter tests in this package read back with `allocateNew(n)` + `getObject(i)` and no value count — the parameter path never sets one either, since the binder writes at an index and the statement sends the whole allocated batch. Matched the existing tests rather than introducing a different setup for one file.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "shahriyar-novruzov (via GitHub)" <gi...@apache.org>.
shahriyar-novruzov commented on code in PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#discussion_r4324914662
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalParameterNarrower.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * Widens Avatica {@link TypedValue}s bound to DECIMAL parameters to {@link BigDecimal}, so calls
+ * like {@code setDouble} against an Arrow {@code Decimal} parameter bind instead of throwing.
+ */
+final class DecimalParameterNarrower {
+
+ private DecimalParameterNarrower() {}
+
+ /**
+ * Returns the {@link BigDecimal} value of a {@link TypedValue} bound to a DECIMAL parameter,
+ * scaled to what the target vector stores.
+ *
+ * <p>A value is scaled rather than rejected on a mismatch: the client sent the number it had, and
+ * the column's scale is what it has to fit. Rounding is HALF_UP, as {@code setBigDecimal} does.
+ */
+ static BigDecimal toBigDecimal(TypedValue typedValue, int scale) {
+ return widen(typedValue).setScale(scale, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * Converts the local value to a {@link BigDecimal}, keeping the digits the client sent.
+ *
+ * <p>{@code BigDecimal.valueOf} rather than {@code new BigDecimal(double)}: the constructor keeps
+ * the binary expansion, so 0.1 arrives as 0.1000000000000000055511151231257827.
+ */
+ private static BigDecimal widen(TypedValue typedValue) {
+ final Object local = typedValue.toLocal();
+ if (local instanceof BigDecimal) {
+ return (BigDecimal) local;
+ }
+ if (local instanceof Double || local instanceof Float) {
+ return BigDecimal.valueOf(((Number) local).doubleValue());
+ }
+ if (local instanceof Number) {
+ return BigDecimal.valueOf(((Number) local).longValue());
+ }
+ // Anything else keeps the upstream failure: a cast error the binder reports as unsupported.
+ return (BigDecimal) local;
Review Comment:
`AvaticaParameterBinder` already catches `ClassCastException` from converters and rethrows it naming the rep and the Arrow type. An `IllegalArgumentException` would escape that catch and give a less specific error.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "shahriyar-novruzov (via GitHub)" <gi...@apache.org>.
shahriyar-novruzov commented on code in PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#discussion_r4324918179
##########
flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalAvaticaParameterConverterTest.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.math.BigDecimal;
+import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestExtension;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.calcite.avatica.ColumnMetaData;
+import org.apache.calcite.avatica.remote.TypedValue;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+/**
+ * Tests for {@link DecimalAvaticaParameterConverter}.
+ *
+ * <p>Clients call {@code setDouble} on parameters whose Arrow type is {@code Decimal}. The
+ * converter must widen the Avatica reps to BigDecimal and scale them to the vector instead of
+ * throwing.
+ */
+public class DecimalAvaticaParameterConverterTest {
+
+ @RegisterExtension
+ public static RootAllocatorTestExtension rootAllocatorTestExtension =
+ new RootAllocatorTestExtension();
+
+ private static final int PRECISION = 38;
+ private static final int SCALE = 3;
+
+ private DecimalVector vector;
+ private DecimalAvaticaParameterConverter converter;
+
+ @BeforeEach
+ public void setUp() {
+ vector =
+ new DecimalVector(
+ "decimal_param", rootAllocatorTestExtension.getRootAllocator(), PRECISION, SCALE);
+ vector.allocateNew(5);
+ converter = new DecimalAvaticaParameterConverter(new ArrowType.Decimal(PRECISION, SCALE, 128));
+ }
+
+ @AfterEach
+ public void tearDown() {
+ vector.close();
+ }
+
+ @Test
+ public void testBindDouble() {
+ // The reported shape: setDouble of 123.456 against a DECIMAL(38,3) parameter.
+ TypedValue typedValue = TypedValue.ofLocal(ColumnMetaData.Rep.DOUBLE, 123.456d);
+
+ boolean result = converter.bindParameter(vector, typedValue, 0);
+
+ assertTrue(result);
+ assertThat(vector.getObject(0), is(new BigDecimal("123.456")));
Review Comment:
The converter tests in this package read back with `allocateNew(n)` + `getObject(i)` and no value count. Matched them rather than introducing a different setup for one file.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "shahriyar-novruzov (via GitHub)" <gi...@apache.org>.
shahriyar-novruzov commented on PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#issuecomment-6290517095
Moved it to a code comment on the `BigDecimal.valueOf` line itself. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "shahriyar-novruzov (via GitHub)" <gi...@apache.org>.
shahriyar-novruzov commented on code in PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#discussion_r4346257971
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalParameterCoercer.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * Widens Avatica {@link TypedValue}s bound to DECIMAL parameters to {@link BigDecimal}, so calls
+ * like {@code setDouble} against an Arrow {@code Decimal} parameter bind instead of throwing.
+ */
+final class DecimalParameterCoercer {
+
+ private DecimalParameterCoercer() {}
+
+ /**
+ * Returns the {@link BigDecimal} value of a {@link TypedValue} bound to a DECIMAL parameter,
+ * scaled to what the target vector stores.
+ *
+ * <p>A value is scaled rather than rejected on a mismatch: the client sent the number it had, and
+ * the column's scale is what it has to fit. Rounding is HALF_UP, as {@code setBigDecimal} does.
+ */
+ static BigDecimal toBigDecimal(TypedValue typedValue, int scale) {
+ return widen(typedValue).setScale(scale, RoundingMode.HALF_UP);
+ }
+
+ private static BigDecimal widen(TypedValue typedValue) {
+ final Object local = typedValue.toLocal();
+ if (local instanceof BigDecimal) {
+ return (BigDecimal) local;
+ }
+ if (local instanceof Double || local instanceof Float) {
+ // valueOf, not new BigDecimal(double): the constructor keeps the binary expansion, so 0.1
+ // arrives as 0.1000000000000000055511151231257827.
+ return BigDecimal.valueOf(((Number) local).doubleValue());
+ }
+ if (local instanceof Number) {
+ return BigDecimal.valueOf(((Number) local).longValue());
+ }
Review Comment:
This one can't happen — Avatica has no rep for BigInteger (ColumnMetaData.Rep.VALUE_MAP.get(BigInteger.class) is null), so toLocal() returns it as a BigDecimal and the first branch takes it. The longValue() branch is only reached by the integral wrappers, where nothing is lost.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "shahriyar-novruzov (via GitHub)" <gi...@apache.org>.
shahriyar-novruzov commented on code in PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#discussion_r4346255148
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalParameterCoercer.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * Widens Avatica {@link TypedValue}s bound to DECIMAL parameters to {@link BigDecimal}, so calls
+ * like {@code setDouble} against an Arrow {@code Decimal} parameter bind instead of throwing.
+ */
+final class DecimalParameterCoercer {
+
+ private DecimalParameterCoercer() {}
+
+ /**
+ * Returns the {@link BigDecimal} value of a {@link TypedValue} bound to a DECIMAL parameter,
+ * scaled to what the target vector stores.
+ *
+ * <p>A value is scaled rather than rejected on a mismatch: the client sent the number it had, and
+ * the column's scale is what it has to fit. Rounding is HALF_UP, as {@code setBigDecimal} does.
+ */
+ static BigDecimal toBigDecimal(TypedValue typedValue, int scale) {
+ return widen(typedValue).setScale(scale, RoundingMode.HALF_UP);
+ }
+
+ private static BigDecimal widen(TypedValue typedValue) {
+ final Object local = typedValue.toLocal();
+ if (local instanceof BigDecimal) {
+ return (BigDecimal) local;
+ }
+ if (local instanceof Double || local instanceof Float) {
+ // valueOf, not new BigDecimal(double): the constructor keeps the binary expansion, so 0.1
+ // arrives as 0.1000000000000000055511151231257827.
+ return BigDecimal.valueOf(((Number) local).doubleValue());
+ }
Review Comment:
Good catch, fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#discussion_r4326217682
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalParameterCoercer.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * Widens Avatica {@link TypedValue}s bound to DECIMAL parameters to {@link BigDecimal}, so calls
+ * like {@code setDouble} against an Arrow {@code Decimal} parameter bind instead of throwing.
+ */
+final class DecimalParameterCoercer {
+
+ private DecimalParameterCoercer() {}
+
+ /**
+ * Returns the {@link BigDecimal} value of a {@link TypedValue} bound to a DECIMAL parameter,
+ * scaled to what the target vector stores.
+ *
+ * <p>A value is scaled rather than rejected on a mismatch: the client sent the number it had, and
+ * the column's scale is what it has to fit. Rounding is HALF_UP, as {@code setBigDecimal} does.
+ */
+ static BigDecimal toBigDecimal(TypedValue typedValue, int scale) {
+ return widen(typedValue).setScale(scale, RoundingMode.HALF_UP);
+ }
+
+ private static BigDecimal widen(TypedValue typedValue) {
+ final Object local = typedValue.toLocal();
+ if (local instanceof BigDecimal) {
+ return (BigDecimal) local;
+ }
+ if (local instanceof Double || local instanceof Float) {
+ // valueOf, not new BigDecimal(double): the constructor keeps the binary expansion, so 0.1
+ // arrives as 0.1000000000000000055511151231257827.
+ return BigDecimal.valueOf(((Number) local).doubleValue());
+ }
Review Comment:
`BigDecimal.valueOf(double)` throws `NumberFormatException` for NaN/Infinity. This changes failure mode compared to the previous direct cast (which would have produced a `ClassCastException` and, per the comment below, be handled by `AvaticaParameterBinder` as “unsupported binding”). To preserve consistent error handling, explicitly detect non-finite `Double`/`Float` values and fail in the same way as before (e.g., by throwing `ClassCastException` or by delegating to the final cast path).
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalAvaticaParameterConverter.java:
##########
@@ -31,9 +31,12 @@ public DecimalAvaticaParameterConverter(ArrowType.Decimal type) {}
@Override
public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) {
- BigDecimal value = (BigDecimal) typedValue.toLocal();
if (vector instanceof DecimalVector) {
- ((DecimalVector) vector).setSafe(index, value);
+ DecimalVector decimalVector = (DecimalVector) vector;
+ // The vector rejects any scale but its own, so widen and scale before writing.
+ BigDecimal value =
+ DecimalParameterCoercer.toBigDecimal(typedValue, decimalVector.getScale());
Review Comment:
The PR description references `DecimalParameterNarrower`, but the implementation introduces/uses `DecimalParameterCoercer`. Please align the PR description with the actual class name (or rename the class) so reviewers and future maintainers can map the change rationale to the code.
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalParameterCoercer.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * Widens Avatica {@link TypedValue}s bound to DECIMAL parameters to {@link BigDecimal}, so calls
+ * like {@code setDouble} against an Arrow {@code Decimal} parameter bind instead of throwing.
+ */
+final class DecimalParameterCoercer {
+
+ private DecimalParameterCoercer() {}
+
+ /**
+ * Returns the {@link BigDecimal} value of a {@link TypedValue} bound to a DECIMAL parameter,
+ * scaled to what the target vector stores.
+ *
+ * <p>A value is scaled rather than rejected on a mismatch: the client sent the number it had, and
+ * the column's scale is what it has to fit. Rounding is HALF_UP, as {@code setBigDecimal} does.
+ */
+ static BigDecimal toBigDecimal(TypedValue typedValue, int scale) {
+ return widen(typedValue).setScale(scale, RoundingMode.HALF_UP);
+ }
+
+ private static BigDecimal widen(TypedValue typedValue) {
+ final Object local = typedValue.toLocal();
+ if (local instanceof BigDecimal) {
+ return (BigDecimal) local;
+ }
+ if (local instanceof Double || local instanceof Float) {
+ // valueOf, not new BigDecimal(double): the constructor keeps the binary expansion, so 0.1
+ // arrives as 0.1000000000000000055511151231257827.
+ return BigDecimal.valueOf(((Number) local).doubleValue());
+ }
+ if (local instanceof Number) {
+ return BigDecimal.valueOf(((Number) local).longValue());
+ }
Review Comment:
This branch will silently truncate/overflow for `Number` implementations that don’t fit in `long` (notably `BigInteger`), producing an incorrect decimal value. Consider handling `BigInteger` explicitly (e.g., constructing a `BigDecimal` from it) and keeping `longValue()` only for known integral primitives/wrappers where truncation cannot occur.
##########
flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalAvaticaParameterConverterTest.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.math.BigDecimal;
+import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestExtension;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.calcite.avatica.ColumnMetaData;
+import org.apache.calcite.avatica.remote.TypedValue;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+/**
+ * Tests for {@link DecimalAvaticaParameterConverter}.
+ *
+ * <p>Clients call {@code setDouble} on parameters whose Arrow type is {@code Decimal}. The
+ * converter must widen the Avatica reps to BigDecimal and scale them to the vector instead of
+ * throwing.
+ */
+public class DecimalAvaticaParameterConverterTest {
+
+ @RegisterExtension
+ public static RootAllocatorTestExtension rootAllocatorTestExtension =
+ new RootAllocatorTestExtension();
+
+ private static final int PRECISION = 38;
+ private static final int SCALE = 3;
+
+ private DecimalVector vector;
+ private DecimalAvaticaParameterConverter converter;
+
+ @BeforeEach
+ public void setUp() {
+ vector =
+ new DecimalVector(
+ "decimal_param", rootAllocatorTestExtension.getRootAllocator(), PRECISION, SCALE);
+ vector.allocateNew(5);
+ converter = new DecimalAvaticaParameterConverter(new ArrowType.Decimal(PRECISION, SCALE, 128));
+ }
+
+ @AfterEach
+ public void tearDown() {
+ vector.close();
+ }
+
+ @Test
+ public void testBindDouble() {
+ // The reported shape: setDouble of 123.456 against a DECIMAL(38,3) parameter.
+ TypedValue typedValue = TypedValue.ofLocal(ColumnMetaData.Rep.DOUBLE, 123.456d);
Review Comment:
The new coercion logic introduces new edge-case behaviors for non-finite floating point values (NaN/Infinity) and for large numeric types (e.g., `BigInteger` if it can arrive via `TypedValue.toLocal()`). Adding targeted tests for these cases would help lock in the intended “unsupported binding” behavior and prevent regressions (especially given the change in exception type risk for NaN/Infinity).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "shahriyar-novruzov (via GitHub) via github" <gi...@arrow.apache.org>.
shahriyar-novruzov commented on PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#issuecomment-6853420088
@lidavidm could you approve the workflow runs when you get a chance? The rebase reset the approval, so `Test`, `Integration`, `Dev` and `RC` are all sitting at `action_required` and haven't run against the fixes.
`Ensure PR format` has gone green.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "shahriyar-novruzov (via GitHub)" <gi...@apache.org>.
shahriyar-novruzov commented on code in PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#discussion_r4324764935
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalParameterNarrower.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * Widens Avatica {@link TypedValue}s bound to DECIMAL parameters to {@link BigDecimal}, so calls
+ * like {@code setDouble} against an Arrow {@code Decimal} parameter bind instead of throwing.
+ */
+final class DecimalParameterNarrower {
+
+ private DecimalParameterNarrower() {}
+
+ /**
+ * Returns the {@link BigDecimal} value of a {@link TypedValue} bound to a DECIMAL parameter,
+ * scaled to what the target vector stores.
+ *
+ * <p>A value is scaled rather than rejected on a mismatch: the client sent the number it had, and
+ * the column's scale is what it has to fit. Rounding is HALF_UP, as {@code setBigDecimal} does.
+ */
+ static BigDecimal toBigDecimal(TypedValue typedValue, int scale) {
+ return widen(typedValue).setScale(scale, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * Converts the local value to a {@link BigDecimal}, keeping the digits the client sent.
+ *
+ * <p>{@code BigDecimal.valueOf} rather than {@code new BigDecimal(double)}: the constructor keeps
Review Comment:
Moved it to a code comment on the `BigDecimal.valueOf` line itself. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "shahriyar-novruzov (via GitHub)" <gi...@apache.org>.
shahriyar-novruzov commented on code in PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#discussion_r4324920934
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalParameterNarrower.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * Widens Avatica {@link TypedValue}s bound to DECIMAL parameters to {@link BigDecimal}, so calls
+ * like {@code setDouble} against an Arrow {@code Decimal} parameter bind instead of throwing.
+ */
+final class DecimalParameterNarrower {
Review Comment:
Renamed to DecimalParameterCoercer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "shahriyar-novruzov (via GitHub)" <gi...@apache.org>.
shahriyar-novruzov commented on code in PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#discussion_r4346260534
##########
flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalAvaticaParameterConverterTest.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.driver.jdbc.converter.impl;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.math.BigDecimal;
+import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestExtension;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.calcite.avatica.ColumnMetaData;
+import org.apache.calcite.avatica.remote.TypedValue;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+/**
+ * Tests for {@link DecimalAvaticaParameterConverter}.
+ *
+ * <p>Clients call {@code setDouble} on parameters whose Arrow type is {@code Decimal}. The
+ * converter must widen the Avatica reps to BigDecimal and scale them to the vector instead of
+ * throwing.
+ */
+public class DecimalAvaticaParameterConverterTest {
+
+ @RegisterExtension
+ public static RootAllocatorTestExtension rootAllocatorTestExtension =
+ new RootAllocatorTestExtension();
+
+ private static final int PRECISION = 38;
+ private static final int SCALE = 3;
+
+ private DecimalVector vector;
+ private DecimalAvaticaParameterConverter converter;
+
+ @BeforeEach
+ public void setUp() {
+ vector =
+ new DecimalVector(
+ "decimal_param", rootAllocatorTestExtension.getRootAllocator(), PRECISION, SCALE);
+ vector.allocateNew(5);
+ converter = new DecimalAvaticaParameterConverter(new ArrowType.Decimal(PRECISION, SCALE, 128));
+ }
+
+ @AfterEach
+ public void tearDown() {
+ vector.close();
+ }
+
+ @Test
+ public void testBindDouble() {
+ // The reported shape: setDouble of 123.456 against a DECIMAL(38,3) parameter.
+ TypedValue typedValue = TypedValue.ofLocal(ColumnMetaData.Rep.DOUBLE, 123.456d);
Review Comment:
Added three: NaN, both infinities, and a value too large for a long
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalAvaticaParameterConverter.java:
##########
@@ -31,9 +31,12 @@ public DecimalAvaticaParameterConverter(ArrowType.Decimal type) {}
@Override
public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) {
- BigDecimal value = (BigDecimal) typedValue.toLocal();
if (vector instanceof DecimalVector) {
- ((DecimalVector) vector).setSafe(index, value);
+ DecimalVector decimalVector = (DecimalVector) vector;
+ // The vector rejects any scale but its own, so widen and scale before writing.
+ BigDecimal value =
+ DecimalParameterCoercer.toBigDecimal(typedValue, decimalVector.getScale());
Review Comment:
Fixed the description
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-1377: [FlightRPC] Bind DOUBLE to DECIMAL parameters [arrow-java]
Posted by "jbonofre (via GitHub) via github" <gi...@arrow.apache.org>.
jbonofre commented on PR #1378:
URL: https://github.com/apache/arrow-java/pull/1378#issuecomment-6908660879
I'm reviewing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org