Skip to content

feat(bigquery-jdbc): harden JDBC ResultSet compliance and optimize warning/statistics caching#13348

Open
Neenu1995 wants to merge 7 commits into
mainfrom
refine-rs
Open

feat(bigquery-jdbc): harden JDBC ResultSet compliance and optimize warning/statistics caching#13348
Neenu1995 wants to merge 7 commits into
mainfrom
refine-rs

Conversation

@Neenu1995
Copy link
Copy Markdown
Contributor

@Neenu1995 Neenu1995 commented Jun 3, 2026

b/516471577

This PR improves the standard JDBC compliance of the BigQuery JDBC driver's ResultSet implementations and reduces redundant network traffic by introducing a lazy-loaded Job caching mechanism.

These changes prevent driver crashes when running in database clients or ORM frameworks that automatically call standard pagination/warning getters, and cut down network latency by 50% when fetching query warnings and statistics.

🛠️ Key Changes

1. ResultSet JDBC Compatibility Stubs

  • Implemented standard, non-throwing method stubs in BigQueryBaseResultSet:
    • getFetchSize(): Returns the locally set fetch size, defaulting to the statement's fetch size or the default driver buffer size (20,000).
    • setFetchSize(int rows): Stores the value in a local field (as a standard no-op placeholder).
    • getFetchDirection(): Returns ResultSet.FETCH_FORWARD (forward-only is the only supported direction).
    • setFetchDirection(int direction): Restricts parameter to FETCH_FORWARD, throwing a SQLException otherwise.
    • getWarnings(): Lazily fetches warnings from the query's associated job.
    • clearWarnings(): Stubs out as a no-op.
  • Removed throwing implementations of the above methods from BigQueryNoOpsResultSet.

2. Network Optimization via Job Caching

  • Introduced a cached job field and setJob(Job) setter on BigQueryBaseResultSet.
  • Updated getQueryStatistics() and getWarnings() to check and reuse the pre-cached Job object in memory before performing a remote lookup via bigQuery.getJob(jobId).
  • Updated BigQueryStatement to automatically assign the query execution Job to the statement's currentResultSet during execution.
  • Left the signatures of all result set factory methods (processJsonResultSet, processArrowResultSet, processQueryResponse) unchanged to preserve compatibility with existing Mockito spy setups.

@Neenu1995 Neenu1995 requested review from a team as code owners June 3, 2026 16:34
Copy link
Copy Markdown
Contributor

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

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 implements standard JDBC ResultSet methods for fetch size, fetch direction, and warnings management in BigQueryBaseResultSet, moving them out of BigQueryNoOpsResultSet. It also introduces job caching to optimize retrieving query statistics and warnings. The review feedback suggests resetting cached warnings, statistics, and the warningsLoaded flag in setJob(Job) to prevent stale data. Additionally, it recommends wrapping job retrieval in getWarnings() with a try-catch block to handle BigQueryException, and optimizing the warning chain construction to O(N) using a tail pointer.

@Neenu1995
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

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

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 implements standard JDBC ResultSet methods in BigQueryBaseResultSet (such as fetch size, fetch direction, and warnings management) and removes their unsupported stubs from BigQueryNoOpsResultSet. It also introduces Job caching to optimize retrieving query statistics and warnings. The feedback suggests updating the jobId field when setJob is called to avoid inconsistent state, and removing redundant reflection setup for fetchSize in one of the unit tests.

@Neenu1995 Neenu1995 changed the title feat(bigquery-jdbc): harden JDBC ResultSet compliance and optimize warning/statis tics caching feat(bigquery-jdbc): harden JDBC ResultSet compliance and optimize warning/statistics caching Jun 4, 2026
@keshavdandeva keshavdandeva self-requested a review June 5, 2026 13:13
@Neenu1995 Neenu1995 requested a review from logachev June 5, 2026 20:16
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.

3 participants