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_r333147885
##########
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:
Yes, we will need to make sure the key schema is structurally identical. You
can use `SchemaNormalization.parsingFingerprint64` for it.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]