Skip to content

Fix Storage Read Avro schema names and NULL values - #531

Closed
alejandrohdezma wants to merge 2 commits into
goccy:mainfrom
alejandrohdezma:fix/storage-read-avro
Closed

alejandrohdezma wants to merge 2 commits into
goccy:mainfrom
alejandrohdezma:fix/storage-read-avro

Conversation

@alejandrohdezma

Copy link
Copy Markdown

💻 How to review this PR?

This PR was created with the idea of being reviewed commit by commit. Each commit contains an incremental change that makes it easier to review. Also some of the commits contain additional information in their description to help understand why the change was made.

I also recommend checking "Hide whitespace" when reviewing this PR!

🚀 What's included in this PR?

  • Name the Avro record of a read session __root__ with no namespace, as BigQuery does. The schema used the table's project and dataset IDs as its namespace and the table ID as its name. Those can hold characters that Avro names do not allow (hyphens, a leading digit), so reading the table failed, and so did reading a query's anonymous result table, whose random ID can start with a digit.
  • Encode a NULL in a nullable field as nil, the null branch of its union, instead of {"<type>": nil}.

Fixes #252

TestStorageReadAVROMatchesBigQuery reads a table in project test-project and dataset my-dataset with a NULL in a nullable column, and a query's result table, and checks the schema name and the decoded rows. The fixes were also checked with the Java client (google-cloud-bigquerystorage), through a Scala test suite that reads query results with the Storage Read API: it fails on v0.8.1 and passes with this branch.

Notes

  • go test ./test/e2e/... fails for the Ruby client on this branch and on main (cb8555b) with ArgumentError: wrong number of arguments (given 2, expected 1) in every case. gems.txt pins only google-cloud-bigquery, so its dependencies resolve to newer versions on each build.
  • docker build fails on main: golang:bookworm is now Go 1.27, and grpc v1.81.1 uses http2.TrailerPrefix, which x/net v0.54.0 leaves out under Go 1.27. I'll open a separate PR that pins the Go version.

The Avro schema of a read session used the table's project and dataset IDs
as its namespace and the table ID as its name. Those IDs can hold
characters that Avro names do not allow, such as hyphens or a leading
digit, so the emulator failed to build its own codec and reading the table
failed. A query's anonymous result table has a random ID that can start
with a digit, so reading query results failed too.

BigQuery names the record __root__ and gives it no namespace, so the
emulator does the same. The namespace is left out of the JSON schema when
empty, as in BigQuery's read session schemas.

TestStorageReadAVROMatchesBigQuery reads a table in a project and dataset
whose IDs have hyphens, and a query's result table, and checks the schema
name and the decoded rows.
A NULL in a nullable field was encoded as a map keyed by the field's
type, such as {"string": nil}. goavro reads that map as the non-null
branch of the field's union, so encoding failed with "value does not
match its schema" and the read stream returned an error. goavro encodes
nil as the null branch.

TestStorageReadAVROMatchesBigQuery now has a NULL in its nullable
column.

Fixes #252
@alejandrohdezma
alejandrohdezma deleted the fix/storage-read-avro branch October 28, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Storage API Avro encoding does not work with nullable fields

1 participant