diff --git a/docs/src/main/sphinx/connector/iceberg.rst b/docs/src/main/sphinx/connector/iceberg.rst index a0514d27f95c..e0f394b210de 100644 --- a/docs/src/main/sphinx/connector/iceberg.rst +++ b/docs/src/main/sphinx/connector/iceberg.rst @@ -1019,11 +1019,5 @@ view is queried, the snapshot-ids are used to check if the data in the storage table is up to date. If the data is outdated, the materialized view behaves like a normal view, and the data is queried directly from the base tables. -.. warning:: - - There is a small time window between the commit of the delete and insert, - when the materialized view is empty. If the commit operation for the insert - fails, the materialized view remains empty. - Dropping a materialized view with :doc:`/sql/drop-materialized-view` removes the definition and the storage table. 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 27d6606a839a..a55cde2990a6 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 @@ -2119,12 +2119,14 @@ public Optional finishRefreshMaterializedView( Collection computedStatistics, List sourceTableHandles) { - // delete before insert .. simulating overwrite - executeDelete(session, tableHandle); - IcebergWritableTableHandle table = (IcebergWritableTableHandle) insertHandle; Table icebergTable = transaction.table(); + // delete before insert .. simulating overwrite + transaction.newDelete() + .deleteFromRowFilter(Expressions.alwaysTrue()) + .commit(); + List commitTasks = fragments.stream() .map(slice -> commitTaskCodec.fromJson(slice.getBytes())) .collect(toImmutableList()); diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java index 822af432d103..b501cc2caa69 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java @@ -194,8 +194,8 @@ public void testRefreshMaterializedView() assertMetastoreInvocations("REFRESH MATERIALIZED VIEW test_refresh_mview_view", ImmutableMultiset.builder() - .addCopies(GET_TABLE, 9) - .addCopies(REPLACE_TABLE, 2) + .addCopies(GET_TABLE, 6) + .addCopies(REPLACE_TABLE, 1) .build()); }