Skip to content

Decode base64 BYTES values instead of storing the text - #4

Merged
Zeus26286 merged 2 commits into
mainfrom
fix/issue-498-bytes-double-base64
Nov 3, 2026
Merged

Zeus26286 merged 2 commits into
mainfrom
fix/issue-498-bytes-double-base64

Conversation

@jackyyy2960

Copy link
Copy Markdown
Collaborator

Fixes compatibility priority #2: BYTES values were base64-encoded twice (upstream goccy#498).

Problem

The REST API carries BYTES as base64 text. normalizeData passed that text through unchanged, so the base64 characters themselves were stored as the bytes. Inserting AAECAw… therefore returned QUFFQ0F3…, and after a query wrote the value to a destination table it came back encoded three times. Every BYTES value written through insertAll was silently corrupted.

Changes

  • types/types.go / server/handler.go:
    • Decode string values of BYTES fields, top-level and inside STRUCTs, in normalizeData. That function serves insertAll, query destination tables and the Storage Write API.
    • The Storage Write API's raw []byte values are left untouched. ARRAY<BYTES> elements already round-tripped correctly and are not changed.
  • insertAll now normalizes row by row. A value that doesn't fit its column, such as BYTES that aren't valid base64, now rejects only its own row with reason invalid, and the other rows still go in, as in BigQuery. Before, it failed the whole request with a 500.

Tests

  • Regression test: TestIssue498BytesRoundTrip.
  • go vet ./... and the full unit suite pass.
  • e2e: 60/73 pass. All python, php, node, bq and java cases pass; the 13 failures are all Ruby cases.
    • The Ruby cases fail with ArgumentError: wrong number of arguments (given 2, expected 1). This already happens on main: 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

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>
Zeus26286
Zeus26286 previously approved these changes Nov 3, 2026

@Zeus26286 Zeus26286 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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 BytesKind to []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.StdEncoding rejects 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
@Zeus26286
Zeus26286 merged commit 97729fb into main Nov 3, 2026
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.

3 participants