xxlaykxx opened a new issue, #1540:
URL: https://github.com/apache/arrow-java/issues/1540

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   With the Arrow Flight SQL JDBC driver 20.0.0 (same code on `main` at 
b376ecd9), `TIMESTAMP` prepared statement parameters are bound with the wrong 
value unless the parameter type is `Timestamp(MILLISECOND)` without a timezone. 
This is the parameter-binding counterpart of #1539.
   
   #### Reproduce
   
   Bind `Timestamp.valueOf("2024-03-15 12:34:56.123456789")` with 
`PreparedStatement.setTimestamp` to a parameter of each Arrow timestamp type.
   
   #### Actual
   
   | Parameter type | Client timezone | Value bound |
   | --- | --- | --- |
   | `Timestamp(SECOND)` | UTC | +56173-10-12T06:15:23 |
   | `Timestamp(MILLISECOND)` | UTC | 2024-03-15T12:34:56.123 |
   | `Timestamp(MICROSECOND)` | UTC | 1970-01-20T19:08:26.096123 |
   | `Timestamp(NANOSECOND)` | UTC | 1970-01-01T00:28:30.506096123 |
   | `Timestamp(MILLISECOND, "UTC")` | Europe/Berlin | 1710509696123 (true 
instant is 1710502496123) |
   
   * `setObject(i, LocalDateTime)`, `setObject(i, Instant)` and `setObject(i, 
OffsetDateTime)` fail with `Binding value of type OBJECT is not yet supported 
for expected Arrow type Timestamp(...)`.
   * `setTimestamp` drops everything below milliseconds, so there is no way to 
bind a microsecond or nanosecond value.
   
   #### Expected
   
   The bound value equals the value passed in, converted to the unit of the 
parameter. For a parameter with a timezone, the bound value is the instant of 
the `java.sql.Timestamp`, independent of the client timezone. `java.time` 
values are accepted and keep their full precision.
   
   #### Cause
   
   All in `TimestampAvaticaParameterConverter.bindParameter` 
(`flight/flight-sql-jdbc-core`):
   
   1. **Unit.** Avatica passes a `java.sql.Timestamp` as epoch milliseconds. 
The converter writes that number unchanged into all eight vector types, so only 
the millisecond vectors are right.
   2. **Timezone columns.** Avatica adds the offset of the connection calendar 
to the milliseconds, which gives wall-clock time. That suits a timestamp 
without a timezone, but for the `TZ` vectors it shifts the instant by the 
client offset.
   3. **`java.time`.** The converter does `(long) typedValue.toLocal()`. 
Avatica wraps `LocalDateTime`, `Instant` and `OffsetDateTime` as `OBJECT`, so 
the cast throws `ClassCastException`.
   4. **Precision.** Avatica truncates `java.sql.Timestamp` to milliseconds 
before the converter runs, so this cannot be fixed for `setTimestamp` inside 
the converter. `java.time` values would be the lossless path.
   
   #### Proposed fix
   
   * Convert the millisecond value to the unit of the target vector before 
`setSafe`.
   * Accept `LocalDateTime`, `Instant`, `OffsetDateTime` and `ZonedDateTime`, 
converted at full precision.
   * For `TZ` vectors, bind the true instant instead of the calendar-adjusted 
wall-clock value.
   * Tests for all eight vector types, a non-UTC default timezone, and 
`java.time` values.
   
   Binding the true instant for `TZ` vectors changes behaviour for clients that 
compensate for the shift today; I would like guidance on whether that is 
acceptable.
   
   I can work on a PR for this.
   


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