Repository navigation
Description
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 b376ecd), 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)andsetObject(i, OffsetDateTime)fail withBinding value of type OBJECT is not yet supported for expected Arrow type Timestamp(...).setTimestampdrops 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):
- Unit. Avatica passes a
java.sql.Timestampas epoch milliseconds. The converter writes that number unchanged into all eight vector types, so only the millisecond vectors are right. - 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
TZvectors it shifts the instant by the client offset. java.time. The converter does(long) typedValue.toLocal(). Avatica wrapsLocalDateTime,InstantandOffsetDateTimeasOBJECT, so the cast throwsClassCastException.- Precision. Avatica truncates
java.sql.Timestampto milliseconds before the converter runs, so this cannot be fixed forsetTimestampinside the converter.java.timevalues would be the lossless path.
Proposed fix
- Convert the millisecond value to the unit of the target vector before
setSafe. - Accept
LocalDateTime,Instant,OffsetDateTimeandZonedDateTime, converted at full precision. - For
TZvectors, 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.timevalues.
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.
Activity
apacheGH-1540: Bind TIMESTAMP parameters in the vector unit and accep…
apacheGH-1540: Bind TIMESTAMP parameters in the vector unit and accep…
apacheGH-1540: Bind TIMESTAMP parameters in the vector unit and accep…