Skip to content

fix(bigquery-jdbc): validate LargeResult properties and use UUID temp tables with WRITE_EMPTY - #15257

Open
keshavdandeva wants to merge 1 commit into
mainfrom
jdbc/fix-largeResultDataset-validation
Open

keshavdandeva wants to merge 1 commit into
mainfrom
jdbc/fix-largeResultDataset-validation

Conversation

@keshavdandeva

@keshavdandeva keshavdandeva commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

b/584840569

Summary of Changes

  1. Property validation (DataSource, BigQueryStatement):
    • Reject negative LargeResultsDatasetExpirationTime via existing DataSource.validateNonNegative(...) while preserving 0 (falls back to the 1-hour default 3600000 ms in BigQueryStatement) for backwards compatibility with existing =0 URLs.
    • Validate LargeResultTable without LargeResultDataset under Standard SQL before running getQueryType dry-run in BigQueryStatement.executeImpl, avoiding a wasted dry-run RPC and failing fast with BigQueryJdbcException.
  2. Sink-level log sanitization (BigQueryStatement):
    • Sanitize this.querySettings.toString() via BigQueryConnection.sanitizeForLog(...) in logQueryExecutionStart, protecting all query settings fields against log injection without adding setter-level character rejections.
  3. Collision-free generated temp tables & idempotent retries (BigQueryStatement):
    • Replace temp_table_<millis>_<random(0..9998)> with temp_table_<uuid> and use JobInfo.WriteDisposition.WRITE_EMPTY for generated temporary tables (keeping WRITE_TRUNCATE for explicit LargeResultTable).
    • Assign a client-generated JobId (google-jdbc-<uuid>) in executeJob whenever destinationTable != null, making jobs.insert retries idempotent under WRITE_EMPTY while leaving JobId.job unset for jobless fast-query-eligible queries.
  4. Internal statement isolation (BigQueryStatement):
    • Ensure internal statements (e.g., Connection.isValid) ignore LargeResultDataset and LargeResultTable so health checks never write into user destination datasets/tables.
  5. Docs & Tests (USER_GUIDE.md, DataSourceTest, BigQueryStatementTest):
    • Document updated LargeResultTable, LargeResultDataset, and LargeResultsDatasetExpirationTime behavior and add unit tests covering each invariant.

Decisions Taken & Open Review Points

  • LargeResultsDatasetExpirationTime=0 kept valid at connect time (falls back to 1h default): Rejecting 0 would break existing URLs that explicitly pass =0 to mean default. Reusing DataSource.validateNonNegative rejects < 0 without a breaking connect-time regression.
  • Sink-level log sanitization instead of input-setter rejection: Sanitizing at logQueryExecutionStart covers all ~80 settings properties uniformly and avoids surprising rejects on unusual valid values.
  • Follow-up bug filed: Extending client-generated JobId idempotency to Priority.BATCH and KMS-encrypted queries without destinationTable is tracked separately in b/592249905.

@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 automatic lifecycle management and cleanup for temporary destination tables and datasets generated during large query executions. It ensures that generated temporary tables are deleted when their associated ResultSet is closed or when a new query is executed on the same statement. Additionally, it resolves the owner's email from connection credentials to set appropriate owner ACLs on auto-created datasets, and improves dataset conflict handling. The feedback suggests two performance optimizations in BigQueryStatement.java: avoiding unnecessary ArrayList allocation when iterating over the concurrent set trackedTempTables, and using System.currentTimeMillis() instead of Instant.now().toEpochMilli() to prevent object allocation.

@keshavdandeva
keshavdandeva marked this pull request as ready for review November 26, 2026 23:40
@keshavdandeva
keshavdandeva requested review from a team as code owners November 26, 2026 23:40
@keshavdandeva
keshavdandeva force-pushed the jdbc/fix-largeResultDataset-validation branch from 3f28088 to 8e7c265 Compare December 1, 2026 17:27
@keshavdandeva keshavdandeva changed the title fix(bigquery-jdbc): use UUID names, WRITE_EMPTY, expiration, and close cleanup for LargeResultDataset temp tables fix(bigquery-jdbc): validate LargeResult properties and use UUID temp tables with WRITE_EMPTY Dec 1, 2026
@keshavdandeva
keshavdandeva force-pushed the jdbc/fix-largeResultDataset-validation branch from 8e7c265 to 9db511a Compare December 1, 2026 20:09

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.

2 participants