prestodb/presto · error · PrestoException

INVALID_VIEW

INVALID_VIEW

Error message

Invalid materialized view JSON

What it means

Thrown with INVALID_VIEW when the stored viewOriginalText of a Presto materialized view cannot be parsed as its JSON definition. The metastore row exists and is flagged as a materialized view, but its encoded definition is corrupt, truncated, hand-edited, or written by an incompatible codec version, so getMaterializedView cannot deserialize it.

Source

Thrown at presto-hive/src/main/java/com/facebook/presto/hive/HiveMetadata.java:2556

            }
        }
        return views.build();
    }

    @Override
    public Optional<MaterializedViewDefinition> getMaterializedView(ConnectorSession session, SchemaTableName viewName)
    {
        requireNonNull(viewName, "viewName is null");

        MetastoreContext metastoreContext = getMetastoreContext(session);
        Optional<Table> table = metastore.getTable(metastoreContext, viewName.getSchemaName(), viewName.getTableName());

        if (table.isPresent() && MetastoreUtil.isPrestoMaterializedView(table.get())) {
            try {
                return Optional.of(MATERIALIZED_VIEW_JSON_CODEC.fromJson(decodeMaterializedViewData(table.get().getViewOriginalText().get())));
            }
            catch (IllegalArgumentException e) {
                throw new PrestoException(INVALID_VIEW, "Invalid materialized view JSON", e);
            }
        }

        return Optional.empty();
    }

    @Override
    public MaterializedViewStatus getMaterializedViewStatus(ConnectorSession session, SchemaTableName materializedViewName, TupleDomain<String> baseQueryDomain)
    {
        MetastoreContext metastoreContext = getMetastoreContext(session);
        MaterializedViewDefinition viewDefinition = getMaterializedView(session, materializedViewName)
                .orElseThrow(() -> new MaterializedViewNotFoundException(materializedViewName));

        List<Table> baseTables = viewDefinition.getBaseTables().stream()
                .map(baseTableName -> metastore.getTable(metastoreContext, baseTableName.getSchemaName(), baseTableName.getTableName())
                        .orElseThrow(() -> new TableNotFoundException(baseTableName)))
                .collect(toImmutableList());

View on GitHub (pinned to 55bb57d202)

Solutions

  1. DROP the broken materialized view and re-CREATE it from its original SQL (recover it from your migration sources)
  2. Inspect the stored viewOriginalText in the metastore to see what is corrupt
  3. Restore the metastore row from a healthy backup
  4. Align Presto versions: a definition written by an incompatible release cannot be parsed; recreate views after upgrade
  5. Never hand-edit viewOriginalText — it must remain exactly what the connector encoded
Defensive patterns

Strategy: validation

Validate before calling

// check the stored definition parses before use
String text = table.getViewOriginalText().get();
try {
    MATERIALIZED_VIEW_JSON_CODEC.fromJson(decodeMaterializedViewData(text));
} catch (IllegalArgumentException e) {
    scheduleRecreate(materializedViewName); // definition is corrupt
}

Type guard

boolean isHealthyMaterializedView(Table t) {
    return t.getViewOriginalText().isPresent() && MetastoreUtil.isPrestoMaterializedView(t);
}

Try / catch

try {
    refreshMaterializedView(name);
} catch (PrestoException e) {
    if (e.getErrorCode() == INVALID_VIEW.toErrorCode()) {
        dropAndRecreate(name); // only fix for corrupt JSON
    } else { throw e; }
}

Prevention

When it happens

Trigger: Reading metadata of a materialized view whose viewOriginalText fails MATERIALIZED_VIEW_JSON_CODEC.fromJson (IllegalArgumentException) — corrupted metastore rows, manual ALTER of viewOriginalText, restore from backup with partial data, or definition written by a newer/older incompatible Presto version.

Common situations: Manual metastore surgery or migration scripts editing viewOriginalText; restoring Hive metastore from partial dumps; upgrades changing the JSON schema of MaterializedViewDefinition; storage-level truncation of the row.

Related errors


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