prestodb/presto · error · SemanticException

NOT_SUPPORTED

NOT_SUPPORTED

Error message

'%s' is a materialized view, and drop branch is not supported

What it means

DropBranchTask.execute rejects the operation when the target object resolves as a materialized view rather than a versioned table. Materialized views do not support branch semantics, so a SemanticException(NOT_SUPPORTED) is thrown before any access-control or connector call.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/execution/DropBranchTask.java:62

        return "DROP BRANCH";
    }

    @Override
    public ListenableFuture<?> execute(DropBranch statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector, String query)
    {
        QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName(), metadata);
        Optional<TableHandle> tableHandleOptional = metadata.getMetadataResolver(session).getTableHandle(tableName);

        if (!tableHandleOptional.isPresent()) {
            if (!statement.isTableExists()) {
                throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
            }
            return immediateFuture(null);
        }

        Optional<MaterializedViewDefinition> optionalMaterializedView = metadata.getMetadataResolver(session).getMaterializedView(tableName);
        if (optionalMaterializedView.isPresent()) {
            throw new SemanticException(NOT_SUPPORTED, statement, "'%s' is a materialized view, and drop branch is not supported", tableName);
        }

        getConnectorIdOrThrow(session, metadata, tableName.getCatalogName());
        accessControl.checkCanDropBranch(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName);

        metadata.dropBranch(session, tableHandleOptional.get(), statement.getBranchName(), statement.isBranchExists());
        return immediateFuture(null);
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Target the underlying versioned base table instead of the materialized view.
  2. If branch-like versioning is needed on the materialized view's data, manage branches on the source table and refresh the view accordingly.
  3. Check the object type first (SHOW CREATE or system metadata) to confirm it is a table, not a materialized view.

Example fix

// before
DROP BRANCH b1 ON hive.default.events_mv; -- materialized view
// after (operate on the base table)
DROP BRANCH b1 ON hive.default.events;
Defensive patterns

Strategy: validation

Validate before calling

-- Check whether the object is a materialized view before DROP BRANCH
SELECT * FROM system.metadata.materialized_views
WHERE catalog = 'hive' AND schema = 'default' AND name = 'events_mv';

Type guard

function isMaterializedView(session, qname) {
  return session.execute(
    'SELECT count(*) FROM system.metadata.materialized_views WHERE catalog = ? AND schema = ? AND name = ?',
    [qname.catalog, qname.schema, qname.table]) > 0;
}

Try / catch

try {
  session.execute(dropBranchSql);
} catch (e) {
  if (/is a materialized view, and drop branch is not supported/.test(e.message)) {
    // redirect operation to the base table
  }
  throw e;
}

Prevention

When it happens

Trigger: Executing DROP BRANCH ... ON <name> where getMaterializedView(tableName) returns a definition, i.e. the name refers to a materialized view.

Common situations: Assuming a materialized view behaves like a versioned Iceberg/Delta table; name collision between a table and a materialized view in a different catalog/schema; migrating scripts written for tables to materialized views.

Understand the failure class

Background: Presto NOT_SUPPORTED error: what "not supported" means and how to fix it — this error's family across 3 libraries.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/25f2f21c3c1cddf8. Report an issue: GitHub.