Skip to content

Conversation

codluca
Copy link
Member

@codluca codluca commented Oct 13, 2025

Add table procedures support for Lakehouse

Fixes #26754

Description

Iceberg module has several table procedures.
Hive and DeltaLake modules have only the "optimize" table procedure.
The code for the "optimize" table procedure is identical in all 3 modules.
So, the code from Iceberg module is used.

We could redeclare the table procedure in the Lakehouse module, or maybe there could be a refactoring so that the identical code for the "optimize" table procedure is placed in a common place and reused from there.

Additional context and related issues

Release notes

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

## Section
* Fix some things. ({issue}`26754`)

Summary by Sourcery

Introduce support for Iceberg-style table procedures in the Lakehouse connector by registering and exposing procedure metadata, and add smoke tests validating these procedures in Iceberg, Hive, and Delta modules.

New Features:

  • Expose Iceberg table procedures in the Lakehouse connector
  • Support procedures: optimize, optimize_manifests, drop_extended_stats, rollback_to_snapshot, expire_snapshots, remove_orphan_files, add_files, and add_files_from_table

Enhancements:

  • Register TableProcedureMetadata bindings in LakehouseModule
  • Implement getTableProcedures in LakehouseConnector
  • Enable add-files procedure via iceberg.add-files-procedure.enabled property in smoke tests

Tests:

  • Add smoke tests for table procedures in Lakehouse Iceberg connector covering various procedure operations
  • Add smoke tests for optimize procedure in Hive connector including session property enforcement
  • Add smoke test for optimize procedure in Delta connector
  • Add tests verifying failure scenarios for add_files and add_files_from_table procedures

Iceberg module has several table procedure.
Hive and DeltaLake modules have only the "optimize" table procedure.
The code for the "optimize" table procedure is identical in all 3 modules.
So, the code from Iceberg module is used.
We could redeclare the table procedure in the Lakehouse module, or maybe there could be a refactoring so that the identical code for the "optimize" table procedure is placed in a common place and reused from there.
@cla-bot cla-bot bot added the cla-signed label Oct 13, 2025
Copy link

sourcery-ai bot commented Oct 13, 2025

Reviewer's Guide

This PR integrates Iceberg’s table procedures into the Lakehouse connector by registering all procedure providers via a Guice Multibinder, injecting them into the connector, and exposing them through a new getTableProcedures API, along with enabling and testing the optimize procedure across Iceberg, Hive, and Delta Lake modules.

Class diagram for LakehouseConnector with table procedures support

classDiagram
class LakehouseConnector {
  - LakehouseLifeCycleManager lifeCycleManager
  - LakehouseTransactionManager transactionManager
  - LakehouseMetadataFactory metadataFactory
  - LakehouseSplitManager splitManager
  - LakehouseNodePartitioningProvider nodePartitioningProvider
  - LakehouseSessionProperties sessionProperties
  - LakehouseTableProperties tableProperties
  - IcebergMaterializedViewProperties materializedViewProperties
  - Set<TableProcedureMetadata> tableProcedures
  + getTableProcedures() Set<TableProcedureMetadata>
}

class TableProcedureMetadata

LakehouseConnector --> "*" TableProcedureMetadata
Loading

Class diagram for LakehouseModule table procedure bindings

classDiagram
class LakehouseModule {
  + setup(Binder binder)
}
class TableProcedureMetadata
class OptimizeTableProcedure
class OptimizeManifestsTableProcedure
class DropExtendedStatsTableProcedure
class RollbackToSnapshotTableProcedure
class ExpireSnapshotsTableProcedure
class RemoveOrphanFilesTableProcedure
class AddFilesTableProcedure
class AddFilesTableFromTableProcedure

LakehouseModule --> TableProcedureMetadata
TableProcedureMetadata <|-- OptimizeTableProcedure
TableProcedureMetadata <|-- OptimizeManifestsTableProcedure
TableProcedureMetadata <|-- DropExtendedStatsTableProcedure
TableProcedureMetadata <|-- RollbackToSnapshotTableProcedure
TableProcedureMetadata <|-- ExpireSnapshotsTableProcedure
TableProcedureMetadata <|-- RemoveOrphanFilesTableProcedure
TableProcedureMetadata <|-- AddFilesTableProcedure
TableProcedureMetadata <|-- AddFilesTableFromTableProcedure
Loading

File-Level Changes

Change Details Files
Register and expose table procedures in Lakehouse connector
  • Add tableProcedures field and constructor parameter in LakehouseConnector
  • Implement getTableProcedures() to return injected procedures
  • Bind each TableProcedureMetadata provider in LakehouseModule via Multibinder
plugin/trino-lakehouse/src/main/java/io/trino/plugin/lakehouse/LakehouseConnector.java
plugin/trino-lakehouse/src/main/java/io/trino/plugin/lakehouse/LakehouseModule.java
Enable new add-files procedure by default in test harness
  • Set iceberg.add-files-procedure.enabled session property to true in BaseLakehouseConnectorSmokeTest
plugin/trino-lakehouse/src/test/java/io/trino/plugin/lakehouse/BaseLakehouseConnectorSmokeTest.java
Add optimize procedure tests for all Lakehouse table types
  • Implement testOptimize in Iceberg, including multiple sub-procedures and failure cases
  • Implement testOptimize in Hive, with session property toggle
  • Implement testOptimize in DeltaLake
plugin/trino-lakehouse/src/test/java/io/trino/plugin/lakehouse/TestLakehouseIcebergConnectorSmokeTest.java
plugin/trino-lakehouse/src/test/java/io/trino/plugin/lakehouse/TestLakehouseHiveConnectorSmokeTest.java
plugin/trino-lakehouse/src/test/java/io/trino/plugin/lakehouse/TestLakehouseDeltaConnectorSmokeTest.java

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

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-lakehouse/src/main/java/io/trino/plugin/lakehouse/LakehouseConnector.java:156-158` </location>
<code_context>
     }

+    @Override
+    public Set<TableProcedureMetadata> getTableProcedures()
+    {
+        return tableProcedures;
+    }
+
</code_context>

<issue_to_address>
**suggestion:** Returning internal Set directly may expose mutability.

Return an unmodifiable view of tableProcedures to safeguard internal state from external changes.

Suggested implementation:

```java
+    @Override
+    public Set<TableProcedureMetadata> getTableProcedures()
+    {
+        return Collections.unmodifiableSet(tableProcedures);
+    }
+

```

```java
import java.util.Set;
import java.util.Collections;

```
</issue_to_address>

### Comment 2
<location> `plugin/trino-lakehouse/src/test/java/io/trino/plugin/lakehouse/TestLakehouseIcebergConnectorSmokeTest.java:49-50` </location>
<code_context>
                 )\\E""");
     }
+
+    @Test
+    public void testOptimize()
+    {
+        String tableName = "test_optimize_" + randomNameSuffix();
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding tests for invalid procedure arguments and permissions.

Please add tests for invalid argument types, missing required arguments, and permission failures to improve error handling and security coverage.
</issue_to_address>

### Comment 3
<location> `plugin/trino-lakehouse/src/test/java/io/trino/plugin/lakehouse/TestLakehouseHiveConnectorSmokeTest.java:72-73` </location>
<code_context>
                 )\\E""");
     }
+
+    @Test
+    public void testOptimize()
+    {
+        String tableName = "test_optimize_" + randomNameSuffix();
</code_context>

<issue_to_address>
**suggestion (testing):** Add test for optimize procedure with invalid session property value.

Please add a test case for an invalid session property value to verify the connector's handling of unexpected input.
</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.

Comment on lines +156 to +158
public Set<TableProcedureMetadata> getTableProcedures()
{
return tableProcedures;
Copy link

Choose a reason for hiding this comment

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

suggestion: Returning internal Set directly may expose mutability.

Return an unmodifiable view of tableProcedures to safeguard internal state from external changes.

Suggested implementation:

+    @Override
+    public Set<TableProcedureMetadata> getTableProcedures()
+    {
+        return Collections.unmodifiableSet(tableProcedures);
+    }
+
import java.util.Set;
import java.util.Collections;

Comment on lines +72 to +73
@Test
public void testOptimize()
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Add test for optimize procedure with invalid session property value.

Please add a test case for an invalid session property value to verify the connector's handling of unexpected input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Lakehouse connector doesn't support table procedures

1 participant