Skip to content

feat(view): add metadata JSON serialization - #1196

Open
kamcheungting-db wants to merge 3 commits into
apache:mainfrom
kamcheungting-db:feat/view-metadata-json
Open

kamcheungting-db wants to merge 3 commits into
apache:mainfrom
kamcheungting-db:feat/view-metadata-json

Conversation

@kamcheungting-db

@kamcheungting-db kamcheungting-db commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

View metadata can now be parsed from and serialized to Iceberg view format v1 JSON.

Builds on #1069, merged on 2026-12-01. Rebased onto origin/main at 11be7bd0; both follow-up patches are unchanged (git range-diff). Review the JSON and validation follow-up changes.

Changes

  • Add core serde for view representations, versions, history entries, and complete metadata, reusing the existing schema, namespace, integer, and string-map helpers.
  • Retain unknown representation payloads as a JSON object, including nested values, so serialization and property edits preserve them. Reject payloads that override the type discriminator.
  • Separate read/serialization validation from strict creation validation. Read checks enforce supported format, schema structure, unique IDs, non-null entries, and required JSON shapes/types. Existing metadata with missing references, duplicate SQL dialects, empty values, or invalid UUIDs can round trip and survive property edits; Validate() retains the strict creation checks, and accessors report missing references with kNotFound.
  • Add typed ViewProperties entries for history size (10), dialect removal (false), metadata compression (gzip), metadata path, and comment, using ConfigBase while preserving string-map storage and unknown keys.
  • Accept empty default namespaces and absent/null default catalogs, and canonicalize SQL discriminator variants to sql.
  • Reject integer literals outside INT64_MIN through UINT64_MAX in the string parser instead of silently rounding them. Require array-valued struct fields in the shared schema parser, including nested structs.

Example view metadata

This complete view format v1 document is the valid Rust fixture covered by the tests. current-version-id selects version 1, whose schema-id refers to schema 1. The SQL representation resolves events using the default catalog prod and namespace default.

{
  "view-uuid": "fa6506c3-7681-40c8-86dc-e36561f83385",
  "format-version": 1,
  "location": "s3://bucket/warehouse/default.db/event_agg",
  "current-version-id": 1,
  "properties": {
    "comment": "Daily event counts"
  },
  "versions": [
    {
      "version-id": 1,
      "timestamp-ms": 1573518431292,
      "schema-id": 1,
      "default-catalog": "prod",
      "default-namespace": [
        "default"
      ],
      "summary": {
        "engine-name": "Spark",
        "engineVersion": "3.3.2"
      },
      "representations": [
        {
          "type": "sql",
          "sql": "SELECT\n    COUNT(1), CAST(event_ts AS DATE)\nFROM events\nGROUP BY 2",
          "dialect": "spark"
        }
      ]
    }
  ],
  "schemas": [
    {
      "schema-id": 1,
      "type": "struct",
      "fields": [
        {
          "id": 1,
          "name": "event_count",
          "required": false,
          "type": "int",
          "doc": "Count of events"
        },
        {
          "id": 2,
          "name": "event_date",
          "required": false,
          "type": "date"
        }
      ]
    }
  ],
  "version-log": [
    {
      "timestamp-ms": 1573518431292,
      "version-id": 1
    }
  ]
}

Validation

CI restarted on 2026-12-01 for rebased head 49d5e3f3; all 15 checks are in progress. The local tests below were rerun successfully after rebasing onto 11be7bd0.

  • 79 view tests pass, including all 12 exact fixtures pinned from Java and Rust. The missing-reference and duplicate-dialect fixtures now assert successful parsing/round trips and strict validation failure, matching the Java parser behavior. Additional coverage checks deferred accessor errors, property edits of legacy metadata, schema structure, typed property defaults/overrides/errors, and string-map round trips.
  • 175 existing JSON serde tests, 580 schema tests, and the C++20 public-header compatibility executable pass.
  • The new integer-overflow and malformed-field regressions failed before the fixes and pass afterward; supported numeric boundaries, floating-point literals, and quoted numeric text still round trip through property edits.
  • Clang 18 Debug build with ASAN, UBSAN, and leak checks. The local libc++18 exception runtime requires ASAN_OPTIONS=detect_leaks=1:alloc_dealloc_mismatch=0; the default setting also reports the runtime mismatch in existing schema tests.
  • Pre-commit passes on the rebased branch. Changed-file clang-tidy passed before the rebase; git range-diff confirms both follow-up patches are unchanged.

Open review findings

A combined review of the foundation, this PR, and the local update/requirement implementation on 2026-12-01 reproduced the following issues. They remain unfixed at rebased head 49d5e3f3; passing existing tests does not cover these cases.

  • Schema defaults: ViewMetadata::Validate() currently skips SchemaField::Validate(). A NaN write-default is serialized as null and lost on reload; an integer field with string default "oops" serializes successfully but cannot reload. Add field-level validation on the creation/write path without reintroducing strict reference/dialect checks on reads.
  • SQL discriminator: metadata validation accepts UnknownViewRepresentation{.type = "ſql"}, while this PR's serializer reserves that tag as SQL and rejects it. Use one discriminator policy across metadata validation, update validation, and serde, with a cross-layer regression test.

The new update/requirement implementation remains local on feat/view-updates, based on the previous PR head 1f41d92c; it has been preserved separately from this rebase. Its separate review finding is a null-type dereference when comparing a rejected schema update with its clone; that fix belongs to the upcoming update/requirement PR.

The metadata builder, catalog APIs, and REST integration follow afterward.

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