prestodb/presto · error · MaterializedViewNotFoundException
Materialized view not found
Error message
Materialized view not found
What it means
Thrown from dropMaterializedView when getMaterializedView finds no materialized view definition for the given name: the object does not exist, or exists but is not a Presto materialized view (no parseable materialized-view JSON in its metadata). MaterializedViewNotFoundException carries the SchemaTableName.
Source
Thrown at presto-hive/src/main/java/com/facebook/presto/hive/HiveMetadata.java:2686
session,
viewTable,
principalPrivileges,
Optional.empty(),
ignoreExisting,
new PartitionStatistics(createEmptyStatistics(), ImmutableMap.of()),
emptyList());
}
catch (TableAlreadyExistsException e) {
throw new MaterializedViewAlreadyExistsException(e.getTableName());
}
}
@Override
public void dropMaterializedView(ConnectorSession session, SchemaTableName viewName)
{
Optional<MaterializedViewDefinition> view = getMaterializedView(session, viewName);
if (!view.isPresent()) {
throw new MaterializedViewNotFoundException(viewName);
}
try {
metastore.dropTable(
new HdfsContext(session, viewName.getSchemaName(), viewName.getTableName()),
viewName.getSchemaName(),
viewName.getTableName());
}
catch (TableNotFoundException e) {
throw new MaterializedViewNotFoundException(e.getTableName());
}
}
@Override
public HiveInsertTableHandle beginRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle)
{
return beginInsertInternal(session, tableHandle);
}View on GitHub (pinned to 55bb57d202)
Solutions
- Use DROP MATERIALIZED VIEW IF EXISTS for idempotency
- Verify the object type with SHOW TABLES / SHOW CREATE and use DROP TABLE or DROP VIEW if it is not a materialized view
- Check catalog/schema spelling and current session catalog
- If getMaterializedView keeps failing on a name you know is an MV, the stored definition is corrupt — see the INVALID_VIEW case and recreate the view
Example fix
-- before DROP MATERIALIZED VIEW metrics.mv_daily; -- after DROP MATERIALIZED VIEW IF EXISTS metrics.mv_daily;
Defensive patterns
Strategy: try-catch
Validate before calling
-- existence and type check before drop SELECT * FROM system.metadata.table_comments WHERE schema_name = ? AND table_name = ?; -- or attempt getMaterializedView first and branch on isPresent()
Try / catch
try {
run("DROP MATERIALIZED VIEW " + name);
} catch (MaterializedViewNotFoundException e) {
log.info("Materialized view absent, nothing to drop: {}", name);
} Prevention
- Use DROP MATERIALIZED VIEW IF EXISTS in cleanup scripts
- Verify object kind before dropping (table vs view vs MV)
- Qualify catalog and schema explicitly in automation
- Guard against double-execution with IF EXISTS or state tracking
When it happens
Trigger: DROP MATERIALIZED VIEW on a name that is a plain table or regular view, was already dropped, is misspelled, or exists in a different catalog/schema.
Common situations: Cleanup scripts running twice; confusing a plain table with a materialized view of the same name; catalog mix-ups (views created in another connector); objects dropped by other users.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/13f774a2ed355f16.
Report an issue: GitHub.