Repository navigation
Decode base64 BYTES values instead of storing the text - #4
Merged
Merged
Conversation
The REST API carries BYTES as base64 text. normalizeData passed that text through unchanged, so the base64 characters themselves became the stored bytes and every BYTES value read back encoded twice (three times after a query wrote it to a destination table). Decode string values of BYTES fields, top-level and inside STRUCTs, in normalizeData, which serves insertAll, query destination tables and the Storage Write API (whose raw []byte values are left untouched). ARRAY<BYTES> elements already round-tripped correctly and are not changed. insertAll now normalizes row by row, so a value that does not fit its column, such as BYTES that are not base64, is reported as a per-row "invalid" insertError and the other rows still go in, as in BigQuery, instead of failing the whole request with a 500. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 3, 2026
Zeus26286
previously approved these changes
Nov 3, 2026
Zeus26286
left a comment
Owner
There was a problem hiding this comment.
Looks good. The decoding in normalizeData only applies to BYTES values that arrive as strings. I checked the other callers of NewTableWithSchema:
- Query results written to a destination table: their rows carry BYTES as base64 text, so decoding them is correct, and it fixes the triple encoding.
- Storage Write API: it decodes protobuf
BytesKindto[]byte, so it is unaffected. StructSource/YAML fixtures: they don't go through this path.
Rejecting a non-base64 value for its own row follows the existing pattern for unknown fields.
Verified locally: go vet ./... and go test ./... -count=1 pass with #1, #3, #4 and #2 merged together.
Non-blocking follow-ups:
base64.StdEncodingrejects unpadded and URL-safe input. That matches what the official clients send, but a lenient fallback might be friendlier.- insertAll still ignores
skipInvalidRows. In BigQuery, one invalid row fails the whole request unless that flag is set. This behaviour predates the PR. - As noted in the PR, load jobs weren't checked for the same bug.
Merge note: this conflicts trivially with #3 at the end of server/server_test.go. Keep both tests.
Generated by Claude Code
Resolve the conflict in server/server_test.go by keeping both TestIssue532SameTableNameInTwoDatasets (from #3) and TestIssue498BytesRoundTrip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019tgEtTxTsLWxmQawCfsQQa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes compatibility priority #2: BYTES values were base64-encoded twice (upstream goccy#498).
Problem
The REST API carries BYTES as base64 text.
normalizeDatapassed that text through unchanged, so the base64 characters themselves were stored as the bytes. InsertingAAECAw…therefore returnedQUFFQ0F3…, and after a query wrote the value to a destination table it came back encoded three times. Every BYTES value written throughinsertAllwas silently corrupted.Changes
types/types.go/server/handler.go:normalizeData. That function serves insertAll, query destination tables and the Storage Write API.[]bytevalues are left untouched.ARRAY<BYTES>elements already round-tripped correctly and are not changed.invalid, and the other rows still go in, as in BigQuery. Before, it failed the whole request with a 500.Tests
TestIssue498BytesRoundTrip.go vet ./...and the full unit suite pass.ArgumentError: wrong number of arguments (given 2, expected 1). This already happens onmain: a fresh image build picks up json 3.x, which multi_json can't call. Keep the table catalog in sync with DDL #1 fixes it.Follow-up
JSON/CSV load jobs store data by a different route and were not checked for the same bug.
Merging
This PR and #3 (same-name tables fix) both add their regression test at the same place at the end of
server/server_test.go. Whichever merges second needs a trivial conflict resolution that keeps both tests. Neither conflicts with #1.🤖 Generated with Claude Code