Repository navigation
fix(bigquery-jdbc): preserve Timestamp instant in PreparedStatement and CallableStatement Calendar overloads - #14640
keshavdandeva wants to merge 3 commits into
Conversation
…t` and `CallableStatement` Calendar overloads
There was a problem hiding this comment.
Code Review
This pull request simplifies timestamp handling in BigQueryCallableStatement and BigQueryPreparedStatement by removing the BigQueryTemporalUtility.convertTimestampWithCalendar utility and delegating Calendar-based timestamp getters and setters to their non-Calendar overloads. However, feedback highlights that ignoring the Calendar parameter entirely may cause issues with timezone-naive DATETIME values, which should be interpreted using the provided Calendar's timezone. Additionally, several test updates modify the JVM-wide default timezone (TimeZone.setDefault), which can introduce flakiness and race conditions during parallel test execution; it is recommended to dynamically select a test timezone instead.
b/565785264
Summary
Fixes an issue where passing a
CalendartoPreparedStatement.setTimestamporCallableStatement.setTimestamp/getTimestampcorrupted the underlying UTC instant by shifting it byJVM_offset - Calendar_offset(or2 * (JVM_offset - Calendar_offset)on aCallableStatementsetter-to-getter round trip).Root Cause
A
java.sql.Timestampalready represents an absolute UTC epoch instant (milliseconds + nanos), and BigQuery'sTIMESTAMPtype is a timezone-aware absolute instant. Previously, theCalendaroverloads calledBigQueryTemporalUtility.convertTimestampWithCalendar(ts, cal), which extracted the JVM-local wall-clock fields (ts.toLocalDateTime()) and re-anchored them incal.getTimeZone(), shifting the epoch instant whenever theCalendartimezone differed from the JVM default timezone.Changes
BigQueryPreparedStatement: DelegatesetTimestamp(int, Timestamp, Calendar)directly tosetTimestamp(int, Timestamp).BigQueryCallableStatement: DelegategetTimestamp(int, Calendar),getTimestamp(String, Calendar), andsetTimestamp(String, Timestamp, Calendar)directly to their non-Calendarcounterparts.BigQueryTemporalUtility: Remove unusedconvertTimestampWithCalendar(Timestamp, Calendar)helper.BigQueryPreparedStatementSettersTest,BigQueryCallableStatementTest,BigQueryTemporalUtilityTest,ITCallableStatementTest) to verifyTimestamppreservation across distinct JVM (America/New_York) andCalendar(Asia/Tokyo) timezones.