zhjwpku commented on code in PR #662:
URL: https://github.com/apache/iceberg-cpp/pull/662#discussion_r3335450138


##########
src/iceberg/avro/avro_writer.cc:
##########
@@ -81,6 +89,126 @@ Result<std::optional<int32_t>> ParseCodecLevel(const 
WriterProperties& propertie
   return level;
 }
 
+enum class FieldContext {
+  kTopLevel,
+  kStruct,
+  kListElement,
+  kMapKey,
+  kMapValue,
+};
+
+Result<std::optional<SchemaField>> PruneUnknownField(const SchemaField& field,
+                                                     FieldContext context) {
+  if (field.type()->type_id() == TypeId::kUnknown) {
+    ICEBERG_PRECHECK(context != FieldContext::kMapKey,
+                     "Cannot write map key '{}' of unknown type because it has 
no "
+                     "physical Avro representation",
+                     field.name());
+    ICEBERG_PRECHECK(field.optional(), "Unknown type field '{}' must be 
optional",
+                     field.name());
+    if (context == FieldContext::kListElement || context == 
FieldContext::kMapValue) {
+      return field;
+    }

Review Comment:
   This is different from the PruneUnknownField in parquet_writer.cc, is it 
intentional?



##########
src/iceberg/avro/avro_schema_util.cc:
##########
@@ -733,20 +764,9 @@ Result<FieldProjection> ProjectList(const ListType& 
list_type,
   }
 
   FieldProjection element_projection;
-  ::avro::NodePtr element_node;
-  ICEBERG_RETURN_UNEXPECTED(UnwrapUnion(avro_node->leafAt(0), &element_node));
-  if (expected_element_field.type()->is_nested()) {
-    ICEBERG_ASSIGN_OR_RAISE(
-        element_projection,
-        ProjectNested(*expected_element_field.type(), element_node, 
prune_source));
-  } else {
-    ICEBERG_RETURN_UNEXPECTED(
-        ValidateAvroSchemaEvolution(*expected_element_field.type(), 
element_node));
-  }
-
-  // Set the element projection metadata but preserve its children
-  element_projection.kind = FieldProjection::Kind::kProjected;
-  element_projection.from = size_t{0};
+  ICEBERG_ASSIGN_OR_RAISE(element_projection,
+                          ProjectField(expected_element_field, 
avro_node->leafAt(0),
+                                       size_t{0}, prune_source));

Review Comment:
   nit:
   ```suggestion
                                          /*source_index*/size_t{0}, 
prune_source));
   ```



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