feat: implement UpdateMapping and apply meta change to UpdateSchema#561
feat: implement UpdateMapping and apply meta change to UpdateSchema#561zhjwpku wants to merge 2 commits intoapache:mainfrom
Conversation
src/iceberg/json_serde.cc
Outdated
| return NameMapping::Make(std::move(mapped_fields)); | ||
| } | ||
|
|
||
| std::optional<std::string> UpdateMappingFromJsonString( |
There was a problem hiding this comment.
This probably works but it seems the pattern in this file is to use Result() for *FromJson. It is also unclear what the intend of the method is, it seems from reading the code that we are trying to update the initial json representation with updates.
There was a problem hiding this comment.
Changed to the Result pattern.
wgtmac
left a comment
There was a problem hiding this comment.
Review Report: PR #561
📄 File: src/iceberg/name_mapping.cc
Java Counterpart: core/src/main/java/org/apache/iceberg/mapping/MappingUtil.java
- Parity Check: ✅ The
UpdateMappingVisitorlogically matches the JavaUpdateMappingvisitor. The logic handling additions and reassigned names perfectly mirrors the Java implementation (e.g.!field.field_id.has_value() || assign_it->second != field.field_id.value()corresponds correctly to Java's nullable integer checksassignedId != null && !Objects.equals(assignedId, field.id())). - Style Check:
⚠️ InUpdateMappingVisitor::VisitFields,std::ranges::for_eachis used with a lambda that mutatesupdate_assignments. Standard C++ algorithms are less idiomatic when they perform side-effects on captured external variables. A simple range-basedforloopfor (const auto& field : field_results)is cleaner and more readable here. - Logic Check: ✅ Handling of recursive nested structures with
std::unique_ptrand implicit conversion tostd::shared_ptris correct and safe. - Design & Conciseness: ✅
UpdateMappingVisitordoes a great job encapsulating the logic internally.std::erase_ifcorrectly translatesSets.differencefrom Java without reinventing the wheel.
📄 File: src/iceberg/json_serde.cc
Java Counterpart: api/src/main/java/org/apache/iceberg/mapping/NameMappingParser.java
- Parity Check: ✅
- Style Check:
⚠️ UpdateMappingFromJsonStringreturnsstd::optional<std::string>, which silently ignores JSON parsing or mapping errors. ReturningResult<std::string>would allow callers to log or trace errors if they occur, keeping consistent with the codebase'sResult<T>error handling pattern. - Logic Check: ✅
- Design & Conciseness: ✅ Consolidating mapping deserialization/serialization into
UpdateMappingFromJsonStringis a concise design that avoids leaking JSON boilerplate intoUpdateSchema.
📄 File: src/iceberg/update/update_schema.cc
Java Counterpart: core/src/main/java/org/apache/iceberg/SchemaUpdate.java
- Parity Check: ✅ In Java, updating the name mapping property is done inside
SchemaUpdate#commit()viaapplyChangesToMetadata(). In C++, embedding this property update insideUpdateSchema::Apply()and returning it withinupdated_propsis the correct equivalent pattern. - Style Check: ✅
- Logic Check: ✅
- Design & Conciseness: ✅
Summary & Recommendation
- Comment. The implementation is functionally sound, adheres tightly to Java parity, and cleanly introduces schema name mapping updates. Consider switching the
std::ranges::for_eachto aforloop inname_mapping.ccand returning aResult<std::string>instead ofstd::optionalinjson_serde.ccfor better error traceability, though neither are critical blockers. Excellent work!
467d908 to
08d3bac
Compare
Yeah, changed to simple for loop.
Changed to Resultstd::string
|
No description provided.