Skip to content

docs(bigquery-jdbc): add user guide with connection property and custom endpoint reference#13878

Open
Neenu1995 wants to merge 4 commits into
mainfrom
pr-1-user-guide-properties
Open

docs(bigquery-jdbc): add user guide with connection property and custom endpoint reference#13878
Neenu1995 wants to merge 4 commits into
mainfrom
pr-1-user-guide-properties

Conversation

@Neenu1995

Copy link
Copy Markdown
Contributor

No description provided.

@Neenu1995
Neenu1995 requested review from a team as code owners July 23, 2026 17:52

@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 adds a comprehensive User Guide (USER_GUIDE.md) for the Google BigQuery JDBC Driver, detailing configuration, architecture, and common code recipes. The review feedback correctly identifies several inconsistencies in the document, specifically regarding incorrect OAuthType values in the authentication examples (confusing OAuthType=0 for Service Accounts with OAuthType=3 for Application Default Credentials) and mismatches in the Table of Contents headings.

Comment thread java-bigquery-jdbc/USER_GUIDE.md
Comment thread java-bigquery-jdbc/USER_GUIDE.md Outdated
Comment thread java-bigquery-jdbc/USER_GUIDE.md Outdated
Comment thread java-bigquery-jdbc/USER_GUIDE.md
Comment thread java-bigquery-jdbc/USER_GUIDE.md
Comment thread java-bigquery-jdbc/USER_GUIDE.md Outdated
Comment thread java-bigquery-jdbc/USER_GUIDE.md Outdated
Comment thread java-bigquery-jdbc/USER_GUIDE.md
Comment thread java-bigquery-jdbc/USER_GUIDE.md
Comment thread java-bigquery-jdbc/USER_GUIDE.md
…rties

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
@Neenu1995

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 a comprehensive User Guide for the Google BigQuery JDBC Driver, detailing setup, configuration properties, architecture, and common code recipes. The review feedback highlights several critical corrections needed in the documentation's code examples: updating the transaction prerequisite exception from IllegalStateException to SQLException to match the JDBC contract, adding null and type safety checks to the complex types example to prevent runtime exceptions, replacing the stored procedure example with a multi-statement script since standard JDBC OUT parameters are unsupported, and wrapping the Spring Boot YAML connection URL in double quotes to avoid parsing issues.

(Auto-re-executes BEGIN TRANSACTION; if setAutoCommit is still false)
```

1. **Pre-requisite Check**: Calling `setAutoCommit(false)`, `commit()`, or `rollback()` requires `;EnableSession=true` in the connection URL. If disabled, an `IllegalStateException` is thrown.

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.

medium

The JDBC API methods setAutoCommit, commit, and rollback are specified to throw java.sql.SQLException when an error or unsupported operation occurs. They do not throw IllegalStateException directly to the caller, as doing so would violate the standard JDBC interface contract and break connection pool wrappers like HikariCP. Please update the documentation to reference SQLException instead.

Suggested change
1. **Pre-requisite Check**: Calling `setAutoCommit(false)`, `commit()`, or `rollback()` requires `;EnableSession=true` in the connection URL. If disabled, an `IllegalStateException` is thrown.
1. **Pre-requisite Check**: Calling setAutoCommit(false), commit(), or rollback() requires ;EnableSession=true in the connection URL. If disabled, a SQLException is thrown.

Comment thread java-bigquery-jdbc/USER_GUIDE.md Outdated
Comment on lines +591 to +607
// 1. Reading Struct
Struct addressStruct = (Struct) rs.getObject("shipping_address");
Object[] addressAttrs = addressStruct.getAttributes();
System.out.printf("Order %d Address: %s, %s%n", orderId, addressAttrs[0], addressAttrs[1]);

// 2. Reading Array of Structs
Array itemsArray = rs.getArray("line_items");
Struct[] items = (Struct[]) itemsArray.getArray();
for (Struct item : items) {
Object[] itemAttrs = item.getAttributes();
System.out.printf(" Item -> SKU: %s, Qty: %s%n", itemAttrs[0], itemAttrs[1]);
}

// 3. Reading Primitive Array
Array tagsArray = rs.getArray("tags");
String[] tags = (String[]) tagsArray.getArray();
System.out.println(" Tags: " + String.join(", ", tags));

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.

medium

This code snippet has potential NullPointerException and ClassCastException risks:

  1. Null Safety: If shipping_address, line_items, or tags are NULL in BigQuery, rs.getObject() or rs.getArray() will return null. Accessing methods on them directly will throw a NullPointerException.
  2. Type Safety: Array.getArray() typically returns a generic Object[] array in most JDBC drivers. Casting Object[] directly to Struct[] or String[] will throw a ClassCastException at runtime. It is safer to cast to Object[] and process elements individually or use safe conversion utilities.
        // 1. Reading Struct
        Struct addressStruct = (Struct) rs.getObject("shipping_address");
        if (addressStruct != null) {
          Object[] addressAttrs = addressStruct.getAttributes();
          System.out.printf("Order %d Address: %s, %s%n", orderId, addressAttrs[0], addressAttrs[1]);
        }

        // 2. Reading Array of Structs
        Array itemsArray = rs.getArray("line_items");
        if (itemsArray != null) {
          Object[] items = (Object[]) itemsArray.getArray();
          for (Object itemObj : items) {
            Struct item = (Struct) itemObj;
            if (item != null) {
              Object[] itemAttrs = item.getAttributes();
              System.out.printf("  Item -> SKU: %s, Qty: %s%n", itemAttrs[0], itemAttrs[1]);
            }
          }
        }

        // 3. Reading Primitive Array
        Array tagsArray = rs.getArray("tags");
        if (tagsArray != null) {
          Object[] tags = (Object[]) tagsArray.getArray();
          System.out.println("  Tags: " + java.util.Arrays.toString(tags));
        }

Comment on lines +654 to +679
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Types;

public class StoredProcedureCUJ {
public static void main(String[] args) throws Exception {
String url = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=my-project;OAuthType=0";

String procSql = "CALL my_dataset.calculate_tax(?, ?)";

try (Connection conn = DriverManager.getConnection(url);
CallableStatement cstmt = conn.prepareCall(procSql)) {

cstmt.setBigDecimal(1, new BigDecimal("1000.00")); // Input subtotal
cstmt.registerOutParameter(2, Types.DECIMAL); // Output calculated tax

cstmt.execute();

BigDecimal taxAmount = cstmt.getBigDecimal(2);
System.out.println("Calculated Tax Amount: $" + taxAmount);
}
}
}
```

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.

medium

BigQuery stored procedures do not support standard JDBC OUT parameters via CallableStatement.registerOutParameter because the underlying BigQuery API does not return output parameters in the traditional JDBC response format. Calling prepareCall or registerOutParameter will likely throw a SQLFeatureNotSupportedException.

To retrieve OUT parameters from a BigQuery stored procedure, the standard and supported approach is to execute a multi-statement SQL script that declares a variable, calls the procedure, and then selects the variable to return it as a standard ResultSet.

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class StoredProcedureCUJ {
  public static void main(String[] args) throws Exception {
    String url = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=my-project;OAuthType=0";

    // Declare a variable, call the procedure, and select the output variable
    String sql = "DECLARE tax DECIMAL; CALL my_dataset.calculate_tax(1000.00, tax); SELECT tax;";

    try (Connection conn = DriverManager.getConnection(url);
         Statement stmt = conn.createStatement()) {

      boolean hasResults = stmt.execute(sql);
      
      // Loop through results to find the selected output variable
      while (hasResults || stmt.getUpdateCount() != -1) {
        if (hasResults) {
          try (ResultSet rs = stmt.getResultSet()) {
            if (rs.next()) {
              BigDecimal taxAmount = rs.getBigDecimal(1);
              System.out.println("Calculated Tax Amount: $" + taxAmount);
            }
          }
        }
        hasResults = stmt.getMoreResults();
      }
    }
  }
}

```yaml
spring:
datasource:
url: jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=my-gcp-project;DefaultDataset=my_dataset;OAuthType=0;OAuthServiceAcctEmail=sa@my-project.iam.gserviceaccount.com;OAuthPvtKeyPath=/path/to/key.json

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.

medium

In YAML configuration files, connection URLs containing special characters (such as colons : and semicolons ;) should be wrapped in double quotes to prevent potential parsing errors by the YAML parser.

Suggested change
url: jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=my-gcp-project;DefaultDataset=my_dataset;OAuthType=0;OAuthServiceAcctEmail=sa@my-project.iam.gserviceaccount.com;OAuthPvtKeyPath=/path/to/key.json
url: "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=my-gcp-project;DefaultDataset=my_dataset;OAuthType=0;OAuthServiceAcctEmail=sa@my-project.iam.gserviceaccount.com;OAuthPvtKeyPath=/path/to/key.json"

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