Skip to content

fix(bigquery): raise when an Arrow batch arrives before its schema - #9681

Open
ohmayr wants to merge 2 commits into
mainfrom
fix/bigquery-arrow-schemaless-batch
Open

ohmayr wants to merge 2 commits into
mainfrom
fix/bigquery-arrow-schemaless-batch

Conversation

@ohmayr

@ohmayr ohmayr commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Context & Problem

createQueryArrowStream turned a record batch that arrived without a schema into an empty RecordBatch, silently dropping its rows. The skip has been on main since #9596, so this fixes it on its own, outside the Arrow stack.

Summary of Changes

Verification

  • New unit test for an inline jobs.query response with arrowRecordBatch but no arrowSchema; it fails without the fix.
  • pnpm test in handwritten/bigquery: 551 passing.
  • GIT_DIFF_ARG=origin/main node ./bin/linter.mjs --strict: no problems.

decodeArrowPayload returned an empty RecordBatch when a record batch
arrived without a schema, so its rows were silently dropped from
createQueryArrowStream results. Throw "Got an Arrow record batch before
its schema." instead, matching the Python client
(googleapis/google-cloud-python#18791).
@ohmayr
ohmayr requested review from a team as code owners October 20, 2026 23:41
@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the BigQuery API. label Oct 20, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request updates the decodeArrowPayload function to throw an error if an Arrow record batch is received without its schema, preventing rows from being silently dropped, and adds a corresponding test case. The review feedback recommends checking that serializedRecordBatch is present and has a length greater than 0 to ensure consistent truthiness handling between empty strings and empty Uint8Arrays.

Comment thread handwritten/bigquery/src/arrow.ts Outdated
Comment on lines +148 to +150
if (serializedRecordBatch) {
throw new Error('Got an Arrow record batch before its schema.');
}

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

Checking serializedRecordBatch directly for truthiness can lead to inconsistent behavior because an empty string ("") is falsy, whereas an empty Uint8Array (new Uint8Array(0)) is truthy. To ensure consistent handling of empty payloads, check that serializedRecordBatch is both present and has a length greater than 0.

Suggested change
if (serializedRecordBatch) {
throw new Error('Got an Arrow record batch before its schema.');
}
if (serializedRecordBatch && serializedRecordBatch.length > 0) {
throw new Error('Got an Arrow record batch before its schema.');
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in 8f1679a. An empty payload has no rows to drop, so it now takes the same path as a missing one for both string and Uint8Array, matching Python's if batch_bytes:. Added a test for an empty Uint8Array without a schema.

@ohmayr
ohmayr requested a review from shivanee-p October 20, 2026 23:45
An empty Uint8Array batch is truthy, so decodeArrowPayload raised
"before its schema" for a payload with no rows. Check its length, so
an empty string and an empty Uint8Array both count as no batch.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the BigQuery API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant