[
https://issues.apache.org/jira/browse/BEAM-8933?focusedWorklogId=616516&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-616516
]
ASF GitHub Bot logged work on BEAM-8933:
----------------------------------------
Author: ASF GitHub Bot
Created on: 29/Jun/21 14:23
Start Date: 29/Jun/21 14:23
Worklog Time Spent: 10m
Work Description: MiguelAnzoWizeline commented on a change in pull
request #14586:
URL: https://github.com/apache/beam/pull/14586#discussion_r660670124
##########
File path:
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryStorageArrowReader.java
##########
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.gcp.bigquery;
+
+import com.google.cloud.bigquery.storage.v1.ArrowSchema;
+import com.google.cloud.bigquery.storage.v1.ReadRowsResponse;
+import com.google.cloud.bigquery.storage.v1.ReadSession;
+import java.io.IOException;
+import java.io.InputStream;
+import javax.annotation.Nullable;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.types.pojo.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.beam.sdk.extensions.arrow.ArrowConversion;
+import
org.apache.beam.sdk.extensions.arrow.ArrowConversion.RecordBatchRowIterator;
+import org.apache.beam.sdk.schemas.utils.AvroUtils;
+import org.apache.beam.sdk.values.Row;
+
+@SuppressWarnings("nullness")
+class BigQueryStorageArrowReader implements BigQueryStorageReader {
+
+ private org.apache.beam.sdk.schemas.Schema arrowBeamSchema;
+ private @Nullable RecordBatchRowIterator recordBatchIterator;
+ private long rowCount;
+ private ArrowSchema protoSchema;
+ private @Nullable RootAllocator alloc;
+
+ BigQueryStorageArrowReader(ReadSession readSession) throws IOException {
+ protoSchema = readSession.getArrowSchema();
+ InputStream input = protoSchema.getSerializedSchema().newInput();
+ this.arrowBeamSchema =
+ ArrowConversion.ArrowSchemaTranslator.toBeamSchema(
+ ArrowConversion.arrowSchemaFromInput(input));
+ this.rowCount = 0;
+ this.alloc = null;
+ }
+
+ @Override
+ public void processReadRowsResponse(ReadRowsResponse readRowsResponse)
throws IOException {
+ com.google.cloud.bigquery.storage.v1.ArrowRecordBatch recordBatch =
+ readRowsResponse.getArrowRecordBatch();
+ rowCount = recordBatch.getRowCount();
+ this.alloc = new RootAllocator(Long.MAX_VALUE);
+ InputStream input = protoSchema.getSerializedSchema().newInput();
+ Schema arrowSchema = ArrowConversion.arrowSchemaFromInput(input);
+ this.recordBatchIterator =
+ ArrowConversion.rowsFromSerializedRecordBatch(
+ arrowSchema, recordBatch.getSerializedRecordBatch().newInput(),
this.alloc);
+ }
+
+ @Override
+ public long getRowCount() {
+ return rowCount;
+ }
+
+ @Override
+ public GenericRecord readSingleRecord() throws IOException {
+ if (recordBatchIterator == null) {
+ throw new IOException("Not Initialized");
+ }
+ Row row = recordBatchIterator.next();
+ return AvroUtils.toGenericRecord(row, null);
Review comment:
Issue created [here](https://issues.apache.org/jira/browse/BEAM-12551)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 616516)
Time Spent: 64h 20m (was: 64h 10m)
> BigQuery IO should support reading Arrow format over Storage API
> ----------------------------------------------------------------
>
> Key: BEAM-8933
> URL: https://issues.apache.org/jira/browse/BEAM-8933
> Project: Beam
> Issue Type: Improvement
> Components: io-java-gcp
> Reporter: Kirill Kozlov
> Assignee: Miguel Anzo
> Priority: P3
> Time Spent: 64h 20m
> Remaining Estimate: 0h
>
> As of right now BigQuery uses Avro format for reading and writing.
> We should add a config to BigQueryIO to specify which format to use: Arrow or
> Avro (with Avro as default).
--
This message was sent by Atlassian Jira
(v8.3.4#803005)