Skip to content

fix(bigquery-jdbc): fix htapi fallback due to permission logic - #14418

Merged
logachev merged 9 commits into
mainfrom
kirl/fix_htapi_fallback
Sep 18, 2026
Merged

logachev merged 9 commits into
mainfrom
kirl/fix_htapi_fallback

Conversation

@logachev

@logachev logachev commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Fix HTAPI permission denied fallback logic. Due to added custom handling for Runtime exception, processArrowResult was no longer throwing SQLException for PermissionDenied error.

Adding new SA that has no ReadAPI permissions & adding integration test.

b/561810298

…ipt query

The listJobs API can return Job wrappers without fully-populated statistics, particularly when dealing with SET statements inside Scripts (such as variable assignments).
When evaluating sub-jobs from a multi-statement BigQuery Script, the code assumed that `getStatistics()` and `.getScriptStatistics()` were not null and blindly dereferenced them (for example, to get evaluation kind), leading to NullPointerExceptions.

This fix makes the statistics extraction gracefully handle `null` stats or non-QueryStatistics classes by providing null-safety fallback values.

TAG=agy
CONV=1f50bc2b-6723-4b07-b755-6f7b18bb91be
@logachev
logachev requested review from a team as code owners September 17, 2026 21:15

@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 a new service account environment variable (SA_EMAIL_NO_READAPI) across Cloud Build configurations, the Makefile, and integration tests, adding a test to verify high-throughput API fallback when the Read API is unavailable. It also simplifies exception handling in BigQueryStatement.java. Feedback suggests retaining the SQLException check in BigQueryStatement.java to avoid losing specific error properties (like SQLState) when wrapping exceptions, and utilizing try-with-resources in the new integration test to ensure proper resource management of connections and statements.

I am having trouble creating individual review comments. Click here to see my feedback.

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryStatement.java (925)

medium

By completely removing the SQLException check, any pre-existing SQLException (including BigQueryJdbcException) will now be wrapped in a new BigQueryJdbcException. This causes a loss of the original SQLException's specific properties, such as the SQLState and vendor-specific error codes, which are crucial for JDBC clients to perform proper error handling.

Consider retaining the SQLException check so that existing SQLExceptions are thrown directly or preserved, while wrapping other exceptions (like RuntimeException) in BigQueryJdbcException.

      if (ex instanceof SQLException) {
        throw (ex instanceof BigQueryJdbcException)
            ? (BigQueryJdbcException) ex
            : new BigQueryJdbcException(ex);
      }
      throw new BigQueryJdbcException(ex.getMessage(), ex);

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java (507-513)

medium

Using try-with-resources ensures that the Connection and Statement are always closed properly, even if the test fails or throws an exception.

    try (Connection connection = DriverManager.getConnection(connection_uri)) {
      assertNotNull(connection);
      assertFalse(connection.isClosed());

      try (Statement statement = connection.createStatement()) {
        validateStatement(statement, 1000);
      }
    }
References
  1. Use try-with-resources to manage closeable resources such as Connection, PreparedStatement, and ResultSet in tests to ensure they are safely closed and prevent resource leaks.

Comment thread wait_and_run.sh Outdated
Comment thread wait_and_run_again.sh Outdated
@logachev
logachev force-pushed the kirl/fix_htapi_fallback branch from b459ab2 to 0d9b2fe Compare September 18, 2026 17:39
@logachev
logachev force-pushed the kirl/fix_htapi_fallback branch from 0d9b2fe to eb5cfac Compare September 18, 2026 17:52
@logachev
logachev merged commit 21e6dc8 into main Sep 18, 2026
202 checks passed
@logachev
logachev deleted the kirl/fix_htapi_fallback branch September 18, 2026 19:03
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