-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix(plugin-iceberg): Drop data table if the MV fails validation #26994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| package com.facebook.presto.iceberg; | ||
|
|
||
| import com.facebook.airlift.http.server.testing.TestingHttpServer; | ||
| import com.facebook.presto.Session; | ||
| import com.facebook.presto.testing.QueryRunner; | ||
| import com.facebook.presto.tests.AbstractTestQueryFramework; | ||
| import com.google.common.collect.ImmutableMap; | ||
|
|
@@ -98,7 +99,9 @@ protected QueryRunner createQueryRunner() | |
| .setDataDirectory(Optional.of(warehouseLocation.toPath())) | ||
| .setSchemaName("test_schema") | ||
| .setCreateTpchTables(false) | ||
| .setExtraProperties(ImmutableMap.of("experimental.legacy-materialized-views", "false")) | ||
| .setExtraProperties(ImmutableMap.of( | ||
| "experimental.legacy-materialized-views", "false", | ||
| "experimental.allow-legacy-materialized-views-toggle", "true")) | ||
| .build().getQueryRunner(); | ||
| } | ||
|
|
||
|
|
@@ -756,4 +759,44 @@ public void testStalenessPropertiesStoredInView() | |
| assertUpdate("DROP MATERIALIZED VIEW test_staleness_props_mv"); | ||
| assertUpdate("DROP TABLE test_staleness_props_base"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNoOrphanStorageTableOnValidationFailure() | ||
| throws Exception | ||
| { | ||
| try (RESTCatalog catalog = new RESTCatalog()) { | ||
| assertUpdate("CREATE TABLE test_orphan_base (id BIGINT, value BIGINT)"); | ||
| assertUpdate("INSERT INTO test_orphan_base VALUES (1, 100)", 1); | ||
|
|
||
| Session legacySession = Session.builder(getSession()) | ||
| .setSystemProperty("legacy_materialized_views", "true") | ||
|
Comment on lines
+763
to
+772
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Also assert that the materialized view itself is not registered after the failed creation Your test already checks that the storage table is removed at both the SQL layer and via the REST catalog. To strengthen coverage from a user perspective, add an assertion that no materialized view entry exists in metadata after the failure (e.g., via Suggested implementation: @Test
public void testNoOrphanStorageTableOnValidationFailure()
throws Exception
{
try (RESTCatalog catalog = new RESTCatalog()) {
assertUpdate("CREATE TABLE test_orphan_base (id BIGINT, value BIGINT)");
assertUpdate("INSERT INTO test_orphan_base VALUES (1, 100)", 1);
Session legacySession = Session.builder(getSession())
.setSystemProperty("legacy_materialized_views", "true")
.build();
// Ensure no stale materialized view metadata entry is registered after the failed creation.
// This verifies that both the storage table and the MV record are fully cleaned up.
assertQueryReturnsEmptyResult("SHOW MATERIALIZED VIEWS LIKE 'test_orphan_%'");This patch assumes:
|
||
| .build(); | ||
|
|
||
| String mvName = "test_orphan_mv"; | ||
| String storageTableName = "__mv_storage__" + mvName; | ||
|
Comment on lines
+775
to
+776
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick (testing): Clarify intent of hard-coded storage table naming to avoid future brittleness This test intentionally depends on the current storage table naming convention ( |
||
|
|
||
| assertQueryFails( | ||
| legacySession, | ||
| "CREATE MATERIALIZED VIEW " + mvName + " AS SELECT id, value FROM test_orphan_base", | ||
| ".*Materialized view security mode is required.*"); | ||
|
|
||
| assertQueryFails( | ||
| "SELECT COUNT(*) FROM \"" + storageTableName + "\"", | ||
| ".*(does not exist|not found).*"); | ||
|
|
||
| Map<String, String> catalogProps = new HashMap<>(); | ||
| catalogProps.put("uri", serverUri); | ||
| catalogProps.put("warehouse", warehouseLocation.getAbsolutePath()); | ||
| catalog.initialize("test_catalog", catalogProps); | ||
|
|
||
| TableIdentifier storageTableId = TableIdentifier.of(Namespace.of("test_schema"), storageTableName); | ||
| boolean tableExists = catalog.tableExists(storageTableId); | ||
| assertFalse(tableExists, | ||
| "Storage table should not exist after failed MV creation. " + | ||
| "This would indicate validation happened after storage table creation."); | ||
| } | ||
| finally { | ||
| assertUpdate("DROP TABLE test_orphan_base"); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.