Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive name mapping from table schema when iceberg.id is missing #24795

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

weijiii
Copy link
Member

@weijiii weijiii commented Jan 24, 2025

Description

  • Currently when iceberg.id is present for any file columns including nested ones from the ORC data files, the name mapping from table metadata would be ignored. If the ORC data file is malformed where no iceberg.id is present, querying the table would incorrectly yield NULL for all columns from the data files. Name mapping can be derived from the table schema. If iceberg.id is present in the file columns, name mapping would not affect anything. If iceberg.id is missing in all file columns, the name mapping from table properties should be used to set the missing iceberg.id attributes. If name mapping is not configured in the table properties, one that is derived from table schema would be used as alternative.

Additional context and related issues

  • Iceberg does something similar for Avro tables when name mapping is not present [1]

Release notes

(v) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

@cla-bot cla-bot bot added the cla-signed label Jan 24, 2025
@github-actions github-actions bot added the iceberg Iceberg connector label Jan 24, 2025
@weijiii weijiii force-pushed the iceberg-orc-infer-name-mapping branch from ef0d3db to d5f34c2 Compare January 24, 2025 23:39
@@ -87,7 +87,7 @@ public static Metrics fileMetrics(TrinoInputFile file, MetricsConfig metricsConf
Footer footer = reader.get().getFooter();

// use name mapping to compute missing Iceberg field IDs
Optional<NameMapping> nameMapping = Optional.of(MappingUtil.create(schema));
NameMapping nameMapping = MappingUtil.create(schema);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I'm understanding correctly, we have two different codepaths that eventually land at fileColumnsByIcebergId. One from IcebergPageSourceProvider, and one here in OrcMetrics. Prior to this PR, the latter would use MappingUtil to derive the schema, but the former would only use the table properties. And in this PR, we are standardizing so that both codepaths use MappingUtil. Do I have that right?

I'm curious, doesn't this OrcMetrics codepath also need to handle the case where the name mapping is set as a JSON in the table properties? Like why aren't these codepaths completely unified in how they derive a NameMapping from the combination of ORC files / table metadata / table schema?

Copy link
Member Author

@weijiii weijiii Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC OrcMetrics::fileMetrics is only used when migrating table to Iceberg, therefore the Iceberg table metadata is not yet created as well as the table properties. Column Ids are expected to be missing in the ORC files so we are using the name mapping derived from table schema to fill the gap.

Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests.

@weijiii weijiii force-pushed the iceberg-orc-infer-name-mapping branch from d5f34c2 to d90decc Compare January 26, 2025 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed iceberg Iceberg connector
Development

Successfully merging this pull request may close these issues.

3 participants