prestodb/presto · error · PrestoException

INVALID_VIEW

INVALID_VIEW

Error message

Invalid view JSON: 

What it means

INVALID_VIEW is thrown when a serialized view definition stored in the connector's metadata cannot be deserialized from JSON. MetadataManager uses a JSON codec (viewCodec) to decode stored view definitions, and if the stored data is malformed or was written by an incompatible Presto version, fromJson fails with IllegalArgumentException. The raw data is included in the message to aid diagnosis.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/metadata/MetadataManager.java:1895

    @Override
    public Optional<TableFunctionApplicationResult<TableHandle>> applyTableFunction(Session session, TableFunctionHandle handle)
    {
        ConnectorId connectorId = handle.getConnectorId();
        ConnectorMetadata metadata = getMetadata(session, connectorId);

        return metadata.applyTableFunction(session.toConnectorSession(connectorId), handle.getFunctionHandle())
                .map(result -> new TableFunctionApplicationResult<>(
                        new TableHandle(connectorId, result.getTableHandle(), handle.getTransactionHandle(), Optional.empty()),
                        result.getColumnHandles()));
    }

    private ViewDefinition deserializeView(String data)
    {
        try {
            return viewCodec.fromJson(data);
        }
        catch (IllegalArgumentException e) {
            throw new PrestoException(INVALID_VIEW, "Invalid view JSON: " + data, e);
        }
    }

    private CatalogMetadata getCatalogMetadata(Session session, ConnectorId connectorId)
    {
        return transactionManager.getCatalogMetadata(session.getRequiredTransactionId(), connectorId);
    }

    private CatalogMetadata getCatalogMetadataForWrite(Session session, String catalogName)
    {
        return transactionManager.getCatalogMetadataForWrite(session.getRequiredTransactionId(), catalogName);
    }

    private CatalogMetadata getCatalogMetadataForWrite(Session session, ConnectorId connectorId)
    {
        return transactionManager.getCatalogMetadataForWrite(session.getRequiredTransactionId(), connectorId);
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Recreate the view with CREATE OR REPLACE VIEW so a fresh, current-format JSON definition is stored
  2. Check the view JSON (printed in the message) for truncation or corruption and fix it at the metastore level
  3. Roll back to the Presto version that originally created the view to read it, then recreate it on the new version
  4. Verify no other Presto/Trino versions with incompatible codecs are sharing the same metastore

Example fix

-- before: SELECT * FROM my_view  ->  Invalid view JSON: {...}
-- after
DROP VIEW my_view;
CREATE VIEW my_view AS SELECT ...;  -- recreate with the current engine
Defensive patterns

Strategy: try-catch

Validate before calling

// Best pre-check: test JSON parse of stored view data
try { JsonCodec.jsonInstance(ViewDefinition.class).fromJson(data); }
catch (IllegalArgumentException e) { /* view data corrupt: recreate view */ }

Type guard

// Java: no dynamic type guard; validate structurally
boolean isLikelyValidViewJson(String data) {
    return data != null && data.trim().startsWith("{") && data.contains("\"columns\"");
}

Try / catch

try {
    metadata.getView(session, viewName);
} catch (PrestoException e) {
    if (e.getErrorCode().getCode() == StandardErrorCode.INVALID_VIEW.getCode()) {
        // drop and recreate the view
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling MetadataManager.getView (or any path that reads a view such as SHOW CREATE VIEW, SELECT on a view, or getViewDefinition) where the stored view JSON string is corrupt, truncated, hand-edited, or written by a different Presto version whose ViewDefinition schema no longer matches.

Common situations: Upgrading Presto across a version where the ViewDefinition format changed; metastore corruption or manual edits to view metadata; restoring a metastore backup from an incompatible cluster; connectors storing views with incompatible codecs.

Related errors


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