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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
