Search in sources :

Example 1 with ReadRowsHelper

use of com.google.cloud.bigquery.connector.common.ReadRowsHelper in project spark-bigquery-connector by GoogleCloudDataproc.

the class BigQueryInputPartitionContext method createPartitionReaderContext.

@Override
public InputPartitionReaderContext<InternalRow> createPartitionReaderContext() {
    ReadRowsRequest.Builder readRowsRequest = ReadRowsRequest.newBuilder().setReadStream(streamName);
    ReadRowsHelper readRowsHelper = new ReadRowsHelper(bigQueryReadClientFactory, readRowsRequest, options);
    Iterator<ReadRowsResponse> readRowsResponses = readRowsHelper.readRows();
    return new BigQueryInputPartitionReaderContext(readRowsResponses, converter, readRowsHelper);
}
Also used : ReadRowsResponse(com.google.cloud.bigquery.storage.v1.ReadRowsResponse) ReadRowsHelper(com.google.cloud.bigquery.connector.common.ReadRowsHelper) ReadRowsRequest(com.google.cloud.bigquery.storage.v1.ReadRowsRequest)

Example 2 with ReadRowsHelper

use of com.google.cloud.bigquery.connector.common.ReadRowsHelper 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)

Aggregations

ReadRowsHelper (com.google.cloud.bigquery.connector.common.ReadRowsHelper)2 ReadRowsRequest (com.google.cloud.bigquery.storage.v1.ReadRowsRequest)2 ReadRowsResponse (com.google.cloud.bigquery.storage.v1.ReadRowsResponse)2 BigQueryClientFactory (com.google.cloud.bigquery.connector.common.BigQueryClientFactory)1 BigQueryStorageReadRowsTracer (com.google.cloud.bigquery.connector.common.BigQueryStorageReadRowsTracer)1 BigQueryTracerFactory (com.google.cloud.bigquery.connector.common.BigQueryTracerFactory)1 ReadSessionResponse (com.google.cloud.bigquery.connector.common.ReadSessionResponse)1 Joiner (com.google.common.base.Joiner)1 Optional.fromJavaUtil (com.google.common.base.Optional.fromJavaUtil)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 StructType (org.apache.spark.sql.types.StructType)1 ColumnarBatch (org.apache.spark.sql.vectorized.ColumnarBatch)1