WZhuo commented on code in PR #430:
URL: https://github.com/apache/iceberg-cpp/pull/430#discussion_r2642369245
##########
src/iceberg/util/type_util.cc:
##########
@@ -294,4 +305,87 @@ std::unordered_map<int32_t, int32_t> IndexParents(const
StructType& root_struct)
return id_to_parent;
}
+AssignFreshIdVisitor::AssignFreshIdVisitor(std::function<int32_t()> next_id)
+ : next_id_(std::move(next_id)) {}
+
+std::shared_ptr<Type> AssignFreshIdVisitor::Visit(
+ const std::shared_ptr<Type>& type) const {
+ switch (type->type_id()) {
+ case TypeId::kStruct:
+ return Visit(*internal::checked_pointer_cast<StructType>(type));
+ case TypeId::kMap:
+ return Visit(*internal::checked_pointer_cast<MapType>(type));
+ case TypeId::kList:
+ return Visit(*internal::checked_pointer_cast<ListType>(type));
+ default:
+ return type;
+ }
+}
+
+std::shared_ptr<StructType> AssignFreshIdVisitor::Visit(const StructType&
type) const {
+ auto fresh_ids = type.fields() |
Review Comment:
It has some misunderstandings about the id assigner. All the implementations
it mentioned, including Java, Python, and Rust, are consistent. The actual
implementation is: use pre-order traversal, and a field's ID is assigned when
its parent node is visited. This ensures that the IDs of the first-level child
nodes in a struct are consecutive.
--
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]