Skip to content

feat(bigquery-jdbc): support picosecond in PreparedStatement parameters and batching - #14373

Open
keshavdandeva wants to merge 3 commits into
mainfrom
jdbc-picosecond-support-6
Open

feat(bigquery-jdbc): support picosecond in PreparedStatement parameters and batching#14373
keshavdandeva wants to merge 3 commits into
mainfrom
jdbc-picosecond-support-6

Conversation

@keshavdandeva

Copy link
Copy Markdown
Contributor

b/545231211

This PR adds picosecond timestamp support for PreparedStatement parameters and batch execution (EnableTimestampPicos=1), refactors statement pre-flight validation, and optimizes temporal string parsing.

Changes

  • BigQueryParameterHandler: Supported enableTimestampPicos to preserve up to 12 fractional digits without premature microsecond truncation, cleaned up constructors into a final-field telescoping chain, and deleted the unused 2-arg formatValueForQueryParameter overload.
  • BigQueryPreparedStatement: Propagated isEnableTimestampPicos across statement initialization and batch parameter handling (getStandardBatchJobConfiguration).
  • BigQueryStatement: Converted getJobConfig into a pure configuration builder and extracted statement checks into validateExecution().
  • BigQueryTemporalUtility: Consolidated fractional seconds truncation into a single helper (truncateFractionalSeconds) across all temporal parsers.
  • Unit Tests: Added coverage for high-precision parameter binding and batching, while deduplicating helper tests and removing dead mock stubs.

Key Architectural Decisions

1. Legacy SQL Exception & Pre-Flight Validation (BigQueryStatement)

  • Fail-Fast over Silent Data Loss: Legacy SQL cannot represent 12-digit picoseconds. Silently falling back to Legacy SQL would drop 6 decimal places of precision without warning. To prevent silent data corruption and maintain parity with the Simba driver, we fail execution explicitly.
  • Pre-Flight Placement: This check previously lived inside getJobConfig. A configuration builder should not enforce fatal query-blocking logic. Moving it to validateExecution() alongside checkClosed() ensures we fail fast at statement execution entry—avoiding false "Executing query..." logs and unnecessary OpenTelemetry trace spans.
  • Exception Classification: We intentionally use BigQueryJdbcException (general SQLException) instead of SQLSyntaxErrorException. The query itself (e.g., SELECT 1) is syntactically valid; the failure is a driver/session configuration conflict, not a SQL grammar defect.

2. ASCII Character Scanning Optimization (BigQueryTemporalUtility)

  • In truncateFractionalSeconds, we replaced Character.isDigit(c) with a direct ASCII check (c >= '0' && c <= '9') and cached str.length().
  • Because ISO-8601 and JDBC timestamp literals are strictly ASCII, avoiding Character.isDigit eliminates repeated Unicode table lookups and branching in the fractional scanning loop, reducing CPU overhead on hot result-set parsing paths.

@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 introduces support for picosecond-precision timestamps in the BigQuery JDBC driver when enableTimestampPicos is enabled. It updates parameter formatting, adds execution validation to prevent using picosecond data with Legacy SQL, and refactors temporal utilities to support configurable fractional second truncation. The reviewer pointed out a potential bug where replacing all occurrences of 'T' with a space in timestamp strings could corrupt timezone names (e.g., "America/Toronto"), and suggested replacing 'T' only at the standard ISO-8601 separator position.

@keshavdandeva

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 introduces support for picosecond timestamp precision in the BigQuery JDBC driver, controlled by the enableTimestampPicos flag. It refactors parameter handling and temporal utilities to dynamically truncate fractional seconds, and adds validation to prevent using picosecond precision with Legacy SQL. Feedback includes suggestions to robustly handle both uppercase and lowercase 'T' separators in ISO 8601 strings, and to add a guard clause against negative precision values in the truncation utility.

@keshavdandeva
keshavdandeva marked this pull request as ready for review September 14, 2026 15:31
@keshavdandeva
keshavdandeva requested review from a team as code owners September 14, 2026 15:31
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