{"record":{"id":"d66db09ef36a8388","repo":"prestodb/presto","slug":"view-analysis-error","errorCode":"VIEW_ANALYSIS_ERROR","errorMessage":"Failed analyzing stored view '%s': %s","messagePattern":"Failed analyzing stored view '(.+?)': (.+?)","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java","lineNumber":5227,"sourceCode":"                if (owner.isPresent() && !owner.get().equals(session.getIdentity().getUser())) {\n                    // definer mode\n                    identity = new Identity(owner.get(), Optional.empty(), emptyMap(), session.getIdentity().getExtraCredentials(), emptyMap(), Optional.empty(), session.getIdentity().getReasonForSelect(), emptyList());\n                    viewAccessControl = new ViewAccessControl(accessControl);\n                }\n                else {\n                    identity = session.getIdentity();\n                    viewAccessControl = accessControl;\n                }\n\n                Session viewSession = createViewSession(catalog, schema, identity);\n\n                StatementAnalyzer analyzer = new StatementAnalyzer(analysis, metadata, sqlParser, viewAccessControl, viewSession, warningCollector);\n                Scope queryScope = analyzer.analyze(query, Scope.create());\n                return queryScope.getRelationType().withAlias(name.getObjectName(), null);\n            }\n            catch (RuntimeException e) {\n                throwIfInstanceOf(e, PrestoException.class);\n                throw new SemanticException(VIEW_ANALYSIS_ERROR, e, node.getLocation(), \"Failed analyzing stored view '%s': %s\", name, e.getMessage());\n            }\n        }\n\n        private Session createViewSession(Optional<String> catalog, Optional<String> schema, Identity identity)\n        {\n            Session.SessionBuilder viewSessionBuilder = Session.builder(metadata.getSessionPropertyManager())\n                    .setQueryId(session.getQueryId())\n                    .setRuntimeStats(session.getRuntimeStats())\n                    .setTransactionId(session.getTransactionId().orElse(null))\n                    .setIdentity(identity)\n                    .setSource(session.getSource().orElse(null))\n                    .setCatalog(catalog.orElse(null))\n                    .setSchema(schema.orElse(null))\n                    .setTimeZoneKey(session.getTimeZoneKey())\n                    .setLocale(session.getLocale())\n                    .setRemoteUserAddress(session.getRemoteUserAddress().orElse(null))\n                    .setUserAgent(session.getUserAgent().orElse(null))\n                    .setClientInfo(session.getClientInfo().orElse(null))","sourceCodeStart":5209,"sourceCodeEnd":5245,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java#L5209-L5245","documentation":"When a query references a stored view, Presto re-analyzes the view's stored SQL. If that analysis fails with a non-PrestoException RuntimeException, it is wrapped as VIEW_ANALYSIS_ERROR so the user sees which view failed and why. Common inner causes: referenced tables/columns dropped or renamed, permission changes, or type invalidation since the view was created.","triggerScenarios":"`SELECT * FROM catalog.schema.view` where the view's underlying table was dropped/renamed, a column's type changed incompatibly, the view body references a missing function, or the caller lacks privileges (analyzed under a view access control); thrown in analyzeView of StatementAnalyzer.","commonSituations":"Schema drift: upstream tables changed after CREATE VIEW; revoked permissions on the base table; connector catalog changes; stale view definitions after migrations.","solutions":["Read the wrapped inner message to find the real failure (missing table/column/function)","DROP and recreate the view against the current schema","Restore the missing base table/column or correct the view's SQL via ALTER VIEW/CREATE OR REPLACE VIEW","Fix permissions so the view owner can access the underlying objects"],"exampleFix":"-- before (broken view referencing dropped column)\nCREATE VIEW v AS SELECT old_col FROM t;\n-- after\nCREATE OR REPLACE VIEW v AS SELECT new_col FROM t;","handlingStrategy":"try-catch","validationCode":"// Periodically re-validate stored views:\nSELECT * FROM system.metadata.views -- then run each view's definition\n-- or: SELECT * FROM <view> LIMIT 0; to detect breakage early","typeGuard":null,"tryCatchPattern":"try { return session.execute(\"SELECT * FROM \" + viewName); }\ncatch (SemanticException e) {\n    if (e.getCode() == VIEW_ANALYSIS_ERROR) {\n        log.error(\"View {} broken: {}\", viewName, e.getCause().getMessage());\n        // rebuild or fail over\n    } else { throw e; }\n}","preventionTips":["Track schema migrations and recreate dependent views in the same change","Add CI checks that run SELECT ... LIMIT 0 against all stored views","Avoid dropping/renaming columns used by views without ALTER VIEW first"],"tags":["sql","view","analysis","schema-drift"],"backgroundTag":"view-analysis-failed","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"}