GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(bigquery): accelerate row-based query() with Arrow wire format by jinseopkim0 · Pull Request #14405 · googleapis/google-cloud-java

feat(bigquery): accelerate row-based query() with Arrow wire format #14405

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.

Sign up for GitHub

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

Merged
jinseopkim0 merged 1 commit into main from feat-bigquery-arrow-query-rowbased
Sep 18, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat(bigquery): accelerate row-based query() with Arrow wire format #14405

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
e2c96f0
feat(bigquery): accelerate row-based query() with Arrow wire format
jinseopkim0 Sep 18, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

235 changes: 200 additions & 35 deletions 235 ...-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.primitives.Longs;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Scope;
Expand Down Expand Up @@ -2408,23 +2409,11 @@ public com.google.api.services.bigquery.model.QueryResponse call()
return job;
}

StatementType statementType =
results.getStatementType() != null
? StatementType.valueOf(results.getStatementType())
: null;
Long totalBytesBilled = results.getTotalBytesBilled();
Long totalBytesProcessed = results.getTotalBytesProcessed();
Long totalSlotMs = results.getTotalSlotMs();
Long numDmlAffectedRows = results.getNumDmlAffectedRows();
SessionInfo sessionInfo =
results.getSessionInfo() != null ? SessionInfo.fromPb(results.getSessionInfo()) : null;

if (results.getPageToken() != null) {
JobId jobId = JobId.fromPb(results.getJobReference());
String cursor = results.getPageToken();
return TableResult.newBuilder()
return newTableResultBuilder(results)
.setSchema(schema)
.setTotalRows(numRows)
.setPageNoSchema(
new PageImpl<>(
// fetch next pages of results
Expand All @@ -2435,21 +2424,12 @@ public com.google.api.services.bigquery.model.QueryResponse call()
schema,
getOptions().getDataFormatOptions().useInt64Timestamp())))
.setJobId(jobId)
.setQueryId(results.getQueryId())
.setJobCreationReason(JobCreationReason.fromPb(results.getJobCreationReason()))
.setRowsInPage(results.getRows() != null ? (long) results.getRows().size() : 0L)
.setStatementType(statementType)
.setTotalBytesBilled(totalBytesBilled)
.setTotalBytesProcessed(totalBytesProcessed)
.setTotalSlotMs(totalSlotMs)
.setNumDmlAffectedRows(numDmlAffectedRows)
.setSessionInfo(sessionInfo)
.build();
}
// only 1 page of result
return TableResult.newBuilder()
return newTableResultBuilder(results)
.setSchema(schema)
.setTotalRows(numRows)
.setPageNoSchema(
new PageImpl<>(
new TableDataPageFetcher(null, schema, getOptions(), null, optionMap(options)),
Expand All @@ -2461,15 +2441,198 @@ public com.google.api.services.bigquery.model.QueryResponse call()
// Return the JobID of the successful job
.setJobId(
results.getJobReference() != null ? JobId.fromPb(results.getJobReference()) : null)
.setQueryId(results.getQueryId())
.setJobCreationReason(JobCreationReason.fromPb(results.getJobCreationReason()))
.setRowsInPage(results.getRows() != null ? (long) results.getRows().size() : 0L)
.build();
}

private static TableResult.Builder newTableResultBuilder(
com.google.api.services.bigquery.model.QueryResponse results) {
StatementType statementType =
results.getStatementType() != null
? StatementType.valueOf(results.getStatementType())
: null;
return TableResult.newBuilder()
.setTotalRows(getNumRows(results))
.setQueryId(results.getQueryId())
.setJobCreationReason(
results.getJobCreationReason() != null
? JobCreationReason.fromPb(results.getJobCreationReason())
: null)
.setStatementType(statementType)
.setTotalBytesBilled(totalBytesBilled)
.setTotalBytesProcessed(totalBytesProcessed)
.setTotalSlotMs(totalSlotMs)
.setNumDmlAffectedRows(numDmlAffectedRows)
.setSessionInfo(sessionInfo)
.setTotalBytesBilled(results.getTotalBytesBilled())
.setTotalBytesProcessed(results.getTotalBytesProcessed())
.setTotalSlotMs(results.getTotalSlotMs())
.setNumDmlAffectedRows(results.getNumDmlAffectedRows())
.setSessionInfo(
results.getSessionInfo() != null ? SessionInfo.fromPb(results.getSessionInfo()) : null);
}

private static long getNumRows(com.google.api.services.bigquery.model.QueryResponse results) {
Comment thread
jinseopkim0 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

if (results.getNumDmlAffectedRows() == null && results.getTotalRows() == null) {
return 0L;
} else if (results.getNumDmlAffectedRows() != null) {
return results.getNumDmlAffectedRows();
} else {
return results.getTotalRows().longValue();
}
}

/**
* Executes a fast-path query RPC request expecting Arrow-formatted wire response.
*
* <p>Deserializes the returned Arrow IPC schema and record batch into standard {@link
* TableResult} row-based representations, configuring {@link ArrowQueryPageFetcher} for
* subsequent pages when pagination tokens are returned.
*
* @param projectId project ID in which to execute the query
* @param content query request content PB
* @param options job options
* @return either a {@link Job} if incomplete/fallback is required, or {@link TableResult}
* @throws InterruptedException if interrupted while awaiting RPC execution
*/
private Object queryRpcArrow(
final String projectId, final QueryRequest content, JobOption... options)
throws InterruptedException {
com.google.api.services.bigquery.model.QueryResponse results;
Span queryRpc = null;
if (getOptions().isOpenTelemetryTracingEnabled()
&& getOptions().getOpenTelemetryTracer() != null) {
queryRpc =
getOptions()
.getOpenTelemetryTracer()
.spanBuilder("com.google.cloud.bigquery.BigQuery.queryRpc")
.setAttribute("bq.query.project_id", projectId)
.setAllAttributes(otelAttributesFromQueryRequest(content))
.setAllAttributes(otelAttributesFromOptions(options))
.startSpan();
}
try (Scope queryRpcScope = queryRpc != null ? queryRpc.makeCurrent() : null) {
results =
BigQueryRetryHelper.runWithRetries(
() -> bigQueryRpc.queryRpcSkipExceptionTranslation(projectId, content),
getOptions().getRetrySettings(),
getOptions().getResultRetryAlgorithm(),
getOptions().getClock(),
DEFAULT_RETRY_CONFIG,
getOptions().isOpenTelemetryTracingEnabled(),
getOptions().getOpenTelemetryTracer());
} catch (BigQueryRetryHelper.BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
} finally {
if (queryRpc != null) {
queryRpc.end();
}
}

if (results.getErrors() != null) {
List<BigQueryError> bigQueryErrors =
Lists.transform(results.getErrors(), BigQueryError.FROM_PB_FUNCTION);
throw new BigQueryException(bigQueryErrors);
}

// If query is incomplete, Arrow format for slow query path is not yet supported.
if (!Boolean.TRUE.equals(results.getJobComplete())) {
throw new UnsupportedOperationException(
"Arrow results format for slow query path execution is not yet supported.");
}
Comment thread
jinseopkim0 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


// If the query completed but the Arrow schema is missing from the response, fail fast.
if (results.getArrowSchema() == null
|| results.getArrowSchema().getSerializedSchema() == null) {
throw new BigQueryException(0, "Arrow schema is missing from the response");
}
Comment thread
jinseopkim0 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


// Deserialize Arrow IPC schema and convert to veneer BigQuery Schema.
byte[] arrowSchemaBytes = results.getArrowSchema().decodeSerializedSchema();
org.apache.arrow.vector.types.pojo.Schema arrowSchemaPojo;
try {
arrowSchemaPojo = ArrowDeserializer.deserializeSchema(arrowSchemaBytes);
} catch (IOException e) {
throw new BigQueryException(0, "Failed to deserialize Arrow schema from response", e);
Comment thread
jinseopkim0 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

}
Schema schema = ArrowPojoUtils.arrowSchemaToBigQuerySchema(arrowSchemaPojo);

// Deserialize first page of rows from the Arrow record batch (if present).
List<FieldValueList> firstPageRows;
if (results.getArrowRecordBatch() == null
|| results.getArrowRecordBatch().getSerializedRecordBatch() == null) {
firstPageRows = ImmutableList.of();
} else {
try {
firstPageRows =
ArrowDeserializer.deserializeRecordBatch(
results.getArrowRecordBatch().decodeSerializedRecordBatch(),
schema,
arrowSchemaPojo);
} catch (IOException e) {
throw new BigQueryException(0, "Failed to deserialize Arrow record batch", e);
}
}

// Enforce maxResults limit on the first page if requested.
if (content.getMaxResults() != null && firstPageRows.size() > content.getMaxResults()) {
firstPageRows =
ImmutableList.copyOf(Iterables.limit(firstPageRows, content.getMaxResults().intValue()));
}

// Calculate row offset and determine if subsequent pages exist.
boolean hasMorePages = results.getPageToken() != null;
long initialRowOffset = 0L;
if (hasMorePages) {
Long parsedOffset = Longs.tryParse(results.getPageToken());
if (parsedOffset == null) {
throw new BigQueryException(
0,
String.format(
"Unable to parse page token '%s' as a numeric row offset for Arrow query pagination",
results.getPageToken()));
}
initialRowOffset = parsedOffset;
if (content.getMaxResults() != null
&& (initialRowOffset >= content.getMaxResults()
|| firstPageRows.size() >= content.getMaxResults())) {
hasMorePages = false;
}
}

// Multi-page results: configure ArrowQueryPageFetcher for subsequent tabledata.list calls.
if (hasMorePages) {
if (results.getJobReference() == null) {
throw new BigQueryException(
0, "More pages exist, but no job reference was returned to fetch them.");
}
JobId jobId = JobId.fromPb(results.getJobReference());
String cursor = results.getPageToken();
NextPageFetcher<FieldValueList> pageFetcher =
new ArrowQueryPageFetcher(
jobId,
schema,
arrowSchemaBytes,
arrowSchemaPojo,
getOptions(),
initialRowOffset,
content.getMaxResults(),
optionMap(options));

return newTableResultBuilder(results)
.setSchema(schema)
.setPageNoSchema(new PageImpl<>(pageFetcher, cursor, firstPageRows))
.setJobId(jobId)
.setRowsInPage((long) firstPageRows.size())
.build();
}

// only 1 page of result
return newTableResultBuilder(results)
.setSchema(schema)
.setPageNoSchema(
new PageImpl<>(
new TableDataPageFetcher(null, schema, getOptions(), null, optionMap(options)),
null,
firstPageRows))
Comment thread
jinseopkim0 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

.setJobId(
results.getJobReference() != null ? JobId.fromPb(results.getJobReference()) : null)
.setRowsInPage((long) firstPageRows.size())
.build();
}

Expand All @@ -2489,11 +2652,6 @@ public Object queryWithTimeout(
throws InterruptedException, JobException {
Job.checkNotDryRun(configuration, "query");

if (configuration.getQueryResultsFormat() == QueryResultsFormat.ARROW) {
throw new UnsupportedOperationException(
"QueryResultsFormat.ARROW is not supported with query(). Use queryArrow() instead.");
}

// If JobCreationMode is not explicitly set, update it with default value;
if (configuration.getJobCreationMode() == null) {
configuration =
Expand Down Expand Up @@ -2546,8 +2704,15 @@ && getOptions().getOpenTelemetryTracer() != null) {
content.setTimeoutMs(timeoutMs);
}

if (configuration.getQueryResultsFormat() == QueryResultsFormat.ARROW) {
return queryRpcArrow(projectId, content, options);
}
return queryRpc(projectId, content, options);
}
if (configuration.getQueryResultsFormat() == QueryResultsFormat.ARROW) {
throw new UnsupportedOperationException(
"Arrow results format for slow query path execution is not yet supported.");
}
return create(JobInfo.of(jobId, configuration), options);
} finally {
if (querySpan != null) {
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.