huaxingao opened a new pull request, #18633: URL: https://github.com/apache/iceberg/pull/18633
## Summary This is the first PR to implement table constraints from the v4 spec ([#17822](https://github.com/apache/iceberg/pull/17822)). It adds the constraint model and reads/writes constraints in table metadata and constraint statuses in snapshot metadata. It does not add any APIs to create or change constraints yet. ## Changes **API** - `Constraint` with `id()`, `name()`, `type()`, `enforced()`, and `timestampMillis()`. - Subtypes `CheckConstraint`, `KeyConstraint` (with `fieldIds()`), `UniqueConstraint`, and `PrimaryKeyConstraint`. - `ConstraintType` (`check`, `unique`, `primary-key`) and `ConstraintStatus` (`VALIDATED`, `VALID`, `INVALID`, `UNVALIDATED`). - `Snapshot.constraintStatuses()` returns a map from constraint ID to status. A constraint that is not in the map is `UNVALIDATED`. - `Table.constraints()` returns the current constraints. **Core** - `TableMetadata` stores `constraints` and `last-constraint-id`, and `TableMetadataParser` reads and writes them for v4 tables. - `SnapshotParser` reads and writes `constraint-statuses` as the four ID lists in the spec. - New `ConstraintParser` and `ConstraintStatusesParser`. - Validation: - Constraints are rejected before v4. - Constraint IDs and names must be unique. - IDs must not be greater than `last-constraint-id`. - A table can have at most one `primary-key` constraint. - A `check` constraint must have an `expression` and no `field-ids`; `unique` and `primary-key` must have non-empty `field-ids` with no duplicates and no `expression`. - A constraint ID can be in only one status list. - `RewriteTablePathUtil` keeps constraints and constraint statuses. ## Not in this PR - `CheckConstraint.expression()`. The expression must use ID references, which `ExpressionParser` doesn't support yet. It's added in [#17343](https://github.com/apache/iceberg/pull/17343). Until then, the expression JSON is kept as-is so it's not lost on read and write. I'll add `expression()` after #17343 is merged. - APIs to add, remove, or change constraints and to record statuses (`UpdateConstraints`, `UpdateConstraintStatuses`), plus schema checks for referenced fields. These will come in follow-up PRs. - Engine support, such as Spark DDL and check enforcement. ## Testing - New `TestConstraintParser` and `TestConstraintStatusesParser`. - Added round-trip and validation tests to `TestTableMetadata` and `TestSnapshotJson`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
