diff --git a/orc/src/main/java/org/apache/iceberg/orc/ORCSchemaUtil.java b/orc/src/main/java/org/apache/iceberg/orc/ORCSchemaUtil.java index 9c2de518da..580cc86134 100644 --- a/orc/src/main/java/org/apache/iceberg/orc/ORCSchemaUtil.java +++ b/orc/src/main/java/org/apache/iceberg/orc/ORCSchemaUtil.java @@ -255,11 +255,6 @@ public static Schema convert(TypeDescription orcSchema) { public static TypeDescription buildOrcProjection(Schema schema, TypeDescription originalOrcSchema) { Map icebergToOrc = icebergToOrcMapping("root", originalOrcSchema); - if (icebergToOrc.isEmpty()) { - // if no field ids are present in original schema then build mapping from expected schema - // this should ideally be handled at a higher layer with NameMapping - icebergToOrc = icebergToOrcMapping("root", convert(schema)); - } return buildOrcProjection(Integer.MIN_VALUE, schema.asStruct(), true, icebergToOrc); } diff --git a/orc/src/main/java/org/apache/iceberg/orc/OrcIterable.java b/orc/src/main/java/org/apache/iceberg/orc/OrcIterable.java index d036ed8b36..55737f2b50 100644 --- a/orc/src/main/java/org/apache/iceberg/orc/OrcIterable.java +++ b/orc/src/main/java/org/apache/iceberg/orc/OrcIterable.java @@ -87,15 +87,16 @@ public CloseableIterator iterator() { TypeDescription fileSchema = orcFileReader.getSchema(); final TypeDescription readOrcSchema; + final TypeDescription fileSchemaWithIds; if (ORCSchemaUtil.hasIds(fileSchema)) { - readOrcSchema = ORCSchemaUtil.buildOrcProjection(schema, fileSchema); + fileSchemaWithIds = fileSchema; } else { if (nameMapping == null) { nameMapping = MappingUtil.create(schema); } - TypeDescription typeWithIds = ORCSchemaUtil.applyNameMapping(fileSchema, nameMapping); - readOrcSchema = ORCSchemaUtil.buildOrcProjection(schema, typeWithIds); + fileSchemaWithIds = ORCSchemaUtil.applyNameMapping(fileSchema, nameMapping); } + readOrcSchema = ORCSchemaUtil.buildOrcProjection(schema, fileSchemaWithIds); SearchArgument sarg = null; if (filter != null) { @@ -125,10 +126,9 @@ public CloseableIterator iterator() { Schema extraFilterColumns = TypeUtil.select(rowFilter.requiredSchema(), filterColumnIdsNotInReadSchema); Schema finalReadSchema = TypeUtil.join(schema, extraFilterColumns); - TypeDescription finalReadOrcSchema = ORCSchemaUtil.buildOrcProjection(finalReadSchema, - orcFileReader.getSchema()); + TypeDescription finalReadOrcSchema = ORCSchemaUtil.buildOrcProjection(finalReadSchema, fileSchemaWithIds); TypeDescription rowFilterOrcSchema = ORCSchemaUtil.buildOrcProjection(rowFilter.requiredSchema(), - orcFileReader.getSchema()); + fileSchemaWithIds); RowFilterValueReader filterReader = new RowFilterValueReader(finalReadOrcSchema, rowFilterOrcSchema); return new OrcRowIterator<>(