[ 
https://issues.apache.org/jira/browse/BEAM-8933?focusedWorklogId=378548&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-378548
 ]

ASF GitHub Bot logged work on BEAM-8933:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 28/Jan/20 22:58
            Start Date: 28/Jan/20 22:58
    Worklog Time Spent: 10m 
      Work Description: emkornfield commented on pull request #10384: 
[BEAM-8933] Utilities for converting Arrow schemas and reading Arrow batches as 
Rows
URL: https://github.com/apache/beam/pull/10384#discussion_r372106201
 
 

 ##########
 File path: 
sdks/java/extensions/arrow/src/test/java/org/apache/beam/sdk/extensions/arrow/ArrowConversionTest.java
 ##########
 @@ -0,0 +1,179 @@
+/*
+ * 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.extensions.arrow;
+
+import static java.util.Arrays.asList;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+
+import java.util.ArrayList;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.BitVector;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.FixedSizeBinaryVector;
+import org.apache.arrow.vector.Float8Vector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.TimeStampMicroTZVector;
+import org.apache.arrow.vector.TimeStampMilliTZVector;
+import org.apache.arrow.vector.VarCharVector;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.arrow.vector.complex.ListVector;
+import org.apache.arrow.vector.types.FloatingPointPrecision;
+import org.apache.arrow.vector.types.TimeUnit;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.arrow.vector.util.Text;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.Schema.Field;
+import org.apache.beam.sdk.schemas.Schema.FieldType;
+import org.apache.beam.sdk.values.Row;
+import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
+import org.hamcrest.collection.IsIterableContainingInOrder;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class ArrowConversionTest {
+
+  private BufferAllocator allocator;
+
+  @Before
+  public void init() {
+    allocator = new RootAllocator(Long.MAX_VALUE);
+  }
+
+  @After
+  public void teardown() {
+    allocator.close();
+  }
+
+  @Test
+  public void toBeamSchema_convertsSimpleArrowSchema() {
+    Schema expected =
+        Schema.of(Field.of("int8", FieldType.BYTE), Field.of("int16", 
FieldType.INT16));
+
+    org.apache.arrow.vector.types.pojo.Schema arrowSchema =
+        new org.apache.arrow.vector.types.pojo.Schema(
+            ImmutableList.of(
+                field("int8", new ArrowType.Int(8, true)),
+                field("int16", new ArrowType.Int(16, true))));
+
+    assertThat(ArrowConversion.toBeamSchema(arrowSchema), equalTo(expected));
+  }
+
+  @Test
+  public void rowIterator() {
+    org.apache.arrow.vector.types.pojo.Schema schema =
+        new org.apache.arrow.vector.types.pojo.Schema(
+            asList(
+                field("int32", new ArrowType.Int(32, true)),
+                field("float64", new 
ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)),
+                field("string", new ArrowType.Utf8()),
+                field("timestampMicroUTC", new 
ArrowType.Timestamp(TimeUnit.MICROSECOND, "UTC")),
+                field("timestampMilliUTC", new 
ArrowType.Timestamp(TimeUnit.MILLISECOND, "UTC")),
+                field(
+                    "int32_list",
+                    new ArrowType.List(),
+                    field("int32s", new ArrowType.Int(32, true))),
+                field("boolean", new ArrowType.Bool()),
+                field("fixed_size_binary", new ArrowType.FixedSizeBinary(3))));
+
+    Schema beamSchema = ArrowConversion.toBeamSchema(schema);
+
+    VectorSchemaRoot expectedSchemaRoot = VectorSchemaRoot.create(schema, 
allocator);
+    expectedSchemaRoot.setRowCount(16);
+    for (FieldVector vector : expectedSchemaRoot.getFieldVectors()) {
 
 Review comment:
   I believe VectorSchemaRoot has an allocateNew
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 378548)
    Time Spent: 9h 50m  (was: 9h 40m)

> BigQuery IO should support read/write in Arrow format
> -----------------------------------------------------
>
>                 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: Kirill Kozlov
>            Priority: Major
>          Time Spent: 9h 50m
>  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)

Reply via email to