Skip to content

feat(jdbc): add RequestReason connection property#4094

Open
keshavdandeva wants to merge 5 commits intomainfrom
jdbc/add-connection-property
Open

feat(jdbc): add RequestReason connection property#4094
keshavdandeva wants to merge 5 commits intomainfrom
jdbc/add-connection-property

Conversation

@keshavdandeva
Copy link
Contributor

b/478305154

This PR adds support for a new JDBC connection property RequestReason. When this property is present in the connection string (e.g., jdbc:bigquery://...;RequestReason=Ticket123), the driver will include the x-goog-request-reason header in all underlying BigQuery API requests.

@keshavdandeva keshavdandeva requested review from a team as code owners February 4, 2026 18:05
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: bigquery Issues related to the googleapis/java-bigquery API. labels Feb 4, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @keshavdandeva, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the BigQuery JDBC driver by adding support for a new RequestReason connection property. This feature allows users to embed a specific reason within their JDBC connection string, which the driver then translates into an x-goog-request-reason HTTP header for BigQuery API calls. This provides valuable context for API requests, aiding in traceability and debugging on the BigQuery service side.

Highlights

  • New Connection Property: A new JDBC connection property, RequestReason, has been introduced to allow users to specify a reason for their BigQuery API requests.
  • Dynamic Header Inclusion: When the RequestReason property is provided, the BigQuery JDBC driver will now include an x-goog-request-reason HTTP header in all underlying BigQuery API requests.
  • Utility and Test Updates: The BigQueryJdbcUrlUtility has been updated to define and describe the new property, and a dedicated unit test ensures its correct parsing from the JDBC URL.
Changelog
  • google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java
    • Removed the unused FixedHeaderProvider import.
    • Added a requestReason field to store the value of the new connection property.
    • Implemented logic to parse the RequestReason property from the connection URL.
    • Modified the createHeaderProvider method to dynamically include the x-goog-request-reason header if a requestReason is present.
  • google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtility.java
    • Defined the REQUEST_REASON_PROPERTY_NAME constant for the new property.
    • Added the RequestReason property to the list of supported BigQueryConnectionProperty with its description.
    • Made a minor formatting adjustment to an existing property description.
  • google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtilityTest.java
    • Added a new unit test, testParseRequestReason, to verify the correct parsing of the RequestReason property from a JDBC URL.
Activity
  • No specific activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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 introduces a new JDBC connection property RequestReason to allow specifying a reason for BigQuery API requests, which is then passed as an x-goog-request-reason header. The implementation is straightforward and correct, with corresponding changes to connection property parsing and header provider logic. A new test case has been added to ensure the property is parsed correctly. I have one minor suggestion to improve the robustness of the createHeaderProvider method by returning an immutable map, which aligns with the previous behavior and is a general best practice.

keshavdandeva and others added 3 commits February 4, 2026 19:08
…uery/jdbc/BigQueryConnection.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Feb 4, 2026
@keshavdandeva
Copy link
Contributor Author

/gemini review

Copy link
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 introduces a useful RequestReason connection property to tag BigQuery API requests. The implementation is clean and follows existing patterns. I've added a couple of suggestions to enhance robustness by handling blank reasons, improve maintainability by using a constant for the header name, and increase test coverage for edge cases.

Comment on lines +395 to +397
if (this.requestReason != null) {
headers.put("x-goog-request-reason", this.requestReason);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

I have a couple of suggestions for this block to improve robustness and maintainability:

  1. Avoid blank headers: The current code sends the x-goog-request-reason header even if requestReason is an empty string or just whitespace. It's better to avoid sending headers with blank values by adding a check like !this.requestReason.trim().isEmpty().
  2. Use a constant for the header name: The string "x-goog-request-reason" is also used in the test file. Defining it as a public constant in BigQueryJdbcUrlUtility would avoid magic strings and improve maintainability.

Here's a suggested implementation that applies the first point:

Suggested change
if (this.requestReason != null) {
headers.put("x-goog-request-reason", this.requestReason);
}
if (this.requestReason != null && !this.requestReason.trim().isEmpty()) {
headers.put("x-goog-request-reason", this.requestReason);
}

Comment on lines +168 to +183
@Test
public void testHeaderProviderWithRequestReason() throws IOException, SQLException {
String requestReason = "Ticket123";
String url =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
+ "OAuthType=2;ProjectId=MyBigQueryProject;"
+ "OAuthAccessToken=redactedToken;OAuthClientId=redactedToken;"
+ "OAuthClientSecret=redactedToken;RequestReason="
+ requestReason;
try (BigQueryConnection connection = new BigQueryConnection(url)) {
HeaderProvider headerProvider = connection.createHeaderProvider();
java.util.Map<String, String> headers = headerProvider.getHeaders();
assertTrue(headers.containsKey("x-goog-request-reason"));
assertEquals(requestReason, headers.get("x-goog-request-reason"));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test covers the happy path well. To improve test coverage, please consider adding another test case for when RequestReason is provided but is empty or blank in the connection URL (e.g., RequestReason= or RequestReason= ). This would ensure the driver handles this edge case correctly and doesn't send the header, especially if you implement my other suggestion to avoid sending blank headers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the googleapis/java-bigquery API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants