rdsr 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_r331375693
########## 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()) { // the value must be a projection return AvroSchemaUtil.createMap( - keyId, keyValue.getField("key").schema(), + keyId, element.getField("key").schema(), Review comment: On second thought, we'd have to use `element.getField("key").schema(),` as the key [if it is a complex type] could contain newly assigned field ids which the original key did not have. ---------------------------------------------------------------- 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