use of com.google.spanner.v1.KeySet 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.spanner.v1.KeySet in project java-spanner by googleapis.
the class AbstractReadContext method readAsync.
@Override
public ListenableAsyncResultSet readAsync(String table, KeySet keys, Iterable<String> columns, ReadOption... options) {
Options readOptions = Options.fromReadOptions(options);
final int bufferRows = readOptions.hasBufferRows() ? readOptions.bufferRows() : AsyncResultSetImpl.DEFAULT_BUFFER_SIZE;
return new AsyncResultSetImpl(executorProvider, readInternal(table, null, keys, columns, options), bufferRows);
}
use of com.google.spanner.v1.KeySet in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerProbes method readProber.
/**
* Probe to test Read and StreamingRead grpc call from Spanner stub.
*/
public static void readProber(SpannerGrpc.SpannerBlockingStub stub) throws ProberException {
Session session = null;
try {
session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(DATABASE).build());
KeySet keySet = KeySet.newBuilder().setAll(true).build();
// Probing read call.
ResultSet response = stub.read(ReadRequest.newBuilder().setSession(session.getName()).setTable(TABLE).setKeySet(keySet).addColumns("username").addColumns("firstname").addColumns("lastname").build());
if (response == null) {
throw new ProberException("Response is null when executing SQL. ");
} else if (response.getRowsCount() != 1) {
throw new ProberException(String.format("The number of Responses '%d' is not correct.", response.getRowsCount()));
} else if (!response.getRows(0).getValuesList().get(0).getStringValue().equals(TEST_USERNAME)) {
throw new ProberException("Response value is not correct when executing Reader.");
}
// Probing streamingRead call.
Iterator<PartialResultSet> responsePartial = stub.streamingRead(ReadRequest.newBuilder().setSession(session.getName()).setTable(TABLE).setKeySet(keySet).addColumns("username").addColumns("firstname").addColumns("lastname").build());
if (responsePartial == null) {
throw new ProberException("Response is null when executing streaming SQL. ");
} else if (!responsePartial.next().getValues(0).getStringValue().equals(TEST_USERNAME)) {
throw new ProberException("Response value is not correct when executing streaming Reader. ");
}
} finally {
deleteSession(stub, session);
}
}
use of com.google.spanner.v1.KeySet in project java-spanner by googleapis.
the class AbstractReadContext method readUsingIndexAsync.
@Override
public ListenableAsyncResultSet readUsingIndexAsync(String table, String index, KeySet keys, Iterable<String> columns, ReadOption... options) {
Options readOptions = Options.fromReadOptions(options);
final int bufferRows = readOptions.hasBufferRows() ? readOptions.bufferRows() : AsyncResultSetImpl.DEFAULT_BUFFER_SIZE;
return new AsyncResultSetImpl(executorProvider, readInternal(table, checkNotNull(index), keys, columns, options), bufferRows);
}
Aggregations