Use field name for Parquet schema mismatch checking
@@ -32,6 +32,7 @@ import com.facebook.presto.spi.PrestoException;
import com.facebook.presto.spi.Subfield;
import com.facebook.presto.spi.predicate.Domain;
import com.facebook.presto.spi.predicate.TupleDomain;
+import com.facebook.presto.spi.type.RowType;
import com.facebook.presto.spi.type.StandardTypes;
import com.facebook.presto.spi.type.Type;
import com.facebook.presto.spi.type.TypeManager;
@@ -61,6 +62,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.HiveErrorCode.HIVE_BAD_DATA;
@@ -93,6 +95,7 @@ import static com.facebook.presto.spi.type.StandardTypes.TINYINT;
import static com.facebook.presto.spi.type.StandardTypes.VARBINARY;
import static com.facebook.presto.spi.type.StandardTypes.VARCHAR;
import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.nullToEmpty;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
@@ -315,8 +318,19 @@ public class ParquetPageSourceFactory
switch (prestoType) {
case ROW:
if (groupType.getFields().size() == type.getTypeParameters().size()) {
+ checkState(type instanceof RowType, "It must be a RowType here.");
+ RowType rowType = (RowType) type;
+ Map<String, Type> prestoFieldMap = rowType.getFields().stream().collect(
+ Collectors.toMap(
+ f -> f.getName().get(),
+ f -> f.getType()));
for (int i = 0; i < groupType.getFields().size(); i++) {
- if (!checkSchemaMatch(groupType.getFields().get(i), type.getTypeParameters().get(i))) {
+ org.apache.parquet.schema.Type parquetFieldType = groupType.getFields().get(i);
+ Type prestoFieldType = prestoFieldMap.get(parquetFieldType.getName());
+ if (prestoFieldType == null) {
+ prestoFieldType = prestoFieldMap.get(parquetFieldType.getName() + "_");
+ }
+ if (!checkSchemaMatch(parquetFieldType, prestoFieldType)) {
return false;
}
}
