wgtmac commented on code in PR #127:
URL: https://github.com/apache/iceberg-cpp/pull/127#discussion_r2203802271


##########
src/iceberg/avro/avro_schema_util.cc:
##########
@@ -783,4 +785,237 @@ Result<SchemaProjection> Project(const Schema& 
expected_schema,
   return SchemaProjection{std::move(field_projection.children)};
 }
 
+namespace {
+
+Result<::avro::NodePtr> CreateRecordNodeWithFieldIds(const ::avro::NodePtr& 
original_node,
+                                                     const MappedField& field) 
{
+  auto new_record_node = std::make_shared<::avro::NodeRecord>();
+  new_record_node->setName(original_node->name());
+
+  if (original_node->leaves() > original_node->names()) {
+    return InvalidSchema("Node has {} leaves but only {} names", 
original_node->leaves(),
+                         original_node->names());
+  }
+
+  for (size_t i = 0; i < original_node->leaves(); ++i) {
+    const std::string& field_name = original_node->nameAt(i);
+    ::avro::NodePtr field_node = original_node->leafAt(i);
+
+    // TODO(liuxiaoyu): Add support for case sensitivity in name matching.
+    // Try to find nested field by name
+    const MappedField* nested_field = nullptr;
+    if (field.nested_mapping) {
+      auto fields_span = field.nested_mapping->fields();
+      for (const auto& f : fields_span) {
+        if (f.names.find(field_name) != f.names.end()) {
+          nested_field = &f;
+          break;
+        }
+      }
+    }

Review Comment:
   ```suggestion
       const MappedField* nested_field = nullptr;
       auto field_id_opt = field.Id(field_name);
       if (field_id_opt.has_value()) {
          nested_field = &(field.Field(field_id_opt.value()).value().get());
       }
   ```
   
   This is not a required suggestion but I just found that the refactoring 
above does the same thing. Perhaps we should extend `MappedFields` by adding a 
new function to return a `std::optional<MappedFieldConstRef>` by finding a 
field name.



-- 
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]

Reply via email to