{"record":{"id":"924cbb7dd661e84e","repo":"prestodb/presto","slug":"invalid-view-924cbb","errorCode":"INVALID_VIEW","errorMessage":"Invalid view JSON: ","messagePattern":"Invalid view JSON: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/metadata/MetadataManager.java","lineNumber":1895,"sourceCode":"    @Override\n    public Optional<TableFunctionApplicationResult<TableHandle>> applyTableFunction(Session session, TableFunctionHandle handle)\n    {\n        ConnectorId connectorId = handle.getConnectorId();\n        ConnectorMetadata metadata = getMetadata(session, connectorId);\n\n        return metadata.applyTableFunction(session.toConnectorSession(connectorId), handle.getFunctionHandle())\n                .map(result -> new TableFunctionApplicationResult<>(\n                        new TableHandle(connectorId, result.getTableHandle(), handle.getTransactionHandle(), Optional.empty()),\n                        result.getColumnHandles()));\n    }\n\n    private ViewDefinition deserializeView(String data)\n    {\n        try {\n            return viewCodec.fromJson(data);\n        }\n        catch (IllegalArgumentException e) {\n            throw new PrestoException(INVALID_VIEW, \"Invalid view JSON: \" + data, e);\n        }\n    }\n\n    private CatalogMetadata getCatalogMetadata(Session session, ConnectorId connectorId)\n    {\n        return transactionManager.getCatalogMetadata(session.getRequiredTransactionId(), connectorId);\n    }\n\n    private CatalogMetadata getCatalogMetadataForWrite(Session session, String catalogName)\n    {\n        return transactionManager.getCatalogMetadataForWrite(session.getRequiredTransactionId(), catalogName);\n    }\n\n    private CatalogMetadata getCatalogMetadataForWrite(Session session, ConnectorId connectorId)\n    {\n        return transactionManager.getCatalogMetadataForWrite(session.getRequiredTransactionId(), connectorId);\n    }\n","sourceCodeStart":1877,"sourceCodeEnd":1913,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/metadata/MetadataManager.java#L1877-L1913","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Recreate the view with CREATE OR REPLACE VIEW so a fresh, current-format JSON definition is stored","Check the view JSON (printed in the message) for truncation or corruption and fix it at the metastore level","Roll back to the Presto version that originally created the view to read it, then recreate it on the new version","Verify no other Presto/Trino versions with incompatible codecs are sharing the same metastore"],"exampleFix":"-- before: SELECT * FROM my_view  ->  Invalid view JSON: {...}\n-- after\nDROP VIEW my_view;\nCREATE VIEW my_view AS SELECT ...;  -- recreate with the current engine","handlingStrategy":"try-catch","validationCode":"// Best pre-check: test JSON parse of stored view data\ntry { JsonCodec.jsonInstance(ViewDefinition.class).fromJson(data); }\ncatch (IllegalArgumentException e) { /* view data corrupt: recreate view */ }","typeGuard":"// Java: no dynamic type guard; validate structurally\nboolean isLikelyValidViewJson(String data) {\n    return data != null && data.trim().startsWith(\"{\") && data.contains(\"\\\"columns\\\"\");\n}","tryCatchPattern":"try {\n    metadata.getView(session, viewName);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == StandardErrorCode.INVALID_VIEW.getCode()) {\n        // drop and recreate the view\n    } else { throw e; }\n}","preventionTips":["Avoid manual edits to view metadata in the metastore","Use the same Presto version family across clusters sharing a metastore","Recreate (not migrate) views when upgrading across format-changing releases","Back up and validate metastore view definitions after restores"],"tags":["presto","view-metadata","json-deserialization"],"backgroundTag":"invalid-view-json","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"}