Search in sources :

Example 56 with ReadRowsResponse

use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse in project spark-bigquery-connector by GoogleCloudDataproc.

the class ArrowInputPartitionContext method createPartitionReaderContext.

public InputPartitionReaderContext<ColumnarBatch> createPartitionReaderContext() {
    BigQueryStorageReadRowsTracer tracer = tracerFactory.newReadRowsTracer(Joiner.on(",").join(streamNames));
    List<ReadRowsRequest.Builder> readRowsRequests = streamNames.stream().map(name -> ReadRowsRequest.newBuilder().setReadStream(name)).collect(Collectors.toList());
    ReadRowsHelper readRowsHelper = new ReadRowsHelper(bigQueryReadClientFactory, readRowsRequests, options);
    tracer.startStream();
    Iterator<ReadRowsResponse> readRowsResponses = readRowsHelper.readRows();
    return new ArrowColumnBatchPartitionReaderContext(readRowsResponses, serializedArrowSchema, readRowsHelper, selectedFields, tracer, userProvidedSchema.toJavaUtil(), options.numBackgroundThreads());
}
Also used : StructType(org.apache.spark.sql.types.StructType) Iterator(java.util.Iterator) ReadRowsResponse(com.google.cloud.bigquery.storage.v1.ReadRowsResponse) Collectors(java.util.stream.Collectors) Optional.fromJavaUtil(com.google.common.base.Optional.fromJavaUtil) ByteString(com.google.protobuf.ByteString) BigQueryStorageReadRowsTracer(com.google.cloud.bigquery.connector.common.BigQueryStorageReadRowsTracer) ReadRowsRequest(com.google.cloud.bigquery.storage.v1.ReadRowsRequest) List(java.util.List) ColumnarBatch(org.apache.spark.sql.vectorized.ColumnarBatch) ImmutableList(com.google.common.collect.ImmutableList) BigQueryClientFactory(com.google.cloud.bigquery.connector.common.BigQueryClientFactory) Optional(java.util.Optional) ReadRowsHelper(com.google.cloud.bigquery.connector.common.ReadRowsHelper) BigQueryTracerFactory(com.google.cloud.bigquery.connector.common.BigQueryTracerFactory) ReadSessionResponse(com.google.cloud.bigquery.connector.common.ReadSessionResponse) Joiner(com.google.common.base.Joiner) BigQueryStorageReadRowsTracer(com.google.cloud.bigquery.connector.common.BigQueryStorageReadRowsTracer) ReadRowsResponse(com.google.cloud.bigquery.storage.v1.ReadRowsResponse) ReadRowsHelper(com.google.cloud.bigquery.connector.common.ReadRowsHelper)

Example 57 with ReadRowsResponse

use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse in project spark-bigquery-connector by GoogleCloudDataproc.

the class BigQueryInputPartitionReaderContext method next.

@Override
public boolean next() throws IOException {
    while (!rows.hasNext()) {
        if (!readRowsResponses.hasNext()) {
            return false;
        }
        ReadRowsResponse readRowsResponse = readRowsResponses.next();
        rows = converter.convert(readRowsResponse);
    }
    currentRow = rows.next();
    return true;
}
Also used : ReadRowsResponse(com.google.cloud.bigquery.storage.v1.ReadRowsResponse)

Example 58 with ReadRowsResponse

use of com.google.cloud.bigquery.storage.v1beta2.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 59 with ReadRowsResponse

use of com.google.cloud.bigquery.storage.v1beta2.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)

Example 60 with ReadRowsResponse

use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse in project java-bigquerystorage by googleapis.

the class EnhancedBigQueryReadStub method readRowsCallable.

public ServerStreamingCallable<ReadRowsRequest, ReadRowsResponse> readRowsCallable() {
    ServerStreamingCallable<ReadRowsRequest, ReadRowsResponse> innerCallable = GrpcRawCallableFactory.createServerStreamingCallable(GrpcCallSettings.<ReadRowsRequest, ReadRowsResponse>newBuilder().setMethodDescriptor(BigQueryReadGrpc.getReadRowsMethod()).setParamsExtractor(new RequestParamsExtractor<ReadRowsRequest>() {

        @Override
        public Map<String, String> extract(ReadRowsRequest request) {
            return ImmutableMap.of("read_stream", String.valueOf(request.getReadStream()));
        }
    }).build(), stubSettings.readRowsSettings().getRetryableCodes());
    ServerStreamingCallSettings<ReadRowsRequest, ReadRowsResponse> callSettings = stubSettings.readRowsSettings();
    StreamingRetryAlgorithm<Void> retryAlgorithm = new StreamingRetryAlgorithm<>(new ApiResultRetryAlgorithm<Void>(readRowsRetryAttemptListener), new ExponentialRetryAlgorithm(callSettings.getRetrySettings(), context.getClock()));
    ScheduledRetryingExecutor<Void> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, context.getExecutor());
    if (context.getStreamWatchdog() != null) {
        innerCallable = Callables.watched(innerCallable, callSettings, context);
    }
    ReadRowsRetryingCallable outerCallable = new ReadRowsRetryingCallable(context.getDefaultCallContext(), innerCallable, retryingExecutor, callSettings.getResumptionStrategy());
    ServerStreamingCallable<ReadRowsRequest, ReadRowsResponse> traced = new TracedServerStreamingCallable<>(outerCallable, context.getTracerFactory(), SpanName.of(TRACING_OUTER_CLIENT_NAME, "ReadRows"));
    return traced.withDefaultCallContext(context.getDefaultCallContext());
}
Also used : TracedServerStreamingCallable(com.google.api.gax.tracing.TracedServerStreamingCallable) ReadRowsRetryingCallable(com.google.cloud.bigquery.storage.v1.stub.readrows.ReadRowsRetryingCallable) ReadRowsRequest(com.google.cloud.bigquery.storage.v1.ReadRowsRequest) ExponentialRetryAlgorithm(com.google.api.gax.retrying.ExponentialRetryAlgorithm) ScheduledRetryingExecutor(com.google.api.gax.retrying.ScheduledRetryingExecutor) StreamingRetryAlgorithm(com.google.api.gax.retrying.StreamingRetryAlgorithm) ReadRowsResponse(com.google.cloud.bigquery.storage.v1.ReadRowsResponse) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Test (org.junit.Test)44 ReadRowsResponse (com.google.cloud.bigquery.storage.v1.ReadRowsResponse)40 ReadRowsRequest (com.google.cloud.bigquery.storage.v1.ReadRowsRequest)25 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)19 ReadSession (com.google.cloud.bigquery.storage.v1.ReadSession)17 StorageClient (org.apache.beam.sdk.io.gcp.bigquery.BigQueryServices.StorageClient)17 FakeBigQueryServices (org.apache.beam.sdk.io.gcp.testing.FakeBigQueryServices)17 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)15 TableRow (com.google.api.services.bigquery.model.TableRow)14 TableRowParser (org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TableRowParser)13 ReadRowsResponse (com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse)11 ReadRowsRequest (com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest)10 ByteString (com.google.protobuf.ByteString)10 CreateReadSessionRequest (com.google.cloud.bigquery.storage.v1.CreateReadSessionRequest)8 GenericRecord (org.apache.avro.generic.GenericRecord)7 StatusRuntimeException (io.grpc.StatusRuntimeException)6 ReadSession (com.google.cloud.bigquery.storage.v1beta2.ReadSession)5 StreamObserver (io.grpc.stub.StreamObserver)5 Mockito.doAnswer (org.mockito.Mockito.doAnswer)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5