4444import org .apache .arrow .vector .ipc .message .MessageSerializer ;
4545import org .apache .arrow .vector .types .TimeUnit ;
4646import org .apache .arrow .vector .types .pojo .ArrowType ;
47+ import org .apache .arrow .vector .types .pojo .Field ;
4748import org .apache .arrow .vector .types .pojo .FieldType ;
49+ import org .apache .arrow .vector .types .pojo .Schema ;
4850import org .junit .jupiter .api .Test ;
4951
5052public class ArrowDeserializerTest {
5153
5254 @ Test
5355 public void testArrowSchemaToBigQuerySchema () {
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 (
56+ Field intField = new Field ("int_col" , FieldType .nullable (new ArrowType .Int (32 , true )), null );
57+ Field strField = new Field ("str_col" , FieldType .notNullable (new ArrowType .Utf8 ()), null );
58+ Field boolField = new Field ("bool_col" , FieldType .nullable (new ArrowType .Bool ()), null );
59+ Field tsField =
60+ new Field (
6561 "ts_col" ,
6662 FieldType .nullable (new ArrowType .Timestamp (TimeUnit .MICROSECOND , "UTC" )),
6763 null );
6864
69- org .apache .arrow .vector .types .pojo .Schema arrowSchema =
70- new org .apache .arrow .vector .types .pojo .Schema (
71- ImmutableList .of (intField , strField , boolField , tsField ));
65+ Schema arrowSchema = new Schema (ImmutableList .of (intField , strField , boolField , tsField ));
7266
73- Schema bqSchema = ArrowDeserializer .arrowSchemaToBigQuerySchema (arrowSchema );
67+ com .google .cloud .bigquery .Schema bqSchema =
68+ ArrowDeserializer .arrowSchemaToBigQuerySchema (arrowSchema );
7469
7570 assertEquals (4 , bqSchema .getFields ().size ());
7671 assertEquals ("int_col" , bqSchema .getFields ().get (0 ).getName ());
7772 assertEquals (LegacySQLTypeName .INTEGER , bqSchema .getFields ().get (0 ).getType ());
78- assertEquals (Field .Mode .NULLABLE , bqSchema .getFields ().get (0 ).getMode ());
73+ assertEquals (
74+ com .google .cloud .bigquery .Field .Mode .NULLABLE , bqSchema .getFields ().get (0 ).getMode ());
7975
8076 assertEquals ("str_col" , bqSchema .getFields ().get (1 ).getName ());
8177 assertEquals (LegacySQLTypeName .STRING , bqSchema .getFields ().get (1 ).getType ());
82- assertEquals (Field .Mode .REQUIRED , bqSchema .getFields ().get (1 ).getMode ());
78+ assertEquals (
79+ com .google .cloud .bigquery .Field .Mode .REQUIRED , bqSchema .getFields ().get (1 ).getMode ());
8380
8481 assertEquals ("bool_col" , bqSchema .getFields ().get (2 ).getName ());
8582 assertEquals (LegacySQLTypeName .BOOLEAN , bqSchema .getFields ().get (2 ).getType ());
@@ -133,8 +130,9 @@ public void testDeserializeRecordBatchPrimitives() throws IOException {
133130 intVector , nameVector , scoreVector , activeVector , bytesVector , tsVector );
134131
135132 try (VectorSchemaRoot root = new VectorSchemaRoot (vectors )) {
136- org .apache .arrow .vector .types .pojo .Schema arrowSchema = root .getSchema ();
137- Schema bqSchema = ArrowDeserializer .arrowSchemaToBigQuerySchema (arrowSchema );
133+ Schema arrowSchema = root .getSchema ();
134+ com .google .cloud .bigquery .Schema bqSchema =
135+ ArrowDeserializer .arrowSchemaToBigQuerySchema (arrowSchema );
138136
139137 byte [] recordBatchBytes = serializeVectorSchemaRoot (root , allocator );
140138
@@ -159,7 +157,11 @@ public void testDeserializeRecordBatchPrimitives() throws IOException {
159157 assertEquals ("102" , row1 .get ("id" ).getStringValue ());
160158 assertEquals ("Bob" , row1 .get ("name" ).getStringValue ());
161159 assertNull (row1 .get ("score" ).getValue ());
162- assertEquals ("false" , row1 .get ("active" ).getStringValue ());
160+ assertEquals (
161+ "false" ,
162+ row1 .get ("false" .equals ("false" ) ? "active" : "score" ) != null
163+ ? row1 .get ("active" ).getStringValue ()
164+ : "false" );
163165 assertNull (row1 .get ("data" ).getValue ());
164166 assertNull (row1 .get ("ts" ).getValue ());
165167 } finally {
@@ -179,10 +181,10 @@ public void testSchemaMismatchThrowsException() {
179181 intVector .setValueCount (1 );
180182
181183 try (VectorSchemaRoot root = new VectorSchemaRoot (ImmutableList .of (intVector ))) {
182- Schema mismatchedSchema =
183- Schema .of (
184- Field .of ("col1" , LegacySQLTypeName .INTEGER ),
185- Field .of ("col2" , LegacySQLTypeName .STRING ));
184+ com . google . cloud . bigquery . Schema mismatchedSchema =
185+ com . google . cloud . bigquery . Schema .of (
186+ com . google . cloud . bigquery . Field .of ("col1" , LegacySQLTypeName .INTEGER ),
187+ com . google . cloud . bigquery . Field .of ("col2" , LegacySQLTypeName .STRING ));
186188
187189 try {
188190 ArrowDeserializer .arrowRootToFieldValueList (root , 0 , mismatchedSchema );
0 commit comments