Skip to content

feat(view): add view metadata types and validation - #1069

Merged
wgtmac merged 6 commits into
apache:mainfrom
kamcheungting-db:feat/view-metadata-types
Dec 1, 2026
Merged

wgtmac merged 6 commits into
apache:mainfrom
kamcheungting-db:feat/view-metadata-types

Conversation

@kamcheungting-db

@kamcheungting-db kamcheungting-db commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Merged on 2026-12-01. JSON serialization and the read/write validation split follow in #1196.

What this PR does

Adds the Iceberg view format v1 metadata model under iceberg/view/: metadata, versions, history entries, SQL and unknown representation types, validation, and lookup helpers. Registers the sources, installed headers, tests, and C++20 compatibility includes.

ViewMetadata stores schemas and versions, the current version ID, history, UUID, location, format version, and properties. Versions carry SQL representations, a summary, and a resolution context. Types compare by value, and scalar members are default-initialized.

Validation and accessors

ViewMetadata::Validate() leaves metadata unchanged and returns kValidationFailed for the first violated invariant:

  • Format version must be 1, the UUID must parse with Uuid::FromString, and location must be non-empty.
  • Schema and version lists must be non-empty, contain no null entries, and have unique IDs. Schema field IDs and names must also be unique recursively, and required unknown fields are rejected. View schemas may use types introduced in later table format versions.
  • The current version, each version's schema, and every history entry must reference listed IDs.
  • Empty default namespaces are accepted. SQL text and dialect must be non-empty; dialects must be unique after Unicode simple lowercasing with the existing StringUtils::ToLower, including Éngine / éngine.
  • Unknown representation type identifiers must be non-empty and cannot use SQL discriminator variants such as sql, SQL, or SqL.

CurrentVersion(), VersionById(), CurrentSchema(), and SchemaById() return the matching entry or kNotFound. The borrowing helpers GetSql() and RepresentationType() reject temporary variants, including implicit conversions from named alternatives.

Tests

view_metadata_test contains 37 GoogleTest cases, plus compile-time assertions for borrowing-helper lifetimes. Coverage includes malformed and uppercase UUIDs, scalar defaults, top-level and nested duplicate field IDs, schema/version/history references, rollback history, empty default namespaces, ASCII and Unicode dialect duplicates, reserved SQL tags, lookup failures, equality, and representation helpers.

All 15 CI checks passed before merge, including ASAN/UBSAN, cpp-linter, pre-commit, and Linux/macOS/Windows builds.

Follow-ups

Metadata JSON serialization, unknown representation payload preservation, the read/write validation split, and typed ViewProperties are implemented in #1196. View update/requirement types are implemented locally on feat/view-updates and have not been published. The metadata builder, view/catalog APIs, and REST integration follow afterward.

A combined stack review on 2026-12-01 reproduced two issues shared with the follow-up work: schema validation skips field-default checks, and the metadata validator and JSON serializer disagree on the ſql discriminator. These findings remain open; #1196 tracks the follow-up details.

Comment thread src/iceberg/view/view_metadata.cc Resolved
@kamcheungting-db

Copy link
Copy Markdown
Contributor Author

@shangxinli @wgtmac

Could you help me review this first PR of view?

Comment thread src/iceberg/view/view_version.h Resolved
Comment thread src/iceberg/view_metadata.h Resolved
Comment thread src/iceberg/view_metadata.cc Resolved
Comment thread src/iceberg/view/view_metadata.cc Resolved
Comment thread src/iceberg/view/view_metadata.cc Resolved
Comment thread src/iceberg/view_metadata.cc Resolved
Comment thread src/iceberg/view_metadata.cc Resolved
Comment thread src/iceberg/CMakeLists.txt Resolved
Comment thread src/iceberg/type_fwd.h Resolved
kamcheungting-db and others added 5 commits November 29, 2026 21:30
Deliver the view format v1 metadata model beside its table equivalent:

- ViewVersion carries version-id, schema-id, timestamp-ms, summary,
  representations, optional default catalog, and required default namespace.
- Representations are SQL (sql, dialect) or opaque unknown types preserved
  for round trips, modeled as a variant with GetSql and RepresentationType
  helpers.
- ViewMetadata carries view-uuid, format-version, location, schemas,
  current-version-id, versions, version-log, and properties, with
  CurrentVersion/VersionById/CurrentSchema/SchemaById accessors returning
  NotFound for missing entries.
- Validate() checks view-v1 invariants without applying table-format schema
  restrictions: supported format version, non-empty UUID/location, listed
  schemas/versions with unique IDs, current-version and schema references,
  non-empty default namespaces, non-empty SQL representations with at most
  one per dialect under ASCII case folding, and non-empty unknown
  representation types.
- Add StringUtils::EqualsIgnoreCaseAscii for the ASCII-only dialect folding;
  existing Unicode-aware EqualsIgnoreCase is unchanged.
- view_metadata_test validates synthetic metadata: every invariant violated
  one at a time with asserted error kinds, accepted shapes including unknown
  representations, accessor NotFound behavior, and equality.
…ation

- Move view metadata and version sources and headers into a view
  subdirectory with its own type_fwd.h.
- Reject temporary variants in GetSql and RepresentationType.
- Default-initialize scalar members of view metadata, versions, and
  history entries.
- Accept an empty default namespace, as Java writes it.
- Reject duplicate field IDs in view schemas.
- Reserve the SQL representation type for SQL representations,
  including Java's case-insensitive variants.
- Validate view UUIDs with the UUID parser.
- Normalize SQL dialects with Unicode case folding before checking
  for duplicates.

Co-authored-by: Isaac <[email protected]>
Reject missing field types, duplicate field paths, and required unknown fields.
Accept ſql as an unknown representation and report invalid view metadata
with kValidationFailed.

@wgtmac wgtmac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the quick update! Two questions for follow-up:

  1. Should ViewMetadata::Validate() use the same rules for reading existing metadata and for writing new metadata? It currently rejects some inputs that Java can read. Before wiring it into JSON deserialization, could we decide which checks belong on the read path?
  2. Once the view builder starts consuming properties like version.history.num-entries, could we extract a ViewProperties type to keep the property keys and defaults together, following TableProperties?

@wgtmac
wgtmac merged commit 11be7bd into apache:main Dec 1, 2026
15 checks passed
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