Skip to content

Conversation

codluca
Copy link
Member

@codluca codluca commented Sep 27, 2025

Fix Create or replace Materialized view error
Fixes #25610

Description

The previous files for materialized views were not cleaned properly:

  • during view replace, the existing view was deleted after creating the new one, not before (this case caused the error from the #25610 issue),
  • during view drop, there was an attempt to delete the files twice (this case caused an error when dropping the materialized view).
  • some leftover metadata and data files remained after recreate

Now, when recreating the materialized view, we are always deleting the existing storage using the dropMaterializedViewStorage method at the beginning of the process.

The dropMaterializedViewStorage had an extra metastore.dropTable call, which caused the DROP error, as the metastore.dropTable call needed files that were deleted by the call before.

In dropMaterializedViewStorage we are making sure the table is cleared from the metastore.

Enabled some unit tests that were ignored before due to the existing issues.

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

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

@cla-bot cla-bot bot added the cla-signed label Sep 27, 2025
@github-actions github-actions bot added the iceberg Iceberg connector label Sep 27, 2025
@ebyhr ebyhr changed the title Fix Create or replace Materialized view error Fix Create or replace Materialized view error in Iceberg Sep 28, 2025
@codluca codluca force-pushed the 25610-create-or-replace-materialized-view branch 3 times, most recently from 63371bc to 1e0aef9 Compare September 28, 2025 11:11
The previous files for materialized views were not cleaned properly:
- during view replace, the existing view was deleted after creating the new one, not before (this case caused the error from the trinodb#25610 issue),
- during view drop, there was an attempt to delete the files twice (this case caused an error when dropping the materialized view).
- some leftover metadata and data files remained after recreate

Now, when recreating the materialized view, we are always deleting the existing storage using the dropMaterializedViewStorage method at the beginning of the process.

The dropMaterializedViewStorage had an extra metastore.dropTable call, which caused the DROP error, as the metastore.dropTable call needed files that were deleted by the call before.

In dropMaterializedViewStorage we are making sure the table is cleared from the metastore.

Enabled some unit tests that were ignored before due to the existing issues.
@chenjian2664
Copy link
Contributor

The issue looks like not invalidate the cache tableMetadataCache for mv properly, could you check if it works if we invalidate when replacing the mv?

@codluca
Copy link
Member Author

codluca commented Oct 1, 2025

Added invalidateTableCache call when deleting materialized view.
Indeed, in one scenario the tableMetadataCache was not invalidated.

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.

Create or replace Materialized view leads to an error in Iceberg
2 participants