Skip to content

fix(bigquery-jdbc): honor Calendar timezone and prevent ClassCastException in ResultSet temporal getters - #14657

Open
keshavdandeva wants to merge 2 commits into
mainfrom
jdbc/fix-calendar-getters
Open

keshavdandeva wants to merge 2 commits into
mainfrom
jdbc/fix-calendar-getters

Conversation

@keshavdandeva

Copy link
Copy Markdown
Contributor

b/565791346

Summary

Fixes two bugs in ResultSet.getDate(col, Calendar), ResultSet.getTime(col, Calendar), and ResultSet.getTimestamp(col, Calendar):

  1. Calendar ignored on DATE, TIME, and DATETIME columns:
    • Previously, the Calendar getter overloads called getObject(columnIndex) first with zone = null, which boxed raw values into Date, Time, or Timestamp anchored in the JVM default timezone before BigQueryTypeRegistry.convert(..., zone) ran.
    • Arrow DATE (LocalDate / Integer) and DATETIME (LocalDateTime) branches in BigQueryTypeRegistry also used Date.valueOf(...) and Timestamp.valueOf(...), ignoring zone.
  2. ClassCastException on cross-type conversions (e.g., getDate / getTime on DATETIME or TIMESTAMP columns):
    • BigQueryTypeRegistry.convert(input, bqType, targetClass, zoneId) dispatched solely by bqType, returning a Timestamp for DATETIME and TIMESTAMP columns even when targetClass was Date.class or Time.class.

Changes

  • Added getObject(int columnIndex, ZoneId zone) to BigQueryBaseResultSet, BigQueryJsonResultSet, and BigQueryArrowResultSet so the Calendar's ZoneId is applied during initial unboxing for zone-less types (DATE, TIME, DATETIME), while continuing to ignore Calendar on TIMESTAMP columns per the JDBC specification.
  • Overloaded boxDate(LocalDate, ZoneId), boxDateTime(LocalDateTime, ZoneId), and boxTime(LocalTime, ZoneId) in BigQueryTemporalUtility and wired them into BigQueryTypeRegistry.
  • Updated BigQueryTypeRegistry.convert(Object, StandardSQLTypeName, Class<T>, ZoneId) to delegate to the target class descriptor when the column descriptor returns an intermediate type.
  • Added unit tests in BigQueryJsonResultSetTest, BigQueryArrowResultSetTest, and BigQueryTypeRegistryTest.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors temporal type handling and timezone conversions across BigQuery JDBC result sets and the type registry, introducing ZoneId-aware boxing and conversion methods. Feedback on these changes highlights a potential JDBC specification compliance issue where Calendar timezones are ignored for TIMESTAMP columns, as well as backward compatibility concerns regarding new coercion exceptions for INT64 columns in getTime and getTimestamp. Additionally, a bug was identified in BigQueryTypeRegistry where Class.isInstance fails on primitive types, which can be resolved by wrapping them.

@keshavdandeva
keshavdandeva marked this pull request as ready for review October 14, 2026 20:27
@keshavdandeva
keshavdandeva requested review from a team as code owners October 14, 2026 20:27

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant