prestodb/presto · error · SemanticException

MISSING_SCHEMA

MISSING_SCHEMA

Error message

Schema '%s' does not exist

What it means

CREATE MATERIALIZED VIEW targets a schema that does not exist in the given catalog. After the catalog check passes, the task verifies metadataResolver.schemaExists(viewName.getCatalogSchemaName()) and throws SemanticException MISSING_SCHEMA when it fails.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/execution/CreateMaterializedViewTask.java:103

    @Override
    public String getName()
    {
        return "CREATE MATERIALIZED VIEW";
    }

    @Override
    public ListenableFuture<?> execute(CreateMaterializedView statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector, String query)
    {
        QualifiedObjectName viewName = createQualifiedObjectName(session, statement, statement.getName(), metadata);
        MetadataResolver metadataResolver = metadata.getMetadataResolver(session);

        if (!metadataResolver.catalogExists(viewName.getCatalogName())) {
            throw new SemanticException(MISSING_CATALOG, "Catalog '%s' does not exist", viewName.getCatalogName());
        }

        if (!metadataResolver.schemaExists(viewName.getCatalogSchemaName())) {
            throw new SemanticException(MISSING_SCHEMA, statement, "Schema '%s' does not exist", viewName.getSchemaName());
        }

        Optional<TableHandle> viewHandle = metadataResolver.getTableHandle(viewName);
        if (viewHandle.isPresent()) {
            if (!statement.isNotExists()) {
                throw new SemanticException(MATERIALIZED_VIEW_ALREADY_EXISTS, statement, "Materialized view '%s' already exists", viewName);
            }
            return immediateFuture(null);
        }

        accessControl.checkCanCreateTable(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), viewName);
        accessControl.checkCanCreateView(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), viewName);

        Map<NodeRef<Parameter>, Expression> parameterLookup = parameterExtractor(statement, parameters);
        Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.empty(), parameters, parameterLookup, warningCollector, query, new ViewDefinitionReferences());
        Analysis analysis = analyzer.analyzeSemantic(statement, false);
        checkAccessPermissions(analysis.getAccessControlReferences(), analysis.getViewDefinitionReferences(), query, session.getPreparedStatements(), session.getIdentity(), accessControl, session.getAccessControlContext());

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Run CREATE SCHEMA cat.my_schema before creating the materialized view
  2. Fix the schema name typo (SHOW SCHEMAS FROM catalog to list valid ones)
  3. Confirm the schema exists in the target environment/catalog, not just locally
  4. Check identifier casing/quoting if the schema uses mixed case

Example fix

// before
CREATE MATERIALIZED VIEW hive.sales.mv_daily AS SELECT ...
// after
CREATE SCHEMA IF NOT EXISTS hive.sales;
CREATE MATERIALIZED VIEW hive.sales.mv_daily AS SELECT ...
Defensive patterns

Strategy: validation

Validate before calling

// ensure schema exists before creating the MV
execute(String.format("CREATE SCHEMA IF NOT EXISTS %s.%s", catalog, schema));

Prevention

When it happens

Trigger: CREATE MATERIALIZED VIEW cat.nonexistent_schema.mv AS ...; schema name typo; schema dropped by another job before this statement ran; using a schema name that only exists in another catalog.

Common situations: Environment differences (schema exists in dev, missing in prod); case-sensitivity issues with quoted vs unquoted identifiers; automation that assumed CREATE SCHEMA was run earlier; permission masking making the schema invisible.

Related errors


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