Skip to content

SS-611 - storage: write jsonb strings as JSON in new Iceberg sinks - #41065

Draft
martykulma wants to merge 2 commits into
MaterializeInc:mainfrom
martykulma:maz-ss-611-iceberg-jsonb-string-fix
Draft

martykulma wants to merge 2 commits into
MaterializeInc:mainfrom
martykulma:maz-ss-611-iceberg-jsonb-string-fix

Conversation

@martykulma

@martykulma martykulma commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Iceberg sinks wrote a jsonb string scalar as its bare contents. '"hello"'::jsonb landed in the table as hello, which is not valid JSON, and '"123"'::jsonb was indistinguishable from the number 123. Objects, arrays and numbers were unaffected.

Approach

An existing sink cannot simply switch encoding. Its equality deletes (jsonb is an allowed key type) and its append-mode retractions are matched by value against rows already in the table, so a switch would leave deleted rows visible.

Sinks now record the release they were created on, in an internal CREATION VERSION option on CREATE SINK. The value is the integer release number that mz_version_num() reports. It is handled like VERSION. Purification stamps it on every new sink of any type, users cannot specify it, and SHOW CREATE SINK strips it. A sink without it predates the recording.

Behavior that depends on it goes through a named predicate on SinkCreationVersion. The one predicate here selects the jsonb string encoding for Iceberg sinks. Any recorded version gets JSON text, since the recording ships with the fix. Sinks without one keep writing bare strings.

No Iceberg table metadata is added or read. #41016 tried recording the encoding in the table, which ran into query engines that reject custom table properties and into snapshot expiry removing the marker.

Upgrade impact

None for existing sinks. They stay self-consistent and keep the old encoding. To get valid JSON for string scalars, drop the Iceberg table and recreate the sink.

Notes for the reviewer

  • New sinks show CREATION VERSION = <release number> in mz_sinks.create_sql, the same way VERSION shows up after an ALTER SINK.
  • The parser's expected-keyword list for sink options now ends in or CREATION.
  • The upgrade check hardcodes v26.53 as the first release with the fix. A backport needs that adjusted on the release branch.

Tests

Unit tests for both encodings, a parser test for the new option, testdrive coverage in the Iceberg suite, and a platform check that creates sinks on the base version and deletes and updates rows after the upgrade.

Release note

This release will fix Iceberg sinks writing jsonb string values without their JSON quotes and escapes. The fix applies to newly created sinks. Existing sinks keep their current output.

Closes: SS-611

🤖 Generated with Claude Code

martykulma and others added 2 commits November 24, 2026 15:45
Iceberg sinks wrote a jsonb string scalar as its bare contents, so
'"hello"'::jsonb landed as hello, which is not valid JSON.

Sinks now record the release they were created on in an internal
CREATION VERSION option. Iceberg sinks that carry it write JSON text.
Sinks that predate it keep the old encoding, because their equality
deletes and append-mode retractions are matched by value against rows
already in the table.

Closes: SS-611

Co-Authored-By: Claude <noreply@anthropic.com>
Uses the form of mz_version_num(), which drops the semver dependency
from mz-storage-types and mz-sql.

Co-Authored-By: Claude <noreply@anthropic.com>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant