Skip to content

Conversation

@ebyhr
Copy link
Member

@ebyhr ebyhr commented Oct 7, 2025

Description

Fixes #26863

Release notes

## Iceberg
* Fix incorrect results when reading Avro files migrated from Hive. ({issue}`26863`)

Summary by Sourcery

Fix partition key handling in Avro page source for migrated Iceberg files and extend migration tests to cover Avro and ORC formats

Bug Fixes:

  • Correct partition column resolution in the Avro page source by passing and applying explicit partition keys

Tests:

  • Parameterize TestIcebergMigrateProcedure to run partitioned table migration tests for AVRO and ORC and include file format in CREATE TABLE

@cla-bot cla-bot bot added the cla-signed label Oct 7, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 7, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR fixes incorrect results when reading migrated Iceberg Avro files by propagating partitionKeys into the Avro page source and updating partition column processing to deserialize correct values, and it extends the migration procedure tests to cover Avro format.

Sequence diagram for Avro page source creation with partitionKeys

sequenceDiagram
    participant Provider as IcebergPageSourceProvider
    participant PageSource as ReaderPageSourceWithRowPositions
    participant Column as IcebergColumnHandle
    Provider->>PageSource: createAvroPageSource(..., columns, partitionKeys)
    loop For each column in columns
        PageSource->>Column: getId()
        PageSource->>partitionKeys: containsKey(column.getId())
        alt partitionKeys contains column id
            PageSource->>Column: getType(), getName()
            PageSource->>PageSource: deserializePartitionValue(...)
            PageSource->>PageSource: nativeValueToBlock(...)
            PageSource->>PageSource: transforms.constantValue(...)
        else column.isPartitionColumn()
            PageSource->>PageSource: nativeValueToBlock(...)
            PageSource->>PageSource: transforms.constantValue(...)
        else column.isPathColumn()
            PageSource->>PageSource: transforms.constantValue(...)
        end
    end
Loading

Class diagram for updated Avro page source creation

classDiagram
    class IcebergPageSourceProvider {
        +createDataPageSource(...)
    }
    class ReaderPageSourceWithRowPositions
    class InputFile
    class NameMapping
    class IcebergColumnHandle {
        +getId()
        +getType()
        +getName()
        +isPartitionColumn()
        +isPathColumn()
    }
    IcebergPageSourceProvider --> ReaderPageSourceWithRowPositions : creates
    ReaderPageSourceWithRowPositions --> InputFile : uses
    ReaderPageSourceWithRowPositions --> NameMapping : uses
    ReaderPageSourceWithRowPositions --> IcebergColumnHandle : uses
    ReaderPageSourceWithRowPositions : -Map<Integer, Optional<String>> partitionKeys
    ReaderPageSourceWithRowPositions : +createAvroPageSource(..., List<IcebergColumnHandle> columns, Map<Integer, Optional<String>> partitionKeys)
    IcebergColumnHandle --> "partitionKeys : Map<Integer, Optional<String>>"
Loading

File-Level Changes

Change Details Files
Propagate partitionKeys and enhance Avro page source to correctly apply migrated partition values
  • Added partitionKeys argument to createDataPageSource invocation
  • Extended createAvroPageSource signature to accept partitionKeys
  • Replaced partition column logic to check partitionKeys map first and deserialize values, falling back to path-based partition fallback
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Extend migration procedure tests to include Avro format
  • Introduced a parameterized @test method to run migration tests for Parquet, ORC, and Avro
  • Updated testMigratePartitionedTable to accept IcebergFileFormat parameter
  • Added 'format' option to CREATE TABLE statements to specify file format
plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/procedure/TestIcebergMigrateProcedure.java

Assessment against linked issues

Issue Objective Addressed Explanation
#26863 Fix corruption of partition column data (becoming NULL) after migrating Avro-partitioned Hive tables to Iceberg using the migrate procedure.
#26863 Ensure that migrated Avro tables retain correct partition column values for all rows when queried in Iceberg.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added the iceberg Iceberg connector label Oct 7, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/procedure/TestIcebergMigrateProcedure.java:306-307` </location>
<code_context>
         String icebergTableName = "iceberg.tpch." + tableName;

-        assertUpdate("CREATE TABLE " + hiveTableName + " WITH (partitioned_by = ARRAY['part_col']) AS SELECT 1 id, 'part1' part_col", 1);
+        assertUpdate("CREATE TABLE " + hiveTableName + " WITH (format = '" + format + "', partitioned_by = ARRAY['part_col']) AS SELECT 1 id, 'part1' part_col", 1);
         assertQueryFails("SELECT * FROM " + icebergTableName, "Not an Iceberg table: .*");

</code_context>

<issue_to_address>
**suggestion (testing):** Suggestion to add assertions for correctness of migrated data, especially for partition columns.

Consider adding assertions to verify that partition column values are correctly migrated, ensuring the fix is fully validated.

```suggestion
        assertUpdate("CREATE TABLE " + hiveTableName + " WITH (format = '" + format + "', partitioned_by = ARRAY['part_col']) AS SELECT 1 id, 'part1' part_col", 1);
        assertQueryFails("SELECT * FROM " + icebergTableName, "Not an Iceberg table: .*");

        // Migrate the Hive table to Iceberg
        assertUpdate("CALL iceberg.system.migrate('" + hiveTableName + "')");

        // Assert that the migrated Iceberg table contains the correct partition column value
        assertQuery("SELECT part_col FROM " + icebergTableName, "VALUES 'part1'");
        // Optionally, assert the full row
        assertQuery("SELECT id, part_col FROM " + icebergTableName, "VALUES (1, 'part1')");
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ebyhr ebyhr merged commit 081877b into trinodb:master Oct 7, 2025
43 of 44 checks passed
@ebyhr ebyhr deleted the ebi/iceberg-avro branch October 7, 2025 21:07
@github-actions github-actions bot added this to the 478 milestone Oct 7, 2025
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.

Partition value becomes NULL after executing Iceberg migrate procedure with Avro format

2 participants