use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigquerystorage by googleapis.
the class ITBigQueryStorageTest method testFilter.
@Test
public void testFilter() throws IOException {
String table = BigQueryResource.FormatTableResource(/* projectId = */
"bigquery-public-data", /* datasetId = */
"samples", /* tableId = */
"shakespeare");
TableReadOptions options = TableReadOptions.newBuilder().setRowRestriction("word_count > 100").build();
CreateReadSessionRequest request = CreateReadSessionRequest.newBuilder().setParent(parentProjectId).setMaxStreamCount(1).setReadSession(ReadSession.newBuilder().setTable(table).setReadOptions(options).setDataFormat(DataFormat.AVRO).build()).build();
ReadSession session = client.createReadSession(request);
assertEquals(String.format("Did not receive expected number of streams for table '%s' CreateReadSession response:%n%s", table, session.toString()), 1, session.getStreamsCount());
ReadRowsRequest readRowsRequest = ReadRowsRequest.newBuilder().setReadStream(session.getStreams(0).getName()).build();
SimpleRowReader reader = new SimpleRowReader(new Schema.Parser().parse(session.getAvroSchema().getSchema()));
long rowCount = 0;
ServerStream<ReadRowsResponse> stream = client.readRowsCallable().call(readRowsRequest);
for (ReadRowsResponse response : stream) {
rowCount += response.getRowCount();
reader.processRows(response.getAvroRows(), new AvroRowConsumer() {
@Override
public void accept(GenericData.Record record) {
Long wordCount = (Long) record.get("word_count");
assertWithMessage("Row not matching expectations: %s", record.toString()).that(wordCount).isGreaterThan(100L);
}
});
}
assertEquals(1_333, rowCount);
}
use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigquerystorage by googleapis.
the class ITBigQueryStorageTest method testSimpleReadAndResume.
@Test
public void testSimpleReadAndResume() {
String table = BigQueryResource.FormatTableResource(/* projectId = */
"bigquery-public-data", /* datasetId = */
"samples", /* tableId = */
"shakespeare");
ReadSession session = client.createReadSession(/* parent = */
parentProjectId, /* readSession = */
ReadSession.newBuilder().setTable(table).setDataFormat(DataFormat.AVRO).build(), /* maxStreamCount = */
1);
assertEquals(String.format("Did not receive expected number of streams for table '%s' CreateReadSession response:%n%s", table, session.toString()), 1, session.getStreamsCount());
// We have to read some number of rows in order to be able to resume. More details:
long rowCount = ReadStreamToOffset(session.getStreams(0), /* rowOffset = */
34_846);
ReadRowsRequest readRowsRequest = ReadRowsRequest.newBuilder().setReadStream(session.getStreams(0).getName()).setOffset(rowCount).build();
ServerStream<ReadRowsResponse> stream = client.readRowsCallable().call(readRowsRequest);
for (ReadRowsResponse response : stream) {
rowCount += response.getRowCount();
}
// Verifies that the number of rows skipped and read equals to the total number of rows in the
// table.
assertEquals(164_656, rowCount);
}
use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project grpc-gcp-java by GoogleCloudPlatform.
the class BigtableLoadTest method getReadRowsResponses.
private static List<Iterator<ReadRowsResponse>> getReadRowsResponses(ManagedChannel channel) {
GoogleCredentials creds = getCreds();
BigtableBlockingStub stub = BigtableGrpc.newBlockingStub(channel).withCallCredentials(MoreCallCredentials.from(creds));
List<Iterator<ReadRowsResponse>> res = new ArrayList<>();
ReadRowsRequest request = ReadRowsRequest.newBuilder().setTableName(LARGE_TABLE_NAME).build();
for (int i = 0; i < DEFAULT_MAX_STREAM + 5; i++) {
Iterator<ReadRowsResponse> iter = stub.readRows(request);
res.add(iter);
}
return res;
}
Aggregations