Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.paging.Page;
import com.google.api.gax.rpc.HeaderProvider;
import com.google.api.gax.rpc.NoHeaderProvider;
import com.google.api.services.bigquery.model.ErrorProto;
import com.google.api.services.bigquery.model.GetQueryResultsResponse;
import com.google.api.services.bigquery.model.ProjectList;
Expand Down Expand Up @@ -371,8 +373,10 @@ private static void configureReadSettings(
if (options.getCredentials() != null) {
settingsBuilder.setCredentialsProvider(
FixedCredentialsProvider.create(options.getCredentials()));
} else {
settingsBuilder.setCredentialsProvider(NoCredentialsProvider.create());
}
HeaderProvider headerProvider = options.getMergedHeaderProvider(null);
HeaderProvider headerProvider = options.getMergedHeaderProvider(new NoHeaderProvider());
if (headerProvider != null) {
settingsBuilder.setHeaderProvider(headerProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.google.cloud.bigquery.Acl.DatasetAclEntity;
import com.google.cloud.bigquery.Acl.Expr;
import com.google.cloud.bigquery.Acl.User;
import com.google.cloud.bigquery.ArrowQueryResult;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQuery.DatasetField;
import com.google.cloud.bigquery.BigQuery.DatasetListOption;
Expand Down Expand Up @@ -118,6 +119,7 @@
import com.google.cloud.bigquery.QueryJobConfiguration.JobCreationMode;
import com.google.cloud.bigquery.QueryJobConfiguration.Priority;
import com.google.cloud.bigquery.QueryParameterValue;
import com.google.cloud.bigquery.QueryResultsFormat;
import com.google.cloud.bigquery.Range;
import com.google.cloud.bigquery.RangePartitioning;
import com.google.cloud.bigquery.Routine;
Expand Down Expand Up @@ -203,6 +205,7 @@
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.arrow.vector.VectorSchemaRoot;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -7499,6 +7502,53 @@ void testQueryWithTimeout() throws InterruptedException {
assertTrue(millis < 1_000_000 * 2);
}

@Test
void testQueryResultsFormatArrow() throws InterruptedException {
String query = "SELECT 1 as id, 'hello' as name, TIMESTAMP('2026-08-10T12:00:00Z') as ts";
QueryJobConfiguration config =
QueryJobConfiguration.newBuilder(query)
.setQueryResultsFormat(QueryResultsFormat.ARROW)
.setJobCreationMode(JobCreationMode.JOB_CREATION_OPTIONAL)
.build();
try (ArrowQueryResult result = bigquery.queryArrow(config)) {
assertNotNull(result);
int batchCount = 0;
long totalRows = 0;
for (VectorSchemaRoot root : result) {
batchCount++;
totalRows += root.getRowCount();
assertEquals(1, root.getRowCount());
}
Comment on lines +7517 to +7521

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To ensure the integrity of the data returned via the Arrow format, consider validating the schema and the actual values within the VectorSchemaRoot. Currently, the test only validates the row count, which could pass even if the data itself is corrupted or incorrectly mapped.

      for (VectorSchemaRoot root : result) {
        batchCount++;
        totalRows += root.getRowCount();
        assertEquals(1, root.getRowCount());
        assertNotNull(root.getSchema().findField("id"));
        assertNotNull(root.getSchema().findField("name"));
        assertNotNull(root.getSchema().findField("ts"));
        assertEquals(1L, root.getVector("id").getObject(0));
        assertEquals("hello", root.getVector("name").getObject(0).toString());
      }

assertEquals(1, batchCount);
assertEquals(1, totalRows);
}
}

@Test
void testQueryResultsFormatArrowMultiPage() throws InterruptedException {
// Under fast-query execution, the initial REST response defaults to a 10 MB payload limit.
// Setting maxResults limits the initial page to 5,000 rows, forcing the remaining 10,000 rows
// to stream across multiple batches via the BigQuery Storage Read API.
String query = "SELECT x FROM UNNEST(GENERATE_ARRAY(1, 15000)) AS x";
Comment thread
jinseopkim0 marked this conversation as resolved.
QueryJobConfiguration config =
QueryJobConfiguration.newBuilder(query)
.setQueryResultsFormat(QueryResultsFormat.ARROW)
.setJobCreationMode(JobCreationMode.JOB_CREATION_OPTIONAL)
.setMaxResults(5000L)
.build();
try (ArrowQueryResult result = bigquery.queryArrow(config)) {
assertNotNull(result);
int batchCount = 0;
long totalRows = 0;
for (VectorSchemaRoot root : result) {
batchCount++;
totalRows += root.getRowCount();
}
Comment thread
jinseopkim0 marked this conversation as resolved.
assertTrue(batchCount > 1);
assertEquals(15000, totalRows);
}
}

@Test
void testUniverseDomainWithInvalidUniverseDomain() {
RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
Expand Down
Loading