Skip to content

Conversation

raunaqmorarka
Copy link
Member

@raunaqmorarka raunaqmorarka commented Oct 15, 2025

Description

It is possible for optimize_manifests to fail

{"type":"java.lang.NullPointerException","message":"Cannot invoke \"org.apache.iceberg.Snapshot.allManifests(org.apache.iceberg.io.FileIO)\" because \"snapshot\" is null","suppressed":[],"stack":["io.trino.plugin.iceberg.IcebergMetadata.loadAllManifestsFromSnapshot(IcebergMetadata.java:4183)","io.trino.plugin.iceberg.IcebergMetadata.executeOptimizeManifests

Additional context and related issues

Release notes

( ) 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.
(x) Release notes are required, with the following suggested text:

## Iceberg
* Fix failure in `optimize_manifests` for empty tables. ({issue}`26970`)

@cla-bot cla-bot bot added the cla-signed label Oct 15, 2025
Copy link

sourcery-ai bot commented Oct 15, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Add a null guard for snapshot in loadAllManifestsFromSnapshot to return an empty manifest list when snapshot is null, preventing NullPointerException during optimize_manifests on empty tables.

Sequence diagram for manifest loading with null snapshot guard

sequenceDiagram
participant "IcebergMetadata"
participant "Table"
participant "Snapshot"
participant "ManifestFile List"

"IcebergMetadata"->>"Snapshot": Check if snapshot is null
alt snapshot is null
    "IcebergMetadata"->>"ManifestFile List": Return empty list
else snapshot is not null
    "IcebergMetadata"->>"Table": Get FileIO
    "IcebergMetadata"->>"Snapshot": allManifests(FileIO)
    "Snapshot"-->>"IcebergMetadata": List<ManifestFile>
end
Loading

Class diagram for updated loadAllManifestsFromSnapshot null guard

classDiagram
class IcebergMetadata {
    +List<ManifestFile> loadAllManifestsFromSnapshot(Table icebergTable, Snapshot snapshot)
}
class Snapshot {
    +List<ManifestFile> allManifests(FileIO io)
}
class Table {
    +FileIO io()
}
IcebergMetadata --> Snapshot : uses
IcebergMetadata --> Table : uses
Snapshot --> ManifestFile : returns list
Table --> FileIO : returns

%% Highlight: loadAllManifestsFromSnapshot now returns ImmutableList.of() if snapshot is null
Loading

File-Level Changes

Change Details Files
Null-check snapshot in loadAllManifestsFromSnapshot to prevent NPE
  • Insert an early return when snapshot is null
  • Return an empty ImmutableList for null snapshots
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java

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 15, 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!


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.

Copy link
Contributor

@grantatspothero grantatspothero left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this.

@wendigo
Copy link
Contributor

wendigo commented Oct 15, 2025

Can we add a test?

@raunaqmorarka
Copy link
Member Author

Can we add a test?

We already have a test for an empty table in io.trino.plugin.iceberg.procedure.TestIcebergOptimizeManifestsProcedure#testEmptyManifest. However, CREATE through Trino always creates a snapshot, I couldn't find a straightforward way of simulating this scenario.

@wendigo wendigo merged commit 6f334b1 into trinodb:master Oct 15, 2025
44 checks passed
@github-actions github-actions bot added this to the 478 milestone Oct 15, 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.

3 participants