Skip to content

GH-1377: [FlightRPC] Bind DOUBLE to DECIMAL parameters - #1378

Open
shahriyar-novruzov wants to merge 4 commits into
apache:mainfrom
shahriyar-novruzov:gh-1377-decimal-double-binding
Open

shahriyar-novruzov wants to merge 4 commits into
apache:mainfrom
shahriyar-novruzov:gh-1377-decimal-double-binding

Conversation

@shahriyar-novruzov

@shahriyar-novruzov shahriyar-novruzov commented Oct 20, 2026 •

Copy link
Copy Markdown

Rationale for this change

JDBC allows setDouble on a DECIMAL column, and tools rely on it.

What changes are included in this PR?

DecimalParameterCoercer widens the Avatica rep to BigDecimal and scales it to the target vector; the converter calls it instead of casting.

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.

DecimalAvaticaParameterConverter cast the local value to BigDecimal, which
only holds when the client called setBigDecimal. TypedValue.toLocal() returns
a Double for Rep.DOUBLE, so setDouble against a decimal parameter failed with
"Binding value of type DOUBLE is not yet supported".

The converter now widens the value and scales it to the vector, which rejects
any scale but its own.
/**
* 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be a brief code comment and not a doc comment, IMO

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Moved it to a code comment on the BigDecimal.valueOf line itself. Thanks.

@lidavidm
lidavidm requested a balanced review from Copilot October 20, 2026 11:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Enables JDBC-style numeric bindings (e.g., setDouble) to Arrow DECIMAL parameters by coercing Avatica TypedValue inputs into scaled BigDecimal values before writing to DecimalVector.

Changes:

  • Added DecimalParameterNarrower to widen numeric Avatica reps into BigDecimal and apply vector scale rounding (HALF_UP).
  • Updated DecimalAvaticaParameterConverter to use the new coercion path instead of directly casting.
  • Added comprehensive JUnit tests for multiple numeric reps, rounding behavior, and non-decimal vectors.
File Description
flight/​flight-sql-jdbc-core/​src/​main/​java/​org/​apache/​arrow/​driver/​jdbc/​converter/​impl/​DecimalAvaticaParameterConverter.java Uses DecimalParameterNarrower to coerce inputs to scaled BigDecimal before writing to the vector.
flight/​flight-sql-jdbc-core/​src/​main/​java/​org/​apache/​arrow/​driver/​jdbc/​converter/​impl/​DecimalParameterNarrower.java Introduces shared logic to widen/scale Avatica values to BigDecimal with HALF_UP rounding.
flight/​flight-sql-jdbc-core/​src/​test/​java/​org/​apache/​arrow/​driver/​jdbc/​converter/​impl/​DecimalAvaticaParameterConverterTest.java Adds coverage for DOUBLE/FLOAT/INTEGER/LONG/BigDecimal bindings, scaling/rounding, and non-decimal rejection.

Review effort: Lite

@lidavidm
lidavidm requested a balanced review from Copilot October 20, 2026 14:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@github-actions

This comment has been minimized.

BigDecimal.valueOf raises NumberFormatException for non-finite doubles,
which AvaticaParameterBinder does not catch. Before this converter widened
doubles, the same value failed as a ClassCastException and came back as
"Binding value of type DOUBLE is not yet supported". Throwing the cast error
keeps that message.

Also tests that a value too large for a long survives: Avatica has no rep
for BigInteger, so toLocal() returns a BigDecimal and the longValue()
branch is unreachable for it.
@lidavidm lidavidm changed the title GH-1377: [FlightRPC][Java] Bind DOUBLE to DECIMAL parameters GH-1377: [FlightRPC] Bind DOUBLE to DECIMAL parameters Oct 22, 2026
@lidavidm lidavidm added the enhancement PRs that add or improve features. label Nov 5, 2026
@lidavidm
lidavidm requested a balanced review from Copilot November 5, 2026 03:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Promoting Float inputs to double introduces decimal precision artifacts and incorrect rounding that the current 2.5f test does not detect.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve float precision during decimal conversion

flight/​flight-sql-jdbc-core/​src/​main/​java/​org/​apache/​arrow/​driver/​jdbc/​converter/​impl/​DecimalParameterCoercer.java:57

For Float inputs, promoting to double before decimal conversion introduces extra digits: 1.0005f at scale 3 rounds to 1.000 instead of 1.001, and 0.1f at scale 9 becomes 0.100000001. Convert finite floats through Float.toString(), keeping BigDecimal.valueOf for doubles. Add a regression test with an inexact float, since the current 2.5f case cannot detect this.

4 resolved since last review

Review effort: Balanced

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

Labels

enhancement PRs that add or improve features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants