Skip to content

Conversation

@SivamuruganP
Copy link

@SivamuruganP SivamuruganP commented Dec 21, 2025

Fixes #4008, Fixes #4002 ☕️

The integration tests ITBigQueryTest:testTableResultJobIdAndQueryId and ITBigQueryTest:testStatelessQueries were failing intermittently on slower networks.

Both tests strictly asserted that Job ID must be null for stateless queries. However, the library correctly falls back to creating a Job ID if the stateless query times out (race condition).

This change updates the assertion logic in both tests to accept either a valid Query ID (stateless success) or a valid Job ID (fallback success) using an XOR check.

Checklist

  • Make sure to open an issue as a bug/issue before writing your code!
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

The testTableResultJobIdAndQueryId test was failing intermittently on slower networks. The test strictly asserted that Job ID must be null for stateless queries.

However, the library correctly falls back to creating a Job ID if the stateless query times out. This change updates the assertion logic to accept either a valid Query ID (stateless success) or a valid Job ID (fallback success).

Fixes googleapis#4008
@SivamuruganP SivamuruganP requested review from a team as code owners December 21, 2025 11:22
@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 Dec 21, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @SivamuruganP, 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 resolves an intermittent integration test failure in the BigQuery client library. The test, which verifies stateless query behavior, was failing due to a race condition where network latency could cause the BigQuery service to fall back to creating a Job ID for a query intended to be stateless. The change updates the test's assertions to correctly validate both the intended stateless outcome (presence of a Query ID) and the acceptable fallback behavior (presence of a Job ID when a timeout occurs), ensuring the test accurately reflects the library's contract.

Highlights

  • Race Condition Fix: Addresses an intermittent failure in the ITBigQueryTest:testTableResultJobIdAndQueryId integration test. This failure was caused by a race condition where network latency could lead to the BigQuery service falling back to creating a Job ID for a query intended to be stateless.
  • Updated Assertion Logic: The test's assertion logic has been modified to correctly account for the BigQuery library's fallback mechanism. It now accepts either a valid Query ID (for successful stateless execution) or a valid Job ID (when a timeout or latency causes a fallback).

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 addresses a race condition in the ITBigQueryTest:testTableResultJobIdAndQueryId integration test. The original test incorrectly assumed that a stateless query would never result in a jobId. The fix correctly handles the fallback scenario where a jobId is created due to network latency. The logic is sound. I've suggested a small refactoring to make the assertion more concise and readable.

 Applied feedback from code review to use exclusive OR operator for validating JobID/QueryID mutual exclusivity.
@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. and removed size: s Pull request size is small. labels Dec 21, 2025
Applied XOR assertion logic to testStatelessQueries. Test was failing on slow networks because they did not account for JOB_CREATION_OPTIONAL falling back to job creation.

Fixes googleapis#4002
@product-auto-label product-auto-label bot added size: s Pull request size is small. and removed size: xs Pull request size is extra small. labels Dec 21, 2025
@lqiu96 lqiu96 self-requested a review December 22, 2025 16:38
@lqiu96 lqiu96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 22, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 22, 2025
@lqiu96
Copy link
Member

lqiu96 commented Dec 22, 2025

Thanks you for your contribution! We'll take a look at this over the next few days.

@lqiu96
Copy link
Member

lqiu96 commented Dec 22, 2025

/gcbrun

TableResult tableResult = executeSimpleQuery(bigQuery);
assertNotNull(tableResult.getQueryId());
assertNull(tableResult.getJobId());
// Use XOR: We accept EITHER a QueryId (fast path) OR a JobId (slow fallback), but not both.
Copy link
Member

Choose a reason for hiding this comment

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

nit: Can you add a bit more to the comment to explain the why. Same for the change below

e.g. For stateless queries, bigquery may determine to return a job instead of a query based on the query complexity or other factors (job timeout config).

Copy link
Author

Choose a reason for hiding this comment

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

Addressed. Added the explanation about the complexity/timeout fallback mechanism.

lqiu96
lqiu96 previously approved these changes Dec 23, 2025
Copy link
Member

@lqiu96 lqiu96 left a comment

Choose a reason for hiding this comment

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

Changes LGTM.

stateless query times out (race condition)

I believe the default jobTimeoutMs is configured to be 10000 (10s). IIUC, for these tests I don't it's due timeouts specifically. Seems to be some non-deterministic factors inside the BQ engine that has it return a job instead of a query.

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: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bigquery.it.ITBigQueryTest: testTableResultJobIdAndQueryId failed bigquery.it.ITBigQueryTest: testStatelessQueries failed

3 participants