{"record":{"id":"25f2f21c3c1cddf8","repo":"prestodb/presto","slug":"not-supported-25f2f2","errorCode":"NOT_SUPPORTED","errorMessage":"'%s' is a materialized view, and drop branch is not supported","messagePattern":"'(.+?)' is a materialized view, and drop branch is not supported","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/execution/DropBranchTask.java","lineNumber":62,"sourceCode":"        return \"DROP BRANCH\";\n    }\n\n    @Override\n    public ListenableFuture<?> execute(DropBranch statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector, String query)\n    {\n        QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName(), metadata);\n        Optional<TableHandle> tableHandleOptional = metadata.getMetadataResolver(session).getTableHandle(tableName);\n\n        if (!tableHandleOptional.isPresent()) {\n            if (!statement.isTableExists()) {\n                throw new SemanticException(MISSING_TABLE, statement, \"Table '%s' does not exist\", tableName);\n            }\n            return immediateFuture(null);\n        }\n\n        Optional<MaterializedViewDefinition> optionalMaterializedView = metadata.getMetadataResolver(session).getMaterializedView(tableName);\n        if (optionalMaterializedView.isPresent()) {\n            throw new SemanticException(NOT_SUPPORTED, statement, \"'%s' is a materialized view, and drop branch is not supported\", tableName);\n        }\n\n        getConnectorIdOrThrow(session, metadata, tableName.getCatalogName());\n        accessControl.checkCanDropBranch(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName);\n\n        metadata.dropBranch(session, tableHandleOptional.get(), statement.getBranchName(), statement.isBranchExists());\n        return immediateFuture(null);\n    }\n}\n","sourceCodeStart":44,"sourceCodeEnd":72,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/DropBranchTask.java#L44-L72","documentation":"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.","triggerScenarios":"Executing DROP BRANCH ... ON <name> where getMaterializedView(tableName) returns a definition, i.e. the name refers to a materialized view.","commonSituations":"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.","solutions":["Target the underlying versioned base table instead of the materialized view.","If branch-like versioning is needed on the materialized view's data, manage branches on the source table and refresh the view accordingly.","Check the object type first (SHOW CREATE or system metadata) to confirm it is a table, not a materialized view."],"exampleFix":"// before\nDROP BRANCH b1 ON hive.default.events_mv; -- materialized view\n// after (operate on the base table)\nDROP BRANCH b1 ON hive.default.events;","handlingStrategy":"validation","validationCode":"-- Check whether the object is a materialized view before DROP BRANCH\nSELECT * FROM system.metadata.materialized_views\nWHERE catalog = 'hive' AND schema = 'default' AND name = 'events_mv';","typeGuard":"function isMaterializedView(session, qname) {\n  return session.execute(\n    'SELECT count(*) FROM system.metadata.materialized_views WHERE catalog = ? AND schema = ? AND name = ?',\n    [qname.catalog, qname.schema, qname.table]) > 0;\n}","tryCatchPattern":"try {\n  session.execute(dropBranchSql);\n} catch (e) {\n  if (/is a materialized view, and drop branch is not supported/.test(e.message)) {\n    // redirect operation to the base table\n  }\n  throw e;\n}","preventionTips":["Resolve object type (table vs materialized view) before issuing branch DDL.","Avoid name collisions between tables and materialized views (use naming conventions like _mv suffix).","Document that branch operations apply only to versioned tables, not materialized views."],"tags":["presto","sql","materialized-view","not-supported"],"backgroundTag":"operation-not-supported","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}