Skip to content

Commit

Permalink
Derive name mapping from table schema when iceberg.id is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
weijiii committed Jan 24, 2025
1 parent 76d1e6f commit ef0d3db
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import org.apache.iceberg.io.InputFile;
import org.apache.iceberg.mapping.MappedField;
import org.apache.iceberg.mapping.MappedFields;
import org.apache.iceberg.mapping.MappingUtil;
import org.apache.iceberg.mapping.NameMapping;
import org.apache.iceberg.mapping.NameMappingParser;
import org.apache.iceberg.parquet.ParquetSchemaUtil;
Expand Down Expand Up @@ -499,6 +500,7 @@ private ReaderPageSourceWithRowPositions createDataPageSource(
inputFile,
start,
length,
fileSchema,
dataColumns,
predicate,
orcReaderOptions
Expand Down Expand Up @@ -582,6 +584,7 @@ private static ReaderPageSourceWithRowPositions createOrcPageSource(
TrinoInputFile inputFile,
long start,
long length,
Schema fileSchema,
List<IcebergColumnHandle> columns,
TupleDomain<IcebergColumnHandle> effectivePredicate,
OrcReaderOptions options,
Expand All @@ -598,6 +601,11 @@ private static ReaderPageSourceWithRowPositions createOrcPageSource(
.orElseThrow(() -> new TrinoException(ICEBERG_BAD_DATA, "ORC file is zero length"));

Map<Integer, OrcColumn> fileColumnsByIcebergId = fileColumnsByIcebergId(reader, nameMapping);
if (fileColumnsByIcebergId.isEmpty()) {
// When name mapping is not present in table metadata, and iceberg.id is not present in all file columns
// Try to recover by deriving name mapping from the table schema.
fileColumnsByIcebergId = fileColumnsByIcebergId(reader, Optional.of(MappingUtil.create(fileSchema)));
}

TupleDomainOrcPredicateBuilder predicateBuilder = TupleDomainOrcPredicate.builder()
.setBloomFiltersEnabled(options.isBloomFiltersEnabled());
Expand Down

0 comments on commit ef0d3db

Please sign in to comment.