feat(bigquery-jdbc): harden JDBC ResultSet compliance and optimize warning/statistics caching#13348
Conversation
…rning/statistics caching
There was a problem hiding this comment.
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.
|
/gemini review |
There was a problem hiding this comment.
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.
b/516471577
This PR improves the standard JDBC compliance of the BigQuery JDBC driver's
ResultSetimplementations and reduces redundant network traffic by introducing a lazy-loadedJobcaching 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
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(): ReturnsResultSet.FETCH_FORWARD(forward-only is the only supported direction).setFetchDirection(int direction): Restricts parameter toFETCH_FORWARD, throwing aSQLExceptionotherwise.getWarnings(): Lazily fetches warnings from the query's associated job.clearWarnings(): Stubs out as a no-op.BigQueryNoOpsResultSet.2. Network Optimization via Job Caching
jobfield andsetJob(Job)setter onBigQueryBaseResultSet.getQueryStatistics()andgetWarnings()to check and reuse the pre-cachedJobobject in memory before performing a remote lookup viabigQuery.getJob(jobId).BigQueryStatementto automatically assign the query executionJobto the statement'scurrentResultSetduring execution.processJsonResultSet,processArrowResultSet,processQueryResponse) unchanged to preserve compatibility with existing Mockito spy setups.