Skip to content

Commit 7fc0c80

Browse files
committed
docs(bigquery): add Javadoc comments to all methods in ArrowDeserializer and ArrowPojoUtils
1 parent 9acfc1f commit 7fc0c80

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,20 @@
4545
*/
4646
final class ArrowDeserializer {
4747

48+
/** Lazy initialization holder for the root {@link BufferAllocator}. */
4849
private static class AllocatorHolder {
4950
private static final BufferAllocator ALLOCATOR = new RootAllocator(Long.MAX_VALUE);
5051
}
5152

53+
/**
54+
* Instantiates a new {@link VectorSchemaRoot} for the given Arrow schema using vectors allocated
55+
* from the provided child allocator, ensuring LIFO cleanup if an error occurs during
56+
* construction.
57+
*
58+
* @param arrowSchema the Apache Arrow schema definition
59+
* @param allocator the buffer allocator to bind the vectors to
60+
* @return a new VectorSchemaRoot containing allocated field vectors
61+
*/
5262
private static VectorSchemaRoot createVectorSchemaRoot(
5363
org.apache.arrow.vector.types.pojo.Schema arrowSchema, BufferAllocator allocator) {
5464
List<FieldVector> vectors = ArrowPojoUtils.createVectors(arrowSchema, allocator);
@@ -93,6 +103,13 @@ static String arrowSchemaToJson(Object arrowSchema) {
93103
return ((org.apache.arrow.vector.types.pojo.Schema) arrowSchema).toJson();
94104
}
95105

106+
/**
107+
* Deserializes an Apache Arrow Schema object from its JSON string representation.
108+
*
109+
* @param json the JSON string representation of the Arrow schema
110+
* @return the deserialized Apache Arrow Schema object, or null if json is null
111+
* @throws IllegalArgumentException if the JSON string cannot be parsed as an Arrow schema
112+
*/
96113
static Object jsonToArrowSchema(String json) {
97114
if (json == null) {
98115
return null;
@@ -195,8 +212,8 @@ static Schema arrowSchemaToBigQuerySchema(Object arrowSchema) {
195212
* Deserializes a raw binary Arrow record batch payload into a list of BigQuery {@link
196213
* FieldValueList} row objects.
197214
*
198-
* <p>Allocates off-heap memory within a local {@link RootAllocator} scope and closes all Arrow
199-
* vector resources before returning, guaranteeing that native memory is released.
215+
* <p>Allocates off-heap memory within a local child allocator scope and closes all Arrow vector
216+
* resources before returning, guaranteeing that native memory is released.
200217
*
201218
* @param recordBatchBytes the raw binary Arrow record batch payload
202219
* @param schema the target BigQuery Schema

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,22 @@
2424
import org.apache.arrow.vector.types.pojo.Field;
2525
import 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+
*/
2832
final 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

Comments
 (0)