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 — fix(bigquery): use first page row count for Arrow query pagination offset by jinseopkim0 · Pull Request #14466 · googleapis/google-cloud-java

fix(bigquery): use first page row count for Arrow query pagination offset #14466

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 fix-arrow-query-page-token
Sep 21, 2026

Uh oh!

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

Merged

fix(bigquery): use first page row count for Arrow query pagination offset #14466

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
7e9d8a3
fix(bigquery): use first page row count for Arrow query pagination of…
jinseopkim0 Sep 21, 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

16 changes: 2 additions & 14 deletions 16 ...-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,7 +67,6 @@
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 @@ -2620,20 +2619,9 @@ && getOptions().getOpenTelemetryTracer() != null) {

// Calculate row offset and determine if subsequent pages exist.
boolean hasMorePages = results.getPageToken() != null;
long initialRowOffset = 0L;
long initialRowOffset = (long) firstPageRows.size();
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())) {
if (content.getMaxResults() != null && initialRowOffset >= content.getMaxResults()) {
hasMorePages = false;
}
}
Expand Down
38 changes: 31 additions & 7 deletions 38 ...query/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3284,6 +3284,24 @@ void testQueryWithArrowFormatMultiplePagesWithMaxResults()
schemaBytes = out.toByteArray();
}

// Prepare page 1 Arrow batch for initial response with 1 row
byte[] page1BatchBytes;
try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
BigIntVector idVector = new BigIntVector("id", allocator)) {
idVector.allocateNew(1);
idVector.set(0, 1L);
idVector.setValueCount(1);
try (VectorSchemaRoot root = new VectorSchemaRoot(ImmutableList.of(idVector))) {
VectorUnloader unloader = new VectorUnloader(root);
try (ArrowRecordBatch recordBatch = unloader.getRecordBatch();
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
WriteChannel channel = new WriteChannel(Channels.newChannel(out));
MessageSerializer.serialize(channel, recordBatch);
page1BatchBytes = out.toByteArray();
}
}
}

// Prepare page 2 Arrow batch for streaming with 2 rows
byte[] page2BatchBytes;
try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
Expand All @@ -3310,10 +3328,13 @@ void testQueryWithArrowFormatMultiplePagesWithMaxResults()
.setJobComplete(true)
.setJobReference(queryJob.toPb())
.setTotalRows(BigInteger.valueOf(3L))
.setPageToken("1")
.setPageToken("BG4QSSWFUAAQAAASA4EAAEEAQCAAKGQIBAABB7X7777QOIFQVYKQ====")
.setArrowSchema(
new com.google.api.services.bigquery.model.ArrowSchema()
.setSerializedSchema(BaseEncoding.base64().encode(schemaBytes)));
.setSerializedSchema(BaseEncoding.base64().encode(schemaBytes)))
.setArrowRecordBatch(
new com.google.api.services.bigquery.model.ArrowRecordBatch()
.setSerializedRecordBatch(BaseEncoding.base64().encode(page1BatchBytes)));

when(bigqueryRpcMock.queryRpcSkipExceptionTranslation(eq(PROJECT), any(QueryRequest.class)))
.thenReturn(queryResponsePb);
Expand Down Expand Up @@ -3632,7 +3653,7 @@ void testQueryWithArrowFormatIncompleteJobJobNotFound() throws Exception {
}

@Test
void testQueryWithArrowFormatInvalidPageToken() throws Exception {
void testQueryWithArrowFormatOpaquePageToken() throws Exception {
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
new org.apache.arrow.vector.types.pojo.Schema(
ImmutableList.of(
Expand All @@ -3648,11 +3669,11 @@ void testQueryWithArrowFormatInvalidPageToken() throws Exception {
JobId queryJob = JobId.of(PROJECT, JOB).toBuilder().setLocation(LOCATION).build();
com.google.api.services.bigquery.model.QueryResponse queryResponsePb =
new com.google.api.services.bigquery.model.QueryResponse()
.setQueryId("q-arrow-invalid-token")
.setQueryId("q-arrow-opaque-token")
.setJobComplete(true)
.setJobReference(queryJob.toPb())
.setTotalRows(BigInteger.valueOf(2L))
.setPageToken("invalid-non-numeric-token")
.setPageToken("BG4QSSWFUAAQAAASA4EAAEEAQCAAKGQIBAABB7X7777QOIFQVYKQ====")
.setArrowSchema(
new com.google.api.services.bigquery.model.ArrowSchema()
.setSerializedSchema(BaseEncoding.base64().encode(schemaBytes)));
Expand All @@ -3666,8 +3687,11 @@ void testQueryWithArrowFormatInvalidPageToken() throws Exception {
QueryJobConfiguration.newBuilder("SELECT id FROM test")
.setQueryResultsFormat(QueryResultsFormat.ARROW)
.build();
BigQueryException e = assertThrows(BigQueryException.class, () -> bigquery.query(config));
assertTrue(e.getMessage().contains("Unable to parse page token 'invalid-non-numeric-token'"));
TableResult result = bigquery.query(config);
assertNotNull(result);
assertTrue(result.hasNextPage());
assertEquals(
"BG4QSSWFUAAQAAASA4EAAEEAQCAAKGQIBAABB7X7777QOIFQVYKQ====", result.getNextPageToken());
}

@Test
Expand Down
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.