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 ExecuteSql 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
Uh oh!
There was an error while loading. Please reload this page.
google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java Outdated Show resolved Hide resolved
Uh oh!
There was an error while loading. Please reload this page.
google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java Outdated Show resolved Hide resolved
Uh oh!
There was an error while loading. Please reload this page.
google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java Outdated Show resolved Hide resolved
Uh oh!
There was an error while loading. Please reload this page.
google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java Outdated Show resolved Hide resolved
Uh oh!
There was an error while loading. Please reload this page.
google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java Outdated Show resolved Hide resolved
Uh oh!
There was an error while loading. Please reload this page.
One thing I notice is that PartitionedDML also uses
|
|
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..com/googleapis/java-spanner/compare/v1.50.0...v1.51.0) (2020-03-13) ### Features * add backend query options ([#90](https://www..com/googleapis/java-spanner/issues/90)) ([e96e172](https://www..com/googleapis/java-spanner/commit/e96e17246bee9691171b46857806d03d1f8e19b4)) * add QueryOptions proto ([#84](https://www..com/googleapis/java-spanner/issues/84)) ([eb8fc37](https://www..com/googleapis/java-spanner/commit/eb8fc375bbd766f25966aa565e266ed972bbe818)) ### Bug Fixes * never use credentials in combination with plain text ([#98](https://www..com/googleapis/java-spanner/issues/98)) ([7eb8d49](https://www..com/googleapis/java-spanner/commit/7eb8d49cd6c35d7f757cb89009ad16be601b77c3)) ### Dependencies * update dependency com.google.cloud:google-cloud-core-bom to v1.93.1 ([#91](https://www..com/googleapis/java-spanner/issues/91)) ([29d8db8](https://www..com/googleapis/java-spanner/commit/29d8db8cfc9d12824b9264d0fb870049a58a9a03)) * update dependency io.opencensus:opencensus-api to v0.25.0 ([#95](https://www..com/googleapis/java-spanner/issues/95)) ([57f5fd0](https://www..com/googleapis/java-spanner/commit/57f5fd0f3bee4b437f48b6a08ab3174f035c8cca)) --- This PR was generated with [Release Please](https://.com/googleapis/release-please).
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: