use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest in project java-bigquerystorage by googleapis.
the class ReadRowsRetryTest method getRowCount.
private int getRowCount(ReadRowsRequest request) {
ServerStream<ReadRowsResponse> serverStream = client.readRowsCallable().call(request);
int rowCount = 0;
for (ReadRowsResponse readRowsResponse : serverStream) {
rowCount += readRowsResponse.getRowCount();
}
return rowCount;
}
use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest in project java-bigquerystorage by googleapis.
the class ITBigQueryStorageLongRunningTest method readAllRowsFromStream.
private long readAllRowsFromStream(ReadStream readStream) {
ReadRowsRequest readRowsRequest = ReadRowsRequest.newBuilder().setReadStream(readStream.getName()).build();
long rowCount = 0;
ServerStream<ReadRowsResponse> serverStream = client.readRowsCallable().call(readRowsRequest);
for (ReadRowsResponse response : serverStream) {
rowCount += response.getRowCount();
}
LOG.info(String.format("Read total of %d rows from stream '%s'.", rowCount, readStream.getName()));
return rowCount;
}
use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest in project java-bigquerystorage by googleapis.
the class ITBigQueryStorageTest method testSimpleRead.
@Test
public void testSimpleRead() {
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());
ReadRowsRequest readRowsRequest = ReadRowsRequest.newBuilder().setReadStream(session.getStreams(0).getName()).build();
long rowCount = 0;
ServerStream<ReadRowsResponse> stream = client.readRowsCallable().call(readRowsRequest);
for (ReadRowsResponse response : stream) {
rowCount += response.getRowCount();
}
assertEquals(164_656, rowCount);
}
use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest in project java-bigquerystorage by googleapis.
the class ReadRowsRetryTest method errorAtTheVeryEndTest.
@Test
public void errorAtTheVeryEndTest() {
ReadRowsRequest request = RpcExpectation.createRequest("fake-stream", 0);
service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 0).respondWithNumberOfRows(10).respondWithNumberOfRows(7).respondWithStatus(Code.UNAVAILABLE));
service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 17).respondWithNumberOfRows(0));
Assert.assertEquals(17, getRowCount(request));
}
use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest in project java-bigquerystorage by googleapis.
the class ReadRowsRetryTest method immediateRetryTest.
@Test
public void immediateRetryTest() {
ReadRowsRequest request = RpcExpectation.createRequest("fake-stream", 0);
service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 0).respondWithStatus(Code.UNAVAILABLE));
service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 0).respondWithNumberOfRows(10).respondWithNumberOfRows(7));
Assert.assertEquals(17, getRowCount(request));
}
Aggregations