rdblue commented on code in PR #12238:
URL: https://github.com/apache/iceberg/pull/12238#discussion_r1972624954


##########
core/src/main/java/org/apache/iceberg/avro/AvroCustomOrderSchemaVisitor.java:
##########
@@ -27,13 +27,20 @@
 import org.apache.iceberg.relocated.com.google.common.collect.Lists;
 
 abstract class AvroCustomOrderSchemaVisitor<T, F> {
+  private static final String METADATA = "metadata";
+
   public static <T, F> T visit(Schema schema, AvroCustomOrderSchemaVisitor<T, 
F> visitor) {
     switch (schema.getType()) {
       case RECORD:
         // check to make sure this hasn't been visited before
         String name = schema.getFullName();
         Preconditions.checkState(
             !visitor.recordLevels.contains(name), "Cannot process recursive 
Avro record %s", name);
+        Preconditions.checkArgument(

Review Comment:
   This check is fairly difficult to understand. When you have complicated 
logic like this, I'd recommend using a variable to make it more straightforward 
and readable:
   
   ```java
   boolean isMalformedVariant = schema.getLogicalType() instanceof 
VariantLogicalType && !AvroSchemaUtil.isVariantSchema(schema);
   Preconditions.checkArgument(!isMalformedVariant, ...);
   ```
   
   However, in this case I think the problem is the structure. I commented 
below that I think Variant behavior should match map and list behavior. Those 
don't call `field` (which is specific to structs in this visitor) and that 
means even less code is going to be shared with records.
   
   I think the best path forward is to handle the variant separately, rather 
than trying to share the code that visits fields. Then this Precondition can be 
back inside the block that validates whether the schema is a variant, which 
should be just after the `visitor.recordLevels.push(name);` line:
   
   ```java
   visitor.recordLevels.push(name);
   
   if (schema.getLogicalType() instanceof VariantLogicalType) {
     Preconditions.checkArgument(AvroSchemaUtil.isVariantSchema(schema), ...)
     T metadataResult = new VisitFuture<>(schema.getField(METADATA).schema(), 
visitor);
     T valueResult = new VisitFuture<>(schema.getField(VALUE).schema(), 
visitor);
     return visit(schema, metadataResult, valueResult);
   }
   ```



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to