xxlaykxx opened a new pull request, #1542:
URL: https://github.com/apache/arrow-java/pull/1542

   ## What's Changed
   
   `TIMESTAMP` prepared statement parameters in the Flight SQL JDBC driver were 
bound with the wrong value unless the parameter was in milliseconds: 
`TimestampAvaticaParameterConverter` wrote the epoch-millisecond value from 
Avatica unchanged into second, microsecond and nanosecond vectors. `java.time` 
values were rejected.
   
   The change is in `TimestampAvaticaParameterConverter` 
(`flight/flight-sql-jdbc-core`):
   
   * **Unit.** The value is converted to the unit of the parameter vector, for 
all eight timestamp vector types. Values before 1970 round towards negative 
infinity.
   * **`java.time` values.** `PreparedStatement.setObject` accepts 
`LocalDateTime`, `Instant`, `OffsetDateTime` and `ZonedDateTime` at full 
precision. They failed before with `Binding value of type OBJECT is not yet 
supported for expected Arrow type Timestamp(...)`. This is also the only 
lossless path, because Avatica truncates `java.sql.Timestamp` to milliseconds 
before the converter sees it.
     * `LocalDateTime` is bound as wall-clock time. For a parameter with a 
timezone it is interpreted in that timezone, which matches `getObject(i, 
LocalDateTime.class)` on the read side.
     * `Instant`, `OffsetDateTime` and `ZonedDateTime` bind the instant for a 
parameter with a timezone. For a parameter without a timezone they are rejected 
with `UnsupportedOperationException`, as 
`ArrowFlightJdbcTimeStampVectorAccessor` does when reading.
   * **Overflow.** A value that does not fit in the unit (for example year 2300 
in nanoseconds) fails with `ArithmeticException` instead of binding a wrong 
value.
   
   ### Not changed: `setTimestamp` on a parameter with a timezone
   
   Point 2 of #1540 is left as it is. Avatica passes a `java.sql.Timestamp` as 
its wall-clock time, and that value is still bound to a timezone parameter 
without adjusting it to the instant. The read side has the matching behaviour: 
`getTimestamp` on a timezone column returns the wall-clock time of the column 
and keeps that for backward compatibility, so for a UTC column a value read 
with `getTimestamp` and bound with `setTimestamp` round-trips. Binding the 
instant would break that unless the read side changes too, and the converter 
cannot see which calendar Avatica applied. Clients that need the instant can 
now bind `Instant` or `OffsetDateTime`. Guidance on whether to change this is 
welcome.
   
   Correction to #1540: the last row of its "Actual" table gives 
`1710509696123` for a `Europe/Berlin` client. The value in a real JVM is 
`1710506096123`, the wall-clock time as if it was UTC; the larger number came 
from changing the default timezone in the reproduction after Avatica had cached 
it.
   
   ### Testing
   
   * New `TimestampAvaticaParameterConverterTest`: all four units with and 
without a timezone, a value before the epoch, each `java.time` type, rejection 
on a parameter without a timezone, and overflow.
   * `mvn -pl flight/flight-sql-jdbc-core -am verify` for the driver tests: 
1373 tests, 0 failures, 6 errors. The 6 errors are TLS connection tests that 
need `testing/data/flight/cert0.pem`; the `testing` submodule was not checked 
out locally. The style and static checks pass.
   * Not tested end to end against a real Flight SQL server.
   
   The `TIME` counterpart is #1541.
   
   AI assistance disclosure: this change and description were prepared with the 
help of an AI coding assistant; the checks above were run locally.
   
   Closes #1540.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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