Skip to content

Commit

Permalink
Fail rename materialized view across schema in iceberg
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-stec authored and sopel39 committed Oct 12, 2021
1 parent 7aa4e8d commit 51279b7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,10 @@ public Optional<ConnectorMaterializedViewDefinition> getMaterializedView(Connect
@Override
public void renameMaterializedView(ConnectorSession session, SchemaTableName source, SchemaTableName target)
{
// TODO (https://github.com/trinodb/trino/issues/9594) support rename across schemas
if (!source.getSchemaName().equals(target.getSchemaName())) {
throw new TrinoException(NOT_SUPPORTED, "Materialized View rename across schemas is not supported");
}
catalog.renameMaterializedView(session, source, target);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_CREATE_MATERIALIZED_VIEW:
case SUPPORTS_RENAME_MATERIALIZED_VIEW:
return true;
case SUPPORTS_RENAME_MATERIALIZED_VIEW_ACROSS_SCHEMAS:
return false;

case SUPPORTS_DELETE:
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_MULTI_STATEMENT_WRITES;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_COLUMN;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_MATERIALIZED_VIEW;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_MATERIALIZED_VIEW_ACROSS_SCHEMAS;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_SCHEMA;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_TABLE;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS;
Expand Down Expand Up @@ -723,7 +724,21 @@ public void testRenameMaterializedView()
assertUpdate(session, "ALTER MATERIALIZED VIEW " + testExistsMaterializedViewName + " RENAME TO " + uppercaseName);
assertTestingMaterializedViewQuery(schema, uppercaseName.toLowerCase(ENGLISH)); // Ensure select allows for lower-case, not delimited identifier

assertUpdate(session, "DROP MATERIALIZED VIEW " + uppercaseName);
String otherSchema = "rename_mv_other_schema";
assertUpdate(format("CREATE SCHEMA IF NOT EXISTS %s", otherSchema));
if (hasBehavior(SUPPORTS_RENAME_MATERIALIZED_VIEW_ACROSS_SCHEMAS)) {
assertUpdate(session, "ALTER MATERIALIZED VIEW " + uppercaseName + " RENAME TO " + otherSchema + "." + originalMaterializedView.getObjectName());
assertTestingMaterializedViewQuery(otherSchema, originalMaterializedView.getObjectName());

assertUpdate(session, "DROP MATERIALIZED VIEW " + otherSchema + "." + originalMaterializedView.getObjectName());
}
else {
assertQueryFails(
session,
"ALTER MATERIALIZED VIEW " + uppercaseName + " RENAME TO " + otherSchema + "." + originalMaterializedView.getObjectName(),
"Materialized View rename across schemas is not supported");
assertUpdate(session, "DROP MATERIALIZED VIEW " + uppercaseName);
}

assertFalse(getQueryRunner().tableExists(session, originalMaterializedView.toString()));
assertFalse(getQueryRunner().tableExists(session, renamedMaterializedView));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public enum TestingConnectorBehavior

SUPPORTS_CREATE_MATERIALIZED_VIEW(false),
SUPPORTS_RENAME_MATERIALIZED_VIEW(false),
SUPPORTS_RENAME_MATERIALIZED_VIEW_ACROSS_SCHEMAS(SUPPORTS_RENAME_MATERIALIZED_VIEW),

SUPPORTS_INSERT,

Expand Down

0 comments on commit 51279b7

Please sign in to comment.