Skip to content

feat(plugin-iceberg): Support rewrite_manifests procedure for iceberg#26888

Merged
agrawalreetika merged 1 commit intoprestodb:masterfrom
agrawalreetika:rewrite_manifests
Jan 6, 2026
Merged

feat(plugin-iceberg): Support rewrite_manifests procedure for iceberg#26888
agrawalreetika merged 1 commit intoprestodb:masterfrom
agrawalreetika:rewrite_manifests

Conversation

@agrawalreetika
Copy link
Copy Markdown
Member

@agrawalreetika agrawalreetika commented Jan 2, 2026

Description

Support rewrite_manifests procedure for iceberg

Motivation and Context

New procedure to rewrite the manifest files of an Iceberg table to optimize table metadata.

Impact

New procedure to rewrite the manifest files of an Iceberg table to optimize table metadata.

Test Plan

Added tests

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

Iceberg Connector Changes
* Add rewrite_manifests procedure for iceberg

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Jan 2, 2026
@prestodb-ci prestodb-ci requested review from a team, namya28 and sh-shamsan and removed request for a team January 2, 2026 07:13
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Jan 2, 2026

Reviewer's Guide

Adds a new Iceberg system procedure system.rewrite_manifests to rewrite manifest files for a table, wires it into the Iceberg module, introduces a dedicated error code for invalid spec IDs, and provides test coverage and (partial) docs updates.

Sequence diagram for executing system.rewrite_manifests procedure

sequenceDiagram
  actor User as User
  participant PrestoCoordinator as PrestoCoordinator
  participant IcebergConnector as IcebergConnector
  participant RewriteManifestsProcedure as RewriteManifestsProcedure
  participant IcebergMetadataFactory as IcebergMetadataFactory
  participant ConnectorMetadata as ConnectorMetadata
  participant IcebergTable as IcebergTable
  participant RewriteManifests as RewriteManifests

  User->>PrestoCoordinator: CALL system.rewrite_manifests(schema, table_name, spec_id)
  PrestoCoordinator->>IcebergConnector: resolve procedure rewrite_manifests
  IcebergConnector->>RewriteManifestsProcedure: invoke get()
  RewriteManifestsProcedure-->>IcebergConnector: Procedure instance
  IcebergConnector->>RewriteManifestsProcedure: rewriteManifests(session, schemaName, tableName, specId)

  activate RewriteManifestsProcedure
  RewriteManifestsProcedure->>IcebergMetadataFactory: create()
  IcebergMetadataFactory-->>RewriteManifestsProcedure: ConnectorMetadata
  RewriteManifestsProcedure->>ConnectorMetadata: getIcebergTable(session, schemaTableName)
  ConnectorMetadata-->>RewriteManifestsProcedure: IcebergTable
  RewriteManifestsProcedure->>IcebergTable: rewriteManifests()
  IcebergTable-->>RewriteManifestsProcedure: RewriteManifests

  alt specId is not null
    RewriteManifestsProcedure->>IcebergTable: specs()
    IcebergTable-->>RewriteManifestsProcedure: specs map
    alt specs map does not contain specId
      RewriteManifestsProcedure-->>IcebergConnector: throw PrestoException(ICEBERG_INVALID_SPEC_ID)
      IcebergConnector-->>PrestoCoordinator: error ICEBERG_INVALID_SPEC_ID
      PrestoCoordinator-->>User: failure response
    else specs map contains specId
      RewriteManifestsProcedure->>RewriteManifests: rewriteIf(manifest -> manifest.partitionSpecId() == specId)
      RewriteManifestsProcedure->>RewriteManifests: commit()
      RewriteManifests-->>RewriteManifestsProcedure: success
      RewriteManifestsProcedure-->>IcebergConnector: return
      IcebergConnector-->>PrestoCoordinator: success
      PrestoCoordinator-->>User: success response
    end
  else specId is null
    RewriteManifestsProcedure->>RewriteManifests: commit()
    RewriteManifests-->>RewriteManifestsProcedure: success
    RewriteManifestsProcedure-->>IcebergConnector: return
    IcebergConnector-->>PrestoCoordinator: success
    PrestoCoordinator-->>User: success response
  end

  deactivate RewriteManifestsProcedure
Loading

Class diagram for new RewriteManifestsProcedure and related types

classDiagram
  class RewriteManifestsProcedure {
    - IcebergMetadataFactory metadataFactory
    + RewriteManifestsProcedure(IcebergMetadataFactory metadataFactory)
    + Procedure get()
    + void rewriteManifests(ConnectorSession clientSession, String schemaName, String tableName, Integer specId)
  }

  class IcebergMetadataFactory {
    + ConnectorMetadata create()
  }

  class Procedure {
    + Procedure(String schemaName, String procedureName, List arguments, MethodHandle methodHandle)
  }

  class ConnectorSession
  class SchemaTableName {
    + SchemaTableName(String schemaName, String tableName)
  }

  class ConnectorMetadata

  class Table {
    + RewriteManifests rewriteManifests()
    + Map specs()
  }

  class RewriteManifests {
    + RewriteManifests rewriteIf(ManifestFileFilter manifestFileFilter)
    + void commit()
  }

  class IcebergErrorCode {
    <<enum>>
    ICEBERG_INVALID_SPEC_ID
  }

  class PrestoException {
    + PrestoException(IcebergErrorCode errorCode, String message)
  }

  RewriteManifestsProcedure --> IcebergMetadataFactory : uses
  RewriteManifestsProcedure ..> Procedure : provides
  RewriteManifestsProcedure ..> ConnectorSession : parameter
  RewriteManifestsProcedure ..> SchemaTableName : builds
  RewriteManifestsProcedure ..> ConnectorMetadata : uses
  RewriteManifestsProcedure ..> Table : obtains
  RewriteManifestsProcedure ..> RewriteManifests : configures
  RewriteManifestsProcedure ..> IcebergErrorCode : uses ICEBERG_INVALID_SPEC_ID
  RewriteManifestsProcedure ..> PrestoException : throws
Loading

File-Level Changes

Change Details Files
Introduce system.rewrite_manifests Iceberg procedure to rewrite manifest files, with optional spec_id filtering and proper classloader/metadata handling.
  • Implement RewriteManifestsProcedure as a Provider that exposes a rewrite_manifests(schema, table_name, spec_id) procedure in the system schema.
  • Use IcebergMetadataFactory and getIcebergTable to resolve the Iceberg Table from schema and table_name, under ThreadContextClassLoader.
  • Invoke Iceberg Table.rewriteManifests(), optionally validate spec_id against table specs and restrict manifests via rewriteIf, then commit the rewrite.
presto-iceberg/src/main/java/com/facebook/presto/iceberg/procedure/RewriteManifestsProcedure.java
Wire the new rewrite_manifests procedure into the Iceberg connector so it is registered and add a specific error code for invalid spec IDs.
  • Bind RewriteManifestsProcedure in IcebergCommonModule so it is registered as a connector procedure.
  • Add ICEBERG_INVALID_SPEC_ID error code for spec-id validation failures in the procedure.
presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergCommonModule.java
presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergErrorCode.java
Add tests for rewrite_manifests behavior and argument validation for the Iceberg connector procedure.
  • Create TestRewriteManifestsProcedure to exercise positional and named argument invocation of the procedure.
  • Test valid spec_id usage and ensure invalid spec_id fails with the expected error message and error code.
  • Verify idempotency, invalid argument combinations (types, missing required args, mixing named/positional), unregistered catalog, and non-existing table behavior.
  • Use IcebergQueryRunner with HADOOP catalog type to run end-to-end procedure tests and validate snapshot history changes.
presto-iceberg/src/test/java/com/facebook/presto/iceberg/procedure/TestRewriteManifestsProcedure.java
Update Iceberg connector documentation to mention support for rewrite_manifests procedure.
  • Extend Iceberg connector docs to list the new rewrite_manifests procedure in the release notes / feature description (exact content may need closer review in the full diff).
presto-docs/src/main/sphinx/connector/iceberg.rst

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

@agrawalreetika agrawalreetika changed the title feat(iceberg): Support rewrite_manifests procedure for iceberg feat(plugin-iceberg): Support rewrite_manifests procedure for iceberg Jan 2, 2026
Copy link
Copy Markdown
Contributor

@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 - I've found 1 issue, and left some high level feedback:

  • In TestRewriteManifestsProcedure, you're mixing TestNG (@Test) with JUnit's org.junit.Assert.assertEquals; for consistency with the rest of the Presto test suite and to avoid dependency mixing, consider switching to org.testng.Assert.assertEquals.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `TestRewriteManifestsProcedure`, you're mixing TestNG (`@Test`) with JUnit's `org.junit.Assert.assertEquals`; for consistency with the rest of the Presto test suite and to avoid dependency mixing, consider switching to `org.testng.Assert.assertEquals`.

## Individual Comments

### Comment 1
<location> `presto-iceberg/src/test/java/com/facebook/presto/iceberg/procedure/TestRewriteManifestsProcedure.java:40-43` </location>
<code_context>
+                .getQueryRunner();
+    }
+
+    private void createTable(String tableName)
+    {
+        assertUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (id INTEGER, value VARCHAR)");
+    }
+
</code_context>

<issue_to_address>
**suggestion (testing):** Avoid `CREATE TABLE IF NOT EXISTS` in tests to prevent masking leftover state from previous runs

In tests, `CREATE TABLE IF NOT EXISTS` can hide leftover tables from previous runs (e.g., when a test aborts before `DROP TABLE`). It’s better for tests to fail if the table already exists. Use a plain `CREATE TABLE` instead (optionally preceded by an explicit `DROP TABLE`), so leaked state and flakiness aren’t silently ignored.

```suggestion
    private void createTable(String tableName)
    {
        assertUpdate("DROP TABLE IF EXISTS " + tableName);
        assertUpdate("CREATE TABLE " + tableName + " (id INTEGER, value VARCHAR)");
    }
```
</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.

Copy link
Copy Markdown
Member

@hantangwangd hantangwangd left a comment

Choose a reason for hiding this comment

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

@agrawalreetika thanks for this feature. I've left some initial comments for your consideration.

@agrawalreetika
Copy link
Copy Markdown
Member Author

@agrawalreetika thanks for this feature. I've left some initial comments for your consideration.

@hantangwangd Thanks for your review & suggestions. I have applied the changes. Please take a look, when you get a chance.

@agrawalreetika agrawalreetika self-assigned this Jan 4, 2026
Copy link
Copy Markdown
Member

@hantangwangd hantangwangd left a comment

Choose a reason for hiding this comment

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

Looks good! Just one more comment on adding a test case.

Copy link
Copy Markdown
Member

@hantangwangd hantangwangd left a comment

Choose a reason for hiding this comment

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

Thanks @agrawalreetika, lgtm!

@agrawalreetika agrawalreetika merged commit 2ba4faf into prestodb:master Jan 6, 2026
111 of 113 checks passed
@agrawalreetika agrawalreetika deleted the rewrite_manifests branch January 6, 2026 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants