-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(bigquery): integrate Arrow query response processing and stream pagination #13944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jinseopkim0
wants to merge
10
commits into
feat-bigquery-arrow-deserializer
from
feat-bigquery-arrow-veneer
+426
−179
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
850e483
feat(bigquery): integrate Arrow query response processing and stream …
jinseopkim0 ee82097
refactor(bigquery): import Arrow IPC classes and simplify FQCNs
jinseopkim0 1905250
refactor(bigquery): clean up DataFormatOptions constructor parameter …
jinseopkim0 bb960be
refactor(bigquery): import Arrow IPC classes and simplify FQCNs
jinseopkim0 1cb383c
refactor(bigquery): delegate Arrow Pojo Schema/Field conversions to A…
jinseopkim0 6c6ffb8
refactor(bigquery): eliminate FQCNs in ArrowPojoUtils, QueryRequestIn…
jinseopkim0 80ae0af
refactor(bigquery): eliminate FQCNs in ArrowSerializationOptionsConve…
jinseopkim0 b05cd0e
test(bigquery): add testQueryResultsFormatArrow integration test case
jinseopkim0 fab15df
fix(bigquery): address gemini-code-assist review feedback on Arrow pa…
jinseopkim0 1f2943a
refactor(bigquery): extract duplicate firstPageRows deserialization i…
jinseopkim0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...igquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ArrowPojoUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed 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 com.google.cloud.bigquery; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import org.apache.arrow.memory.BufferAllocator; | ||
| import org.apache.arrow.vector.FieldVector; | ||
| import org.apache.arrow.vector.types.pojo.ArrowType; | ||
|
|
||
| /** Internal helper for Apache Arrow Schema/Field conversions. */ | ||
| final class ArrowPojoUtils { | ||
|
|
||
| private ArrowPojoUtils() {} | ||
|
|
||
| static Schema arrowSchemaToBigQuerySchema(Object arrowSchemaObj) { | ||
| org.apache.arrow.vector.types.pojo.Schema arrowSchema = | ||
| (org.apache.arrow.vector.types.pojo.Schema) arrowSchemaObj; | ||
| List<Field> fields = new ArrayList<>(); | ||
| for (org.apache.arrow.vector.types.pojo.Field arrowField : arrowSchema.getFields()) { | ||
| fields.add(arrowFieldToBigQueryField(arrowField)); | ||
| } | ||
| return Schema.of(fields); | ||
| } | ||
|
|
||
| static Field arrowFieldToBigQueryField(Object arrowFieldObj) { | ||
| org.apache.arrow.vector.types.pojo.Field arrowField = | ||
| (org.apache.arrow.vector.types.pojo.Field) arrowFieldObj; | ||
| String name = arrowField.getName(); | ||
| ArrowType type = arrowField.getType(); | ||
| Field.Builder builder; | ||
|
|
||
| if (type instanceof ArrowType.List) { | ||
| if (arrowField.getChildren().isEmpty()) { | ||
| throw new IllegalArgumentException( | ||
| "Arrow List field must have at least one child field: " + name); | ||
| } | ||
| org.apache.arrow.vector.types.pojo.Field innerField = arrowField.getChildren().get(0); | ||
| LegacySQLTypeName innerType = arrowTypeToLegacySQLTypeName(innerField.getType()); | ||
| builder = Field.newBuilder(name, innerType); | ||
| builder.setMode(Field.Mode.REPEATED); | ||
| if (!innerField.getChildren().isEmpty()) { | ||
| List<Field> subFields = new ArrayList<>(); | ||
| for (org.apache.arrow.vector.types.pojo.Field childField : innerField.getChildren()) { | ||
| subFields.add(arrowFieldToBigQueryField(childField)); | ||
| } | ||
| builder.setType(LegacySQLTypeName.RECORD, FieldList.of(subFields)); | ||
| } | ||
| } else { | ||
| LegacySQLTypeName bqType = arrowTypeToLegacySQLTypeName(type); | ||
| builder = Field.newBuilder(name, bqType); | ||
| if (arrowField.isNullable()) { | ||
| builder.setMode(Field.Mode.NULLABLE); | ||
| } else { | ||
| builder.setMode(Field.Mode.REQUIRED); | ||
| } | ||
| if (!arrowField.getChildren().isEmpty()) { | ||
| List<Field> subFields = new ArrayList<>(); | ||
| for (org.apache.arrow.vector.types.pojo.Field childField : arrowField.getChildren()) { | ||
| subFields.add(arrowFieldToBigQueryField(childField)); | ||
| } | ||
| builder.setType(LegacySQLTypeName.RECORD, FieldList.of(subFields)); | ||
| } | ||
| } | ||
| return builder.build(); | ||
| } | ||
|
|
||
| static List<FieldVector> createVectors(Object arrowSchemaObj, BufferAllocator allocator) { | ||
| org.apache.arrow.vector.types.pojo.Schema arrowSchema = | ||
| (org.apache.arrow.vector.types.pojo.Schema) arrowSchemaObj; | ||
| List<FieldVector> vectors = new ArrayList<>(); | ||
| for (org.apache.arrow.vector.types.pojo.Field field : arrowSchema.getFields()) { | ||
| vectors.add(field.createVector(allocator)); | ||
| } | ||
| return vectors; | ||
| } | ||
|
Comment on lines
+82
to
+90
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap the vector creation loop in a try-catch block to close any successfully created vectors in reverse order (LIFO) if an exception is thrown during the process. This ensures exception safety and prevents resource leaks. static List<FieldVector> createVectors(Object arrowSchemaObj, BufferAllocator allocator) {
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
(org.apache.arrow.vector.types.pojo.Schema) arrowSchemaObj;
List<FieldVector> vectors = new ArrayList<>();
try {
for (org.apache.arrow.vector.types.pojo.Field field : arrowSchema.getFields()) {
vectors.add(field.createVector(allocator));
}
return vectors;
} catch (Throwable t) {
for (int i = vectors.size() - 1; i >= 0; i--) {
try {
vectors.get(i).close();
} catch (Exception e) {
// ignore
}
}
throw t;
}
}References
|
||
|
|
||
| private static LegacySQLTypeName arrowTypeToLegacySQLTypeName(ArrowType type) { | ||
| switch (type.getTypeID()) { | ||
| case Int: | ||
| return LegacySQLTypeName.INTEGER; | ||
| case FloatingPoint: | ||
| return LegacySQLTypeName.FLOAT; | ||
| case Utf8: | ||
| return LegacySQLTypeName.STRING; | ||
| case Bool: | ||
| return LegacySQLTypeName.BOOLEAN; | ||
| case Binary: | ||
| return LegacySQLTypeName.BYTES; | ||
| case Decimal: | ||
| return LegacySQLTypeName.NUMERIC; | ||
| case Timestamp: | ||
| return LegacySQLTypeName.TIMESTAMP; | ||
| case Date: | ||
| return LegacySQLTypeName.DATE; | ||
| case Time: | ||
| return LegacySQLTypeName.TIME; | ||
| case Struct: | ||
| return LegacySQLTypeName.RECORD; | ||
| default: | ||
| throw new IllegalArgumentException("Unsupported Arrow type: " + type.getTypeID()); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an exception is thrown during
field.createVector(allocator)(for example, due to allocator capacity limits or other runtime issues), any vectors already added to thevectorslist will not be closed, leading to a memory/resource leak. Wrapping the loop in atry-catchblock to close any already allocated vectors in thecatchblock before rethrowing the exception prevents this leak.References