use of com.google.cloud.spanner.AbstractResultSet.GrpcStreamIterator in project java-spanner by googleapis.
the class AbstractReadContext method readInternalWithOptions.
ResultSet readInternalWithOptions(String table, @Nullable String index, KeySet keys, Iterable<String> columns, final Options readOptions, ByteString partitionToken) {
beforeReadOrQuery();
final ReadRequest.Builder builder = ReadRequest.newBuilder().setSession(session.getName()).setTable(checkNotNull(table)).addAllColumns(columns);
if (readOptions.hasLimit()) {
builder.setLimit(readOptions.limit());
}
keys.appendToProto(builder.getKeySetBuilder());
if (index != null) {
builder.setIndex(index);
}
if (partitionToken != null) {
builder.setPartitionToken(partitionToken);
}
final int prefetchChunks = readOptions.hasPrefetchChunks() ? readOptions.prefetchChunks() : defaultPrefetchChunks;
ResumableStreamIterator stream = new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, SpannerImpl.READ, span) {
@Override
CloseableIterator<PartialResultSet> startStream(@Nullable ByteString resumeToken) {
GrpcStreamIterator stream = new GrpcStreamIterator(prefetchChunks);
TransactionSelector selector = null;
if (resumeToken != null) {
builder.setResumeToken(resumeToken);
selector = getTransactionSelector();
} else if (!builder.hasTransaction()) {
selector = getTransactionSelector();
}
if (selector != null) {
builder.setTransaction(selector);
}
builder.setRequestOptions(buildRequestOptions(readOptions));
SpannerRpc.StreamingCall call = rpc.read(builder.build(), stream.consumer(), session.getOptions());
call.request(prefetchChunks);
stream.setCall(call, /* withBeginTransaction = */
builder.getTransaction().hasBegin());
return stream;
}
};
return new GrpcResultSet(stream, this);
}
use of com.google.cloud.spanner.AbstractResultSet.GrpcStreamIterator in project java-spanner by googleapis.
the class AbstractReadContext method executeQueryInternalWithOptions.
ResultSet executeQueryInternalWithOptions(final Statement statement, final com.google.spanner.v1.ExecuteSqlRequest.QueryMode queryMode, final Options options, final ByteString partitionToken) {
beforeReadOrQuery();
final int prefetchChunks = options.hasPrefetchChunks() ? options.prefetchChunks() : defaultPrefetchChunks;
final ExecuteSqlRequest.Builder request = getExecuteSqlRequestBuilder(statement, queryMode, options, /* withTransactionSelector = */
false);
ResumableStreamIterator stream = new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, SpannerImpl.QUERY, span) {
@Override
CloseableIterator<PartialResultSet> startStream(@Nullable ByteString resumeToken) {
GrpcStreamIterator stream = new GrpcStreamIterator(statement, prefetchChunks);
if (partitionToken != null) {
request.setPartitionToken(partitionToken);
}
TransactionSelector selector = null;
if (resumeToken != null) {
request.setResumeToken(resumeToken);
selector = getTransactionSelector();
} else if (!request.hasTransaction()) {
selector = getTransactionSelector();
}
if (selector != null) {
request.setTransaction(selector);
}
SpannerRpc.StreamingCall call = rpc.executeQuery(request.build(), stream.consumer(), session.getOptions());
call.request(prefetchChunks);
stream.setCall(call, request.getTransaction().hasBegin());
return stream;
}
};
return new GrpcResultSet(stream, this);
}
Aggregations