-
Notifications
You must be signed in to change notification settings - Fork 123
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
feat: add backend query options #90
Conversation
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.
LGTM
A couple of requests:
- I would like to verify that both ExecuteSql and ExecuteStreamingSql requests support query options. I think it does from what I understand of the implementation but thought I'd check.
- If you could update the description of this PR to contain the information about the env variable and the precedence, that would be great. Example PR
MultiUseReadOnlyTransaction(Builder builder) { | ||
super(builder); | ||
checkArgument( | ||
bound.getMode() != TimestampBound.Mode.MAX_STALENESS | ||
&& bound.getMode() != TimestampBound.Mode.MIN_READ_TIMESTAMP, | ||
"Bounded staleness mode %s is not supported for multi-use read-only transactions." | ||
+ " Create a single-use read or read-only transaction instead.", | ||
bound.getMode()); | ||
this.bound = bound; | ||
} | ||
|
||
MultiUseReadOnlyTransaction( | ||
SessionImpl session, | ||
ByteString transactionId, | ||
Timestamp timestamp, | ||
SpannerRpc rpc, | ||
int defaultPrefetchChunks) { | ||
super(session, rpc, defaultPrefetchChunks); | ||
this.transactionId = transactionId; | ||
this.timestamp = timestamp; | ||
!(builder.bound != null && builder.transactionId != null) | ||
&& !(builder.bound == null && builder.transactionId == null), | ||
"Either TimestampBound or TransactionId must be specified"); | ||
if (builder.bound != null) { | ||
checkArgument( | ||
builder.bound.getMode() != TimestampBound.Mode.MAX_STALENESS | ||
&& builder.bound.getMode() != TimestampBound.Mode.MIN_READ_TIMESTAMP, | ||
"Bounded staleness mode %s is not supported for multi-use read-only transactions." | ||
+ " Create a single-use read or read-only transaction instead.", | ||
builder.bound.getMode()); | ||
this.bound = builder.bound; | ||
} else { | ||
this.timestamp = builder.timestamp; | ||
this.transactionId = builder.transactionId; | ||
} |
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.
Since most of this refactoring and extra checks for arguments is not related to the query options work, would it be ok to move this to a separate PR?
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.
I would prefer not to. The reason for introducing this builder pattern in this PR is that this PR requires an additional object to be passed in to the different transaction classes. This would add another parameter to the constructors of these classes, bringing the total number to 6 in this specific case. As a general rule of thumb, a method (or constructor) in Java should not take more than 4 arguments: https://rules.sonarsource.com/java/RSPEC-107
google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerImplTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java
Outdated
Show resolved
Hide resolved
One thing I notice is that PartitionedDML also uses Lines 73 to 78 in d8b6438
|
|
I've added a PartitionedDML statement to |
9130062
to
59d2f8d
Compare
@olavloite you are welcome to merge this in as I've now merged in the generated code. |
59d2f8d
to
2c7df30
Compare
Adds support for setting QueryOptions that will be used by the backend to execute queries.
QueryOptions should be an option on a Statement instead of a parameter to the executeQuery method. By setting these options on a Statement, it is possible to use it with analyzeQuery as well.
624f0e1
to
d27b3a7
Compare
🤖 I have created a release \*beep\* \*boop\* --- ## [1.51.0](https://www.github.com/googleapis/java-spanner/compare/v1.50.0...v1.51.0) (2020-03-13) ### Features * add backend query options ([#90](https://www.github.com/googleapis/java-spanner/issues/90)) ([e96e172](https://www.github.com/googleapis/java-spanner/commit/e96e17246bee9691171b46857806d03d1f8e19b4)) * add QueryOptions proto ([#84](https://www.github.com/googleapis/java-spanner/issues/84)) ([eb8fc37](https://www.github.com/googleapis/java-spanner/commit/eb8fc375bbd766f25966aa565e266ed972bbe818)) ### Bug Fixes * never use credentials in combination with plain text ([#98](https://www.github.com/googleapis/java-spanner/issues/98)) ([7eb8d49](https://www.github.com/googleapis/java-spanner/commit/7eb8d49cd6c35d7f757cb89009ad16be601b77c3)) ### Dependencies * update dependency com.google.cloud:google-cloud-core-bom to v1.93.1 ([#91](https://www.github.com/googleapis/java-spanner/issues/91)) ([29d8db8](https://www.github.com/googleapis/java-spanner/commit/29d8db8cfc9d12824b9264d0fb870049a58a9a03)) * update dependency io.opencensus:opencensus-api to v0.25.0 ([#95](https://www.github.com/googleapis/java-spanner/issues/95)) ([57f5fd0](https://www.github.com/googleapis/java-spanner/commit/57f5fd0f3bee4b437f48b6a08ab3174f035c8cca)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please).
This PR was generated using Autosynth. 🌈 <details><summary>Log from Synthtool</summary> ``` 2020-03-17 12:21:53,248 synthtool > Executing /tmpfs/src/git/autosynth/working_repo/synth.py. .github/ISSUE_TEMPLATE/bug_report.md .github/ISSUE_TEMPLATE/feature_request.md .github/ISSUE_TEMPLATE/support_request.md .github/PULL_REQUEST_TEMPLATE.md .github/release-please.yml .github/trusted-contribution.yml .kokoro/build.bat .kokoro/build.sh .kokoro/coerce_logs.sh .kokoro/common.cfg .kokoro/continuous/common.cfg .kokoro/continuous/dependencies.cfg .kokoro/continuous/integration.cfg .kokoro/continuous/java11.cfg .kokoro/continuous/java7.cfg .kokoro/continuous/java8-osx.cfg .kokoro/continuous/java8-win.cfg .kokoro/continuous/java8.cfg .kokoro/continuous/lint.cfg .kokoro/continuous/propose_release.cfg .kokoro/continuous/samples.cfg .kokoro/dependencies.sh .kokoro/linkage-monitor.sh .kokoro/nightly/common.cfg .kokoro/nightly/dependencies.cfg .kokoro/nightly/integration.cfg .kokoro/nightly/java11.cfg .kokoro/nightly/java7.cfg .kokoro/nightly/java8-osx.cfg .kokoro/nightly/java8-win.cfg .kokoro/nightly/java8.cfg .kokoro/nightly/lint.cfg .kokoro/nightly/samples.cfg .kokoro/presubmit/clirr.cfg .kokoro/presubmit/common.cfg .kokoro/presubmit/dependencies.cfg .kokoro/presubmit/integration.cfg .kokoro/presubmit/java11.cfg .kokoro/presubmit/java7.cfg .kokoro/presubmit/java8-osx.cfg .kokoro/presubmit/java8-win.cfg .kokoro/presubmit/java8.cfg .kokoro/presubmit/linkage-monitor.cfg .kokoro/presubmit/lint.cfg .kokoro/presubmit/samples.cfg .kokoro/release/bump_snapshot.cfg .kokoro/release/common.cfg .kokoro/release/common.sh .kokoro/release/drop.cfg .kokoro/release/drop.sh .kokoro/release/promote.cfg .kokoro/release/promote.sh .kokoro/release/publish_javadoc.cfg .kokoro/release/publish_javadoc.sh .kokoro/release/snapshot.cfg .kokoro/release/snapshot.sh .kokoro/release/stage.cfg .kokoro/release/stage.sh .kokoro/trampoline.sh CODE_OF_CONDUCT.md CONTRIBUTING.md LICENSE README.md codecov.yaml java.header license-checks.xml renovate.json samples/install-without-bom/pom.xml samples/pom.xml samples/snapshot/pom.xml samples/snippets/pom.xml 2020-03-17 12:21:53,455 synthtool > Wrote metadata to synth.metadata. ``` </details>
Adds the ability to set
QueryOptions
when running Cloud Spanner queries. For now, only setting thequery_optimizer_version
is added.QueryOptions can be configured through the following mechanisms:
SPANNER_OPTIMIZER_VERSION
environment variable.Spanner
level usingSpannerOptions.newBuilder().setDefaultQueryOptions(DatabaseId, QueryOptions)
.Statement.newBuilder(String).withQueryOptions(QueryOptions)
.If the options are configured through multiple mechanisms then:
SpannerOptions
level.SpannerOptions
or environment variable level.If no options are set, the optimizer version will default to: