Skip to content

fix(bigquery-jdbc): apply per-table expiration to generated LargeResultDataset temp tables - #15333

Open
keshavdandeva wants to merge 1 commit into
jdbc/large-results-3-dataset-aclsfrom
jdbc/large-results-4-table-expiration
Open

keshavdandeva wants to merge 1 commit into
jdbc/large-results-3-dataset-aclsfrom
jdbc/large-results-4-table-expiration

Conversation

@keshavdandeva

@keshavdandeva keshavdandeva commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

b/584840569

Summary of Changes

  1. Simple 1-rule per-table expiration fallback (LargeResultDestinations, BigQueryStatement):
    • If the target dataset already has a finite defaultTableLifetime > 0 (including any dataset auto-created in PR 3), never call tables.update — the dataset's configured TTL is respected with zero extra RPCs.
    • Only when a pre-existing LargeResultDataset has no defaultTableLifetime (null or <= 0, or when a 409 reload failed for a service account), best-effort patch expirationTime = now + LargeResultsDatasetExpirationTime (default 1h) on generated temporary tables (LargeResultTable == null) as a crash-leak safety net (b/584840569). Explicit LargeResultTable tables are never patched.
    • Zero changes to DataSource.java or BigQuerySettings.java (no explicit-vs-default property tri-state).
  2. Per-connection 403 accessDenied memoization (LargeResultDestinations, BigQueryConnection):
    • Best-effort tables.update never fails query execution. If BigQuery returns HTTP 403 with reason accessDenied, memoize per connection so subsequent queries skip tables.update; non-IAM failures (503, 403 rateLimitExceeded) log a warning without poisoning the connection.
    • BigQueryConnection.resetForReuse() calls largeResultDestinations.resetForReuse() to clear memoized state on pooled connection reuse.
  3. Docs & Tests (USER_GUIDE.md, BigQueryStatementTest):
    • Document finite dataset TTL preservation and fixed-deadline expiration on no-TTL datasets; add parameterized tests for null/zero/finite dataset TTLs, =0 URL fallback, 403 accessDenied memoization, non-IAM errors, resetForReuse(), and concurrent Statement.close() during table expiration.

Decisions Taken & Open Review Points

  • Dropped explicit-vs-default URL tri-state: Previously an explicit LargeResultsDatasetExpirationTime=3600000 (common in Simba URL templates) overrode a dataset's admin-configured defaultTableLifetime. Always respecting finite dataset TTLs eliminates that footgun, eliminates changes to DataSource/BigQuerySettings, and keeps extra RPCs at zero for datasets with a TTL.
  • Open review question — fixed deadline (1h default) on no-TTL datasets: On pre-existing datasets with no defaultTableLifetime, setting expirationTime = now + LargeResultsDatasetExpirationTime (default 1h) ensures temp tables expire even if the JVM crashes before PR 5's ResultSet.close() cleanup runs (b/584840569), at the cost that reads open longer than 1 hour on a no-TTL dataset require increasing LargeResultsDatasetExpirationTime (or setting a dataset TTL). Please weigh in if you prefer:
    1. Keep current LargeResultsDatasetExpirationTime default (1h),
    2. Use a longer floor/backstop (e.g., 24h) when patching per-table expiration on no-TTL datasets, or
    3. Rely solely on PR 5's delete-on-close for pre-existing no-TTL datasets.

@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 explicit tracking of destination dataset expiration times and implements a best-effort mechanism to set expiration times on generated temporary destination tables, including connection-level memoization of permission errors to avoid redundant API calls. The review feedback correctly identifies that setting the expiration time to Long.MAX_VALUE will result in a 400 Bad Request error from BigQuery, which has a maximum supported timestamp of 9999-12-31 23:59:59.999 UTC (253402300799000L). Capping the expiration time to this maximum value and updating the corresponding test assertion is recommended.

@keshavdandeva
keshavdandeva force-pushed the jdbc/large-results-4-table-expiration branch from 7906d4e to 9681094 Compare December 1, 2026 17:51
@keshavdandeva
keshavdandeva force-pushed the jdbc/large-results-4-table-expiration branch from 9681094 to 24aaa5f 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.

1 participant