rdblue commented on a change in pull request #207: Add external schema mappings 
for files written with name-based schemas #40
URL: https://github.com/apache/incubator-iceberg/pull/207#discussion_r331299559
 
 

 ##########
 File path: core/src/main/java/org/apache/iceberg/avro/PruneColumns.java
 ##########
 @@ -100,36 +116,48 @@ public Schema union(Schema union, List<Schema> options) {
   }
 
   @Override
+  @SuppressWarnings("checkstyle:CyclomaticComplexity")
   public Schema array(Schema array, Schema element) {
-    if (array.getLogicalType() instanceof LogicalMap) {
+    if (array.getLogicalType() instanceof LogicalMap || 
AvroSchemaUtil.isKeyValueSchema(array.getElementType())) {
       Schema keyValue = array.getElementType();
-      int keyId = AvroSchemaUtil.getFieldId(keyValue.getField("key"));
-      int valueId = AvroSchemaUtil.getFieldId(keyValue.getField("value"));
+      Integer keyId = fieldId(keyValue.getField("key"));
+      Integer valueId = fieldId(keyValue.getField("value"));
+      if (keyId == null) {
+        if (valueId != null) {
+          LOG.warn("Map schema {} has value id but not key id", array);
+        }
+        return null;
+      }
 
       // if either key or value is selected, the whole map must be projected
       if (selectedIds.contains(keyId) || selectedIds.contains(valueId)) {
-        return array;
+        return complexMapWithIds(array, keyId, valueId);
       } else if (element != null) {
-        if (keyValue.getField("value").schema() != 
element.getField("value").schema()) {
+        if (keyValue.getField("key").schema() != 
element.getField("key").schema() ||
+            keyValue.getField("value").schema() != 
element.getField("value").schema()) {
 
 Review comment:
   Because the key is always fully projected, this doesn't need to check the 
key for changes.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to