Skip to content

Omit the Avro namespace from Storage Read API schemas - #508

Open
laughingman7743 wants to merge 1 commit into
goccy:mainfrom
laughingman7743:storage-read-avro-namespace
Open

Omit the Avro namespace from Storage Read API schemas#508
laughingman7743 wants to merge 1 commit into
goccy:mainfrom
laughingman7743:storage-read-avro-namespace

Conversation

@laughingman7743

Copy link
Copy Markdown

Fixes #221.

What

TableToAVRO built the schema's namespace from the project and dataset ids. A BigQuery project id
may contain a hyphen, which is not a legal character in an Avro name, so a read session against such
a project returned a schema no Avro client could parse — the failure landed in the client's schema
parser, before any row was decoded:

Record ought to have valid name: schema name ought to have second and remaining characters
contain only [A-Za-z0-9_]: test-project

The namespace is now omitted, which is also what BigQuery does: a real read session answers with
{"type":"record","name":"__root__","fields":[…]} and no namespace (checked against the service on
2026-08-09).

Why this is safe for the value encoder

AVROSchema.Namespace is read in one other place, (*TableCell).AVROValue, which passes it to
avroRecordUnionKey for a nullable RECORD field. That helper already returns the bare record name
when the namespace is empty — which is the union branch key goavro expects — so nullable STRUCT
columns keep working. TestStorageReadAVRO covers that path and still passes.

I left the record Name as the table id rather than also matching BigQuery's __root__, since that
is a separate behavioural change and not what breaks here; happy to add it if you would prefer the
closer match.

Test

TestIssue221ReadSessionSchemaParsesForHyphenatedProject loads a project named test-project,
creates a read session, parses the returned schema with goavro and then decodes the rows the
stream delivers. Reverting the change makes it fail with the message quoted above.

go test ./server ./types ./internal/... passes.

The schema a read session returns carried a namespace built from the
project and dataset ids. A BigQuery project id may contain a hyphen,
which is not a legal character in an Avro name, so every read against
such a project failed in the client's schema parser before a row was
decoded:

    Record ought to have valid name: schema name ought to have second
    and remaining characters contain only [A-Za-z0-9_]: test-project

BigQuery itself returns no namespace, so omitting it also brings the
emulator closer to the service. The value encoder already handled an
empty namespace: avroRecordUnionKey falls back to the bare record name,
which is the union branch key goavro expects.

Fixes goccy#221
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.

BigQuery Storage Read API schema error

1 participant