Skip to content

Commit 0e96d1f

Browse files
refactor: move inner classes to top level (#2846)
* refactor: move inner classes to top level Move the gRPC-related inner classes from AbstractResultSet to top-level classes, so they are easier to modify and maintain. This change only contains modifications that are needed to move these inner classes. There are no functional changes. * feat: support lazy decoding of query results (#2847) * feat: support lazy decoding of query results Adds an option for lazy decoding of query results. Currently, all values in a query result row are decoded from protobuf values to plain Java objects at the moment that the result set is advanced to the next row. This means that all values are decoded, regardless whether the application actually fetches these or not. Lazy decoding also enables the possibility for (internal) consumers of a result set to access the protobuf value before it is converted to a plain Java object. This for example allows ChecksumResultSet to calculate the checksum based on the protobuf value, instead of a Java object, which can be more efficient. * fix: add null check * perf: calculate checksum using protobuf values (#2848) * perf: calculate checksum using protobuf values * chore: cleanup * test: remove unrelated test * fix: undo change to public API * chore: cleanup| * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 3ba604d commit 0e96d1f

34 files changed

+2341
-1740
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-spanner'
5757
If you are using Gradle without BOM, add this to your dependencies:
5858

5959
```Groovy
60-
implementation 'com.google.cloud:google-cloud-spanner:6.57.0'
60+
implementation 'com.google.cloud:google-cloud-spanner:6.58.0'
6161
```
6262

6363
If you are using SBT, add this to your dependencies:
6464

6565
```Scala
66-
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.57.0"
66+
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.58.0"
6767
```
6868
<!-- {x-version-update-end} -->
6969

@@ -444,7 +444,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
444444
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java11.html
445445
[stability-image]: https://img.shields.io/badge/stability-stable-green
446446
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-spanner.svg
447-
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.57.0
447+
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.58.0
448448
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
449449
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
450450
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles

google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractReadContext.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
import com.google.api.gax.core.ExecutorProvider;
2929
import com.google.cloud.Timestamp;
3030
import com.google.cloud.spanner.AbstractResultSet.CloseableIterator;
31-
import com.google.cloud.spanner.AbstractResultSet.GrpcResultSet;
32-
import com.google.cloud.spanner.AbstractResultSet.GrpcStreamIterator;
33-
import com.google.cloud.spanner.AbstractResultSet.ResumableStreamIterator;
3431
import com.google.cloud.spanner.AsyncResultSet.CallbackResponse;
3532
import com.google.cloud.spanner.AsyncResultSet.ReadyCallback;
3633
import com.google.cloud.spanner.Options.QueryOption;
@@ -73,6 +70,7 @@ abstract static class Builder<B extends Builder<?, T>, T extends AbstractReadCon
7370
private TraceWrapper tracer;
7471
private int defaultPrefetchChunks = SpannerOptions.Builder.DEFAULT_PREFETCH_CHUNKS;
7572
private QueryOptions defaultQueryOptions = SpannerOptions.Builder.DEFAULT_QUERY_OPTIONS;
73+
private DecodeMode defaultDecodeMode = SpannerOptions.Builder.DEFAULT_DECODE_MODE;
7674
private DirectedReadOptions defaultDirectedReadOption;
7775
private ExecutorProvider executorProvider;
7876
private Clock clock = new Clock();
@@ -114,6 +112,11 @@ B setDefaultQueryOptions(QueryOptions defaultQueryOptions) {
114112
return self();
115113
}
116114

115+
B setDefaultDecodeMode(DecodeMode defaultDecodeMode) {
116+
this.defaultDecodeMode = defaultDecodeMode;
117+
return self();
118+
}
119+
117120
B setExecutorProvider(ExecutorProvider executorProvider) {
118121
this.executorProvider = executorProvider;
119122
return self();
@@ -414,8 +417,8 @@ void initTransaction() {
414417
TraceWrapper tracer;
415418
private final int defaultPrefetchChunks;
416419
private final QueryOptions defaultQueryOptions;
417-
418420
private final DirectedReadOptions defaultDirectedReadOptions;
421+
private final DecodeMode defaultDecodeMode;
419422
private final Clock clock;
420423

421424
@GuardedBy("lock")
@@ -441,6 +444,7 @@ void initTransaction() {
441444
this.defaultPrefetchChunks = builder.defaultPrefetchChunks;
442445
this.defaultQueryOptions = builder.defaultQueryOptions;
443446
this.defaultDirectedReadOptions = builder.defaultDirectedReadOption;
447+
this.defaultDecodeMode = builder.defaultDecodeMode;
444448
this.span = builder.span;
445449
this.executorProvider = builder.executorProvider;
446450
this.clock = builder.clock;
@@ -730,7 +734,8 @@ CloseableIterator<PartialResultSet> startStream(@Nullable ByteString resumeToken
730734
return stream;
731735
}
732736
};
733-
return new GrpcResultSet(stream, this);
737+
return new GrpcResultSet(
738+
stream, this, options.hasDecodeMode() ? options.decodeMode() : defaultDecodeMode);
734739
}
735740

736741
/**
@@ -874,7 +879,8 @@ CloseableIterator<PartialResultSet> startStream(@Nullable ByteString resumeToken
874879
return stream;
875880
}
876881
};
877-
return new GrpcResultSet(stream, this);
882+
return new GrpcResultSet(
883+
stream, this, readOptions.hasDecodeMode() ? readOptions.decodeMode() : defaultDecodeMode);
878884
}
879885

880886
private Struct consumeSingleRow(ResultSet resultSet) {

0 commit comments

Comments
 (0)