diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java index a10d807fcd9f..e22834a756dd 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java @@ -970,6 +970,7 @@ public Optional finishRefreshMaterializedView( .map(handle -> (IcebergTableHandle) handle) .filter(handle -> handle.getSnapshotId().isPresent()) .map(handle -> handle.getSchemaTableName() + "=" + handle.getSnapshotId().get()) + .distinct() .collect(joining(",")); // Update the 'dependsOnTables' property that tracks tables on which the materialized view depends and the corresponding snapshot ids of the tables diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMaterializedViews.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMaterializedViews.java index 4934bfbecdba..5b9cab679b1b 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMaterializedViews.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMaterializedViews.java @@ -140,6 +140,20 @@ public void testCreateWithInvalidPropertyFails() .hasMessage("Catalog 'iceberg' does not support materialized view property 'invalid_property'"); } + @Test + public void testCreateWithDuplicateSourceTableSucceeds() + { + assertUpdate("" + + "CREATE MATERIALIZED VIEW materialized_view_with_duplicate_source AS " + + "SELECT _bigint, _date FROM base_table1 " + + "UNION ALL " + + "SELECT _bigint, _date FROM base_table1 "); + + assertUpdate("REFRESH MATERIALIZED VIEW materialized_view_with_duplicate_source", 12); + + assertQuery("SELECT count(*) FROM materialized_view_with_duplicate_source", "VALUES 12"); + } + @Test public void testShowCreate() {