Search in sources :

Example 31 with ReadRowsResponse

use of com.google.bigtable.v2.ReadRowsResponse in project java-bigtable by googleapis.

the class BigtableChannelPrimerTest method testErrorsAreLogged.

@Test
public void testErrorsAreLogged() {
    fakeService.readRowsCallback = new ApiFunction<ReadRowsRequest, ReadRowsResponse>() {

        @Override
        public ReadRowsResponse apply(ReadRowsRequest req) {
            throw new StatusRuntimeException(Status.FAILED_PRECONDITION);
        }
    };
    primer.primeChannel(channel);
    assertThat(logHandler.logs).hasSize(2);
    for (LogRecord log : logHandler.logs) {
        assertThat(log.getMessage()).contains("FAILED_PRECONDITION");
    }
}
Also used : ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) LogRecord(java.util.logging.LogRecord) StatusRuntimeException(io.grpc.StatusRuntimeException) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Test(org.junit.Test)

Example 32 with ReadRowsResponse

use of com.google.bigtable.v2.ReadRowsResponse in project java-bigtable by googleapis.

the class BigtableEmulatorRuleTest method testDataClient.

@Test
public void testDataClient() throws Exception {
    tableAdminStub.createTable(CreateTableRequest.newBuilder().setParent("projects/fake-project/instances/fake-instance").setTableId("fake-table").setTable(Table.newBuilder().putColumnFamilies("cf", ColumnFamily.getDefaultInstance())).build());
    dataStub.mutateRow(MutateRowRequest.newBuilder().setTableName("projects/fake-project/instances/fake-instance/tables/fake-table").setRowKey(ByteString.copyFromUtf8("fake-key")).addMutations(Mutation.newBuilder().setSetCell(SetCell.newBuilder().setFamilyName("cf").setColumnQualifier(ByteString.EMPTY).setValue(ByteString.copyFromUtf8("value")))).build());
    Iterator<ReadRowsResponse> results = dataStub.readRows(ReadRowsRequest.newBuilder().setTableName("projects/fake-project/instances/fake-instance/tables/fake-table").build());
    ReadRowsResponse row = results.next();
    assertThat(row.getChunks(0).getValue()).isEqualTo(ByteString.copyFromUtf8("value"));
}
Also used : ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) Test(org.junit.Test)

Example 33 with ReadRowsResponse

use of com.google.bigtable.v2.ReadRowsResponse in project trino by trinodb.

the class BigQueryResultPageSource method getNextPage.

@Override
public Page getNextPage() {
    checkState(pageBuilder.isEmpty(), "PageBuilder is not empty at the beginning of a new page");
    ReadRowsResponse response = responses.next();
    Iterable<GenericRecord> records = parse(response);
    for (GenericRecord record : records) {
        pageBuilder.declarePosition();
        for (int column = 0; column < columnTypes.size(); column++) {
            BlockBuilder output = pageBuilder.getBlockBuilder(column);
            appendTo(columnTypes.get(column), record.get(columnNames.get(column)), output);
        }
    }
    Page page = pageBuilder.build();
    pageBuilder.reset();
    return page;
}
Also used : ReadRowsResponse(com.google.cloud.bigquery.storage.v1.ReadRowsResponse) Page(io.trino.spi.Page) GenericRecord(org.apache.avro.generic.GenericRecord) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 34 with ReadRowsResponse

use of com.google.bigtable.v2.ReadRowsResponse in project trino by trinodb.

the class TestReadRowsHelper method testRetryOfSingleFailure.

@Test
public void testRetryOfSingleFailure() {
    BigQueryReadClient client = mock(BigQueryReadClient.class);
    MockResponsesBatch batch1 = new MockResponsesBatch();
    batch1.addResponse(ReadRowsResponse.newBuilder().setRowCount(10).build());
    batch1.addException(new StatusRuntimeException(Status.INTERNAL.withDescription("Received unexpected EOS on DATA frame from server.")));
    MockResponsesBatch batch2 = new MockResponsesBatch();
    batch2.addResponse(ReadRowsResponse.newBuilder().setRowCount(11).build());
    List<ReadRowsResponse> responses = ImmutableList.copyOf(new MockReadRowsHelper(client, "test", 3, ImmutableList.of(batch1, batch2)).readRows());
    assertThat(responses.size()).isEqualTo(2);
    assertThat(responses.stream().mapToLong(ReadRowsResponse::getRowCount).sum()).isEqualTo(21);
}
Also used : ReadRowsResponse(com.google.cloud.bigquery.storage.v1.ReadRowsResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) BigQueryReadClient(com.google.cloud.bigquery.storage.v1.BigQueryReadClient) Test(org.testng.annotations.Test)

Aggregations

Test (org.junit.Test)29 ReadRowsResponse (com.google.cloud.bigquery.storage.v1.ReadRowsResponse)21 StorageClient (org.apache.beam.sdk.io.gcp.bigquery.BigQueryServices.StorageClient)17 FakeBigQueryServices (org.apache.beam.sdk.io.gcp.testing.FakeBigQueryServices)17 TableRow (com.google.api.services.bigquery.model.TableRow)14 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)13 TableRowParser (org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TableRowParser)13 ReadRowsRequest (com.google.cloud.bigquery.storage.v1.ReadRowsRequest)11 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)10 ReadSession (com.google.cloud.bigquery.storage.v1.ReadSession)10 ByteString (com.google.protobuf.ByteString)9 GenericRecord (org.apache.avro.generic.GenericRecord)7 StatusRuntimeException (io.grpc.StatusRuntimeException)6 StreamObserver (io.grpc.stub.StreamObserver)6 Mockito.doAnswer (org.mockito.Mockito.doAnswer)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 Answer (org.mockito.stubbing.Answer)6 Table (com.google.api.services.bigquery.model.Table)4 TableReference (com.google.api.services.bigquery.model.TableReference)4 CreateReadSessionRequest (com.google.cloud.bigquery.storage.v1.CreateReadSessionRequest)3