Skip to content

Commit b44ffe8

Browse files
authored
feat(bigquery): add zero-copy queryArrow API for Arrow VectorSchemaRoot streaming (#14402)
This PR introduces the `queryArrow` API on the `BigQuery` client veneer. It enables applications to stream query results as Apache Arrow `VectorSchemaRoot` batches with zero memory copies, supporting fast-path query execution and automatic fallback to BigQuery Storage Read API sessions for larger queries.
1 parent e1c9326 commit b44ffe8

5 files changed

Lines changed: 541 additions & 2 deletions

File tree

‎java-bigquery/google-cloud-bigquery/pom.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@
122122
<artifactId>arrow-memory-netty</artifactId>
123123
</dependency>
124124

125+
126+
125127
<dependency>
126128
<groupId>com.google.errorprone</groupId>
127129
<artifactId>error_prone_annotations</artifactId>

‎java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,58 @@ TableResult query(QueryJobConfiguration configuration, JobOption... options)
16391639
TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOption... options)
16401640
throws InterruptedException, JobException;
16411641

1642+
/**
1643+
* <b>[Beta]</b> Runs the query associated with the request and returns an {@link
1644+
* ArrowQueryResult} yielding Apache Arrow {@code VectorSchemaRoot} batches directly for zero-copy
1645+
* vector access.
1646+
*
1647+
* <p>Callers must manage off-heap native memory by closing the returned {@link ArrowQueryResult}
1648+
* (e.g. via a {@code try-with-resources} block).
1649+
*
1650+
* <p><b>Prerequisite:</b> Requires the BigQuery Storage Read API ({@code
1651+
* bigquerystorage.googleapis.com}) to be enabled on your GCP project.
1652+
*
1653+
* @param configuration the query configuration
1654+
* @param options query options
1655+
* @return an {@link ArrowQueryResult} streaming Arrow vectors
1656+
* @throws BigQueryException upon failure
1657+
* @throws InterruptedException if the current thread gets interrupted while waiting for the query
1658+
* to complete
1659+
* @throws JobException if the job completes unsuccessfully
1660+
*/
1661+
@BetaApi
1662+
default ArrowQueryResult queryArrow(QueryJobConfiguration configuration, JobOption... options)
1663+
throws InterruptedException, JobException {
1664+
throw new UnsupportedOperationException("queryArrow is not implemented");
1665+
}
1666+
1667+
/**
1668+
* <b>[Beta]</b> Runs the query associated with the request, using the given JobId, and returns an
1669+
* {@link ArrowQueryResult} yielding Apache Arrow {@code VectorSchemaRoot} batches directly for
1670+
* zero-copy vector access.
1671+
*
1672+
* <p>Callers must manage off-heap native memory by closing the returned {@link ArrowQueryResult}
1673+
* (e.g. via a {@code try-with-resources} block).
1674+
*
1675+
* <p><b>Prerequisite:</b> Requires the BigQuery Storage Read API ({@code
1676+
* bigquerystorage.googleapis.com}) to be enabled on your GCP project.
1677+
*
1678+
* @param configuration the query configuration
1679+
* @param jobId the job ID to use
1680+
* @param options query options
1681+
* @return an {@link ArrowQueryResult} streaming Arrow vectors
1682+
* @throws BigQueryException upon failure
1683+
* @throws InterruptedException if the current thread gets interrupted while waiting for the query
1684+
* to complete
1685+
* @throws JobException if the job completes unsuccessfully
1686+
*/
1687+
@BetaApi
1688+
default ArrowQueryResult queryArrow(
1689+
QueryJobConfiguration configuration, JobId jobId, JobOption... options)
1690+
throws InterruptedException, JobException {
1691+
throw new UnsupportedOperationException("queryArrow is not implemented");
1692+
}
1693+
16421694
/**
16431695
* Starts the query associated with the request, using the given JobId. It returns either
16441696
* TableResult for quick queries or Job object for long-running queries.

0 commit comments

Comments
 (0)