shahriyar-novruzov opened a new issue, #1377:
URL: https://github.com/apache/arrow-java/issues/1377

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   Arrow version 19.0.0, Flight SQL JDBC driver.
   
   `DecimalAvaticaParameterConverter.bindParameter` casts the local value to 
`BigDecimal`:
   
   
https://github.com/apache/arrow-java/blob/main/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalAvaticaParameterConverter.java#L33-L41
   
   ```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:
   
   ```
   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. DBeaver's 
CSV import infers a numeric column as DOUBLE, so importing into any decimal 
column fails.
   
   ### Reproduction
   
   ```sql
   CREATE TABLE target (id INT, money DECIMAL(38,3));
   ```
   
   ```java
   PreparedStatement ps = conn.prepareStatement("INSERT INTO target VALUES (?, 
?)");
   ps.setInt(1, 1);
   ps.setDouble(2, 123.456);   // throws
   ps.executeUpdate();
   ```
   
   ### Expected
   
   The converter widens the value to `BigDecimal` and scales it to the vector, 
the way `setBigDecimal` already works.
   
   Two details matter:
   
   - `BigDecimal.valueOf(double)` rather than `new BigDecimal(double)`: the 
constructor keeps the binary expansion, so `0.1` becomes 
`0.1000000000000000055511151231257827`.
   - `DecimalVector.set` rejects any scale but its own 
(`DecimalUtility.checkPrecisionAndScale`), so the value has to be scaled before 
the write. `BigDecimal` of a different scale fails today for the same reason, 
even when the client did call `setBigDecimal`.
   
   Same shape as #477, which fixed DATE(MILLISECOND) binding.
   
   ### Component(s)
   
   FlightRPC, Java
   


-- 
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]

Reply via email to