{"record":{"id":"97df787083a66da7","repo":"prestodb/presto","slug":"invalid-view-97df78","errorCode":"INVALID_VIEW","errorMessage":"Invalid materialized view JSON","messagePattern":"Invalid materialized view JSON","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/HiveMetadata.java","lineNumber":2556,"sourceCode":"            }\n        }\n        return views.build();\n    }\n\n    @Override\n    public Optional<MaterializedViewDefinition> getMaterializedView(ConnectorSession session, SchemaTableName viewName)\n    {\n        requireNonNull(viewName, \"viewName is null\");\n\n        MetastoreContext metastoreContext = getMetastoreContext(session);\n        Optional<Table> table = metastore.getTable(metastoreContext, viewName.getSchemaName(), viewName.getTableName());\n\n        if (table.isPresent() && MetastoreUtil.isPrestoMaterializedView(table.get())) {\n            try {\n                return Optional.of(MATERIALIZED_VIEW_JSON_CODEC.fromJson(decodeMaterializedViewData(table.get().getViewOriginalText().get())));\n            }\n            catch (IllegalArgumentException e) {\n                throw new PrestoException(INVALID_VIEW, \"Invalid materialized view JSON\", e);\n            }\n        }\n\n        return Optional.empty();\n    }\n\n    @Override\n    public MaterializedViewStatus getMaterializedViewStatus(ConnectorSession session, SchemaTableName materializedViewName, TupleDomain<String> baseQueryDomain)\n    {\n        MetastoreContext metastoreContext = getMetastoreContext(session);\n        MaterializedViewDefinition viewDefinition = getMaterializedView(session, materializedViewName)\n                .orElseThrow(() -> new MaterializedViewNotFoundException(materializedViewName));\n\n        List<Table> baseTables = viewDefinition.getBaseTables().stream()\n                .map(baseTableName -> metastore.getTable(metastoreContext, baseTableName.getSchemaName(), baseTableName.getTableName())\n                        .orElseThrow(() -> new TableNotFoundException(baseTableName)))\n                .collect(toImmutableList());\n","sourceCodeStart":2538,"sourceCodeEnd":2574,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/HiveMetadata.java#L2538-L2574","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["DROP the broken materialized view and re-CREATE it from its original SQL (recover it from your migration sources)","Inspect the stored viewOriginalText in the metastore to see what is corrupt","Restore the metastore row from a healthy backup","Align Presto versions: a definition written by an incompatible release cannot be parsed; recreate views after upgrade","Never hand-edit viewOriginalText — it must remain exactly what the connector encoded"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// check the stored definition parses before use\nString text = table.getViewOriginalText().get();\ntry {\n    MATERIALIZED_VIEW_JSON_CODEC.fromJson(decodeMaterializedViewData(text));\n} catch (IllegalArgumentException e) {\n    scheduleRecreate(materializedViewName); // definition is corrupt\n}","typeGuard":"boolean isHealthyMaterializedView(Table t) {\n    return t.getViewOriginalText().isPresent() && MetastoreUtil.isPrestoMaterializedView(t);\n}","tryCatchPattern":"try {\n    refreshMaterializedView(name);\n} catch (PrestoException e) {\n    if (e.getErrorCode() == INVALID_VIEW.toErrorCode()) {\n        dropAndRecreate(name); // only fix for corrupt JSON\n    } else { throw e; }\n}","preventionTips":["Never hand-edit viewOriginalText in the metastore","Back up metastore rows before migrations","Recreate materialized views after major Presto upgrades","Validate definitions after metastore restores"],"tags":["hive","materialized-view","json","corruption","metastore"],"backgroundTag":"invalid-view-definition","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"}