Search in sources :

Example 66 with ReadRowsRequest

use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigquerystorage by googleapis.

the class ITBigQueryStorageTest method ReadStreamToOffset.

/**
 * Reads to the specified row offset within the stream. If the stream does not have the desired
 * rows to read, it will read all of them.
 *
 * @param readStream
 * @param rowOffset
 * @return the number of requested rows to skip or the total rows read if stream had less rows.
 */
private long ReadStreamToOffset(ReadStream readStream, long rowOffset) {
    ReadRowsRequest readRowsRequest = ReadRowsRequest.newBuilder().setReadStream(readStream.getName()).build();
    long rowCount = 0;
    ServerStream<ReadRowsResponse> serverStream = client.readRowsCallable().call(readRowsRequest);
    Iterator<ReadRowsResponse> responseIterator = serverStream.iterator();
    while (responseIterator.hasNext()) {
        ReadRowsResponse response = responseIterator.next();
        rowCount += response.getRowCount();
        if (rowCount >= rowOffset) {
            return rowOffset;
        }
    }
    return rowCount;
}
Also used : ReadRowsResponse(com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse) ReadRowsRequest(com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest)

Example 67 with ReadRowsRequest

use of com.google.bigtable.repackaged.com.google.bigtable.v2.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);
}
Also used : ReadRowsResponse(com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse) ReadSession(com.google.cloud.bigquery.storage.v1beta2.ReadSession) ReadRowsRequest(com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest) Test(org.junit.Test)

Example 68 with ReadRowsRequest

use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigquerystorage by googleapis.

the class ReadRowsRetryTest method multipleRetryTestWithZeroInitialOffset.

@Test
public void multipleRetryTestWithZeroInitialOffset() {
    ReadRowsRequest request = RpcExpectation.createRequest("fake-stream", 0);
    service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 0).respondWithNumberOfRows(5).respondWithStatus(Code.UNAVAILABLE));
    service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 5).respondWithNumberOfRows(10).respondWithNumberOfRows(7).respondWithStatus(Code.UNAVAILABLE));
    service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 22).respondWithNumberOfRows(6));
    Assert.assertEquals(28, getRowCount(request));
}
Also used : ReadRowsRequest(com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest) Test(org.junit.Test)

Example 69 with ReadRowsRequest

use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigquerystorage by googleapis.

the class ReadRowsRetryTest method happyPathTest.

@Test
public void happyPathTest() {
    ReadRowsRequest request = RpcExpectation.createRequest("fake-stream", 0);
    service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 0).respondWithNumberOfRows(10).respondWithNumberOfRows(7));
    Assert.assertEquals(17, getRowCount(request));
}
Also used : ReadRowsRequest(com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest) Test(org.junit.Test)

Example 70 with ReadRowsRequest

use of com.google.bigtable.repackaged.com.google.bigtable.v2.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));
}
Also used : ReadRowsRequest(com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)59 ReadRowsRequest (com.google.cloud.bigquery.storage.v1.ReadRowsRequest)31 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)28 ReadRowsResponse (com.google.cloud.bigquery.storage.v1.ReadRowsResponse)24 ReadSession (com.google.cloud.bigquery.storage.v1.ReadSession)17 ReadRowsRequest (com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest)16 ReadRowsResponse (com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse)10 StorageClient (org.apache.beam.sdk.io.gcp.bigquery.BigQueryServices.StorageClient)10 FakeBigQueryServices (org.apache.beam.sdk.io.gcp.testing.FakeBigQueryServices)10 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)9 Row (com.google.cloud.bigtable.data.v2.models.Row)9 CreateReadSessionRequest (com.google.cloud.bigquery.storage.v1.CreateReadSessionRequest)8 TableRow (com.google.api.services.bigquery.model.TableRow)7 Query (com.google.cloud.bigtable.data.v2.models.Query)7 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)7 ByteString (com.google.protobuf.ByteString)7 GenericRecord (org.apache.avro.generic.GenericRecord)6 TableRowParser (org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TableRowParser)6 ReadSession (com.google.cloud.bigquery.storage.v1beta2.ReadSession)5 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)5