2424import org .apache .arrow .vector .types .pojo .Field ;
2525import org .apache .arrow .vector .types .pojo .Schema ;
2626
27- /** Internal helper for Apache Arrow Schema/Field conversions. */
27+ /**
28+ * Internal helper utility for converting Apache Arrow POJO Schema and Field definitions into
29+ * BigQuery Veneer {@link com.google.cloud.bigquery.Schema} and {@link
30+ * com.google.cloud.bigquery.Field} models.
31+ */
2832final class ArrowPojoUtils {
2933
3034 private ArrowPojoUtils () {}
3135
36+ /**
37+ * Converts an Apache Arrow {@link Schema} into a BigQuery Veneer {@link
38+ * com.google.cloud.bigquery.Schema}.
39+ *
40+ * @param arrowSchema the Apache Arrow schema definition
41+ * @return the corresponding BigQuery Veneer Schema
42+ */
3243 static com .google .cloud .bigquery .Schema arrowSchemaToBigQuerySchema (Schema arrowSchema ) {
3344 List <com .google .cloud .bigquery .Field > fields = new ArrayList <>();
3445 for (Field arrowField : arrowSchema .getFields ()) {
@@ -37,6 +48,16 @@ static com.google.cloud.bigquery.Schema arrowSchemaToBigQuerySchema(Schema arrow
3748 return com .google .cloud .bigquery .Schema .of (fields );
3849 }
3950
51+ /**
52+ * Recursively converts an Apache Arrow {@link Field} into a BigQuery Veneer {@link
53+ * com.google.cloud.bigquery.Field}.
54+ *
55+ * <p>Handles primitive types, repeated/list types, and nested struct/record types.
56+ *
57+ * @param arrowField the Apache Arrow field definition
58+ * @return the corresponding BigQuery Veneer Field
59+ * @throws IllegalArgumentException if an Arrow List field contains no child elements
60+ */
4061 static com .google .cloud .bigquery .Field arrowFieldToBigQueryField (Field arrowField ) {
4162 String name = arrowField .getName ();
4263 ArrowType type = arrowField .getType ();
@@ -83,6 +104,17 @@ static com.google.cloud.bigquery.Field arrowFieldToBigQueryField(Field arrowFiel
83104 return builder .build ();
84105 }
85106
107+ /**
108+ * Instantiates a list of {@link FieldVector} instances corresponding to the fields in the
109+ * provided Arrow schema using the specified allocator.
110+ *
111+ * <p>Guarantees exception-safe LIFO cleanup of already-allocated vectors if an allocation fails
112+ * halfway through.
113+ *
114+ * @param arrowSchema the Apache Arrow schema definition
115+ * @param allocator the buffer allocator to allocate vector memory from
116+ * @return the list of allocated FieldVector instances
117+ */
86118 static List <FieldVector > createVectors (Schema arrowSchema , BufferAllocator allocator ) {
87119 List <FieldVector > vectors = new ArrayList <>();
88120 try {
@@ -102,6 +134,13 @@ static List<FieldVector> createVectors(Schema arrowSchema, BufferAllocator alloc
102134 }
103135 }
104136
137+ /**
138+ * Maps an Apache {@link ArrowType} to its corresponding BigQuery {@link LegacySQLTypeName}.
139+ *
140+ * @param type the Apache Arrow type
141+ * @return the matching BigQuery LegacySQLTypeName
142+ * @throws IllegalArgumentException if the Arrow type is unsupported
143+ */
105144 private static LegacySQLTypeName arrowTypeToLegacySQLTypeName (ArrowType type ) {
106145 switch (type .getTypeID ()) {
107146 case Int :
0 commit comments