Skip to content

Commit 1f04b96

Browse files
committed
refactor(bigquery): clean up FQCNs in ArrowDeserializer and ArrowDeserializerTest
1 parent c2a9986 commit 1f04b96

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ArrowDeserializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.arrow.vector.complex.ListVector;
3232
import org.apache.arrow.vector.complex.StructVector;
3333
import org.apache.arrow.vector.ipc.ReadChannel;
34+
import org.apache.arrow.vector.ipc.message.ArrowRecordBatch;
3435
import org.apache.arrow.vector.ipc.message.MessageSerializer;
3536
import org.apache.arrow.vector.types.pojo.ArrowType;
3637
import org.apache.arrow.vector.util.ByteArrayReadableSeekableByteChannel;
@@ -179,7 +180,7 @@ static List<FieldValueList> deserializeRecordBatch(
179180
}
180181
try (VectorSchemaRoot root = new VectorSchemaRoot(vectors)) {
181182
VectorLoader loader = new VectorLoader(root);
182-
try (org.apache.arrow.vector.ipc.message.ArrowRecordBatch deserializedBatch =
183+
try (ArrowRecordBatch deserializedBatch =
183184
MessageSerializer.deserializeRecordBatch(
184185
new ReadChannel(new ByteArrayReadableSeekableByteChannel(recordBatchBytes)),
185186
allocator)) {

java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ArrowDeserializerTest.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.bigquery;
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2021
import static org.junit.jupiter.api.Assertions.assertNull;
2122
import static org.junit.jupiter.api.Assertions.fail;
2223

@@ -37,24 +38,30 @@
3738
import org.apache.arrow.vector.VarBinaryVector;
3839
import org.apache.arrow.vector.VarCharVector;
3940
import org.apache.arrow.vector.VectorSchemaRoot;
41+
import org.apache.arrow.vector.VectorUnloader;
4042
import org.apache.arrow.vector.ipc.WriteChannel;
4143
import org.apache.arrow.vector.ipc.message.ArrowRecordBatch;
4244
import org.apache.arrow.vector.ipc.message.MessageSerializer;
4345
import org.apache.arrow.vector.types.TimeUnit;
4446
import org.apache.arrow.vector.types.pojo.ArrowType;
45-
import org.apache.arrow.vector.types.pojo.Field;
4647
import org.apache.arrow.vector.types.pojo.FieldType;
4748
import org.junit.jupiter.api.Test;
4849

4950
public class ArrowDeserializerTest {
5051

5152
@Test
5253
public void testArrowSchemaToBigQuerySchema() {
53-
Field intField = new Field("int_col", FieldType.nullable(new ArrowType.Int(32, true)), null);
54-
Field strField = new Field("str_col", FieldType.notNullable(new ArrowType.Utf8()), null);
55-
Field boolField = new Field("bool_col", FieldType.nullable(new ArrowType.Bool()), null);
56-
Field tsField =
57-
new Field(
54+
org.apache.arrow.vector.types.pojo.Field intField =
55+
new org.apache.arrow.vector.types.pojo.Field(
56+
"int_col", FieldType.nullable(new ArrowType.Int(32, true)), null);
57+
org.apache.arrow.vector.types.pojo.Field strField =
58+
new org.apache.arrow.vector.types.pojo.Field(
59+
"str_col", FieldType.notNullable(new ArrowType.Utf8()), null);
60+
org.apache.arrow.vector.types.pojo.Field boolField =
61+
new org.apache.arrow.vector.types.pojo.Field(
62+
"bool_col", FieldType.nullable(new ArrowType.Bool()), null);
63+
org.apache.arrow.vector.types.pojo.Field tsField =
64+
new org.apache.arrow.vector.types.pojo.Field(
5865
"ts_col",
5966
FieldType.nullable(new ArrowType.Timestamp(TimeUnit.MICROSECOND, "UTC")),
6067
null);
@@ -68,13 +75,11 @@ public void testArrowSchemaToBigQuerySchema() {
6875
assertEquals(4, bqSchema.getFields().size());
6976
assertEquals("int_col", bqSchema.getFields().get(0).getName());
7077
assertEquals(LegacySQLTypeName.INTEGER, bqSchema.getFields().get(0).getType());
71-
assertEquals(
72-
com.google.cloud.bigquery.Field.Mode.NULLABLE, bqSchema.getFields().get(0).getMode());
78+
assertEquals(Field.Mode.NULLABLE, bqSchema.getFields().get(0).getMode());
7379

7480
assertEquals("str_col", bqSchema.getFields().get(1).getName());
7581
assertEquals(LegacySQLTypeName.STRING, bqSchema.getFields().get(1).getType());
76-
assertEquals(
77-
com.google.cloud.bigquery.Field.Mode.REQUIRED, bqSchema.getFields().get(1).getMode());
82+
assertEquals(Field.Mode.REQUIRED, bqSchema.getFields().get(1).getMode());
7883

7984
assertEquals("bool_col", bqSchema.getFields().get(2).getName());
8085
assertEquals(LegacySQLTypeName.BOOLEAN, bqSchema.getFields().get(2).getType());
@@ -124,7 +129,8 @@ public void testDeserializeRecordBatchPrimitives() throws IOException {
124129
tsVector.setValueCount(2);
125130

126131
List<FieldVector> vectors =
127-
ImmutableList.of(intVector, nameVector, scoreVector, activeVector, bytesVector, tsVector);
132+
ImmutableList.of(
133+
intVector, nameVector, scoreVector, activeVector, bytesVector, tsVector);
128134

129135
try (VectorSchemaRoot root = new VectorSchemaRoot(vectors)) {
130136
org.apache.arrow.vector.types.pojo.Schema arrowSchema = root.getSchema();
@@ -175,8 +181,8 @@ public void testSchemaMismatchThrowsException() {
175181
try (VectorSchemaRoot root = new VectorSchemaRoot(ImmutableList.of(intVector))) {
176182
Schema mismatchedSchema =
177183
Schema.of(
178-
com.google.cloud.bigquery.Field.of("col1", LegacySQLTypeName.INTEGER),
179-
com.google.cloud.bigquery.Field.of("col2", LegacySQLTypeName.STRING));
184+
Field.of("col1", LegacySQLTypeName.INTEGER),
185+
Field.of("col2", LegacySQLTypeName.STRING));
180186

181187
try {
182188
ArrowDeserializer.arrowRootToFieldValueList(root, 0, mismatchedSchema);
@@ -195,8 +201,7 @@ private byte[] serializeVectorSchemaRoot(VectorSchemaRoot root, BufferAllocator
195201
ByteArrayOutputStream out = new ByteArrayOutputStream();
196202
WriteChannel channel = new WriteChannel(Channels.newChannel(out));
197203

198-
org.apache.arrow.vector.VectorUnloader unloader =
199-
new org.apache.arrow.vector.VectorUnloader(root);
204+
VectorUnloader unloader = new VectorUnloader(root);
200205
try (ArrowRecordBatch batch = unloader.getRecordBatch()) {
201206
MessageSerializer.serialize(channel, batch);
202207
}

0 commit comments

Comments
 (0)