Skip to content

Commit 2db4089

Browse files
authored
ORC: Support NameMapping with row-level filtering (#53)
1 parent bb40e42 commit 2db4089

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

orc/src/main/java/org/apache/iceberg/orc/ORCSchemaUtil.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,6 @@ public static Schema convert(TypeDescription orcSchema) {
255255
public static TypeDescription buildOrcProjection(Schema schema,
256256
TypeDescription originalOrcSchema) {
257257
Map<Integer, OrcField> icebergToOrc = icebergToOrcMapping("root", originalOrcSchema);
258-
if (icebergToOrc.isEmpty()) {
259-
// if no field ids are present in original schema then build mapping from expected schema
260-
// this should ideally be handled at a higher layer with NameMapping
261-
icebergToOrc = icebergToOrcMapping("root", convert(schema));
262-
}
263258
return buildOrcProjection(Integer.MIN_VALUE, schema.asStruct(), true, icebergToOrc);
264259
}
265260

orc/src/main/java/org/apache/iceberg/orc/OrcIterable.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,16 @@ public CloseableIterator<T> iterator() {
8787

8888
TypeDescription fileSchema = orcFileReader.getSchema();
8989
final TypeDescription readOrcSchema;
90+
final TypeDescription fileSchemaWithIds;
9091
if (ORCSchemaUtil.hasIds(fileSchema)) {
91-
readOrcSchema = ORCSchemaUtil.buildOrcProjection(schema, fileSchema);
92+
fileSchemaWithIds = fileSchema;
9293
} else {
9394
if (nameMapping == null) {
9495
nameMapping = MappingUtil.create(schema);
9596
}
96-
TypeDescription typeWithIds = ORCSchemaUtil.applyNameMapping(fileSchema, nameMapping);
97-
readOrcSchema = ORCSchemaUtil.buildOrcProjection(schema, typeWithIds);
97+
fileSchemaWithIds = ORCSchemaUtil.applyNameMapping(fileSchema, nameMapping);
9898
}
99+
readOrcSchema = ORCSchemaUtil.buildOrcProjection(schema, fileSchemaWithIds);
99100

100101
SearchArgument sarg = null;
101102
if (filter != null) {
@@ -125,10 +126,9 @@ public CloseableIterator<T> iterator() {
125126
Schema extraFilterColumns = TypeUtil.select(rowFilter.requiredSchema(), filterColumnIdsNotInReadSchema);
126127
Schema finalReadSchema = TypeUtil.join(schema, extraFilterColumns);
127128

128-
TypeDescription finalReadOrcSchema = ORCSchemaUtil.buildOrcProjection(finalReadSchema,
129-
orcFileReader.getSchema());
129+
TypeDescription finalReadOrcSchema = ORCSchemaUtil.buildOrcProjection(finalReadSchema, fileSchemaWithIds);
130130
TypeDescription rowFilterOrcSchema = ORCSchemaUtil.buildOrcProjection(rowFilter.requiredSchema(),
131-
orcFileReader.getSchema());
131+
fileSchemaWithIds);
132132
RowFilterValueReader filterReader = new RowFilterValueReader(finalReadOrcSchema, rowFilterOrcSchema);
133133

134134
return new OrcRowIterator<>(

0 commit comments

Comments
 (0)