-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Move ratio calculation for whether to use read API to avoid NPE with setUseReadAPI(false) #2509
fix: Move ratio calculation for whether to use read API to avoid NPE with setUseReadAPI(false) #2509
Conversation
🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use -- conventional-commit-lint bot |
All reactions
Sorry, something went wrong.
…with setUseReadAPI(false) If a query takes longer than 10+ seconds, the returned job will not have results / totalRows thus totalRows will be null, However, if useReadAPI is false the moved line would throw a null pointer exception trying to unbox the (nullable -- and actually null) Long for division.
8e11d07
to
88f6910
Compare
@prash-mi PTAL. Thank you . |
All reactions
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for raising the PR.
NPE shouldn't ideally come as we had made getQueryResultFirstPage(...)
a blocking call(Ref: https://github.com/googleapis/java-bigquery/blob/main/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java#L243), such that it should not return unless the job
is complete, which implies that we must be getting totalRows
and pageRows
back.
Still we can use a null
check IMO
Do we want to replace
if ((totalRows == null || pageRows == null)
&& Boolean.TRUE.equals(
connectionSettings
.getUseReadAPI())) { // totalRows and pageRows are returned null when the job is not
// complete
return true;
}
with
if (totalRows == null || pageRows == null) {
return false;
}
as, we can't check the ration if any one of these attributes are null
. WDYT?
Sorry, something went wrong.
All reactions
To ensure that NPE is not thrown. Based on requested changes from @prash-mi
@prash-mi That sounds reasonable to me, I have made that additional change. Let me know what you think. |
All reactions
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for making the changes, LGTM
Sorry, something went wrong.
All reactions
Merge-on-green attempted to merge your PR for 6 hours, but it was not mergeable because either one of your required status checks failed, one of your required reviews was not approved, or there is a do not merge label. Learn more about your required status checks here: https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks. You can remove and reapply the label to re-run the bot. |
All reactions
Sorry, something went wrong.
@jonathanswenson thanks for making the changes, it's better to add unit tests to the changes to ensure that the NPE would be avoided |
All reactions
Sorry, something went wrong.
@prash-mi there's a behaviour change as a side effect of this change that I'm worried about. Specifically, when either The current behaviour would be to use the Read API, but after introducing this fix such queries would always use If you believe that this change makes sense, then we can unit test and merge it. Otherwise maybe the following change might be reasonable:
This would avoid the NPE while maintaining the current behaviour. |
All reactions
Sorry, something went wrong.
Change useReadAPI to default to connectionSettings.getUseReadAPI() when either totalRows or pageRows are null (for long running queries). Also, move the Interval type/Queryparameters check earlier. Add unit testing.
Added mentioned change alongside unit testing. I don't think new integration tests are useful, but it might be worth it to run the benchmark queries to ensure long-running jobs are working fine, and that their execution time hasn't gotten worse. Will work on that. |
All reactions
-
👍 1 reaction
Sorry, something went wrong.
@obada-ab I think returning |
All reactions
-
👍 1 reaction
Sorry, something went wrong.
I ran the benchmark queries locally against my test project. The third run of the queries in
The third run in
Nothing concerning IMO, the differences seem minor and are probably just due to variance between runs. |
All reactions
Sorry, something went wrong.
Successfully merging this pull request may close these issues.
BigQuery Java Client throws NPE when a query takes more than 10 seconds with useReadAPI(false)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #2508 ☕️