{"record":{"id":"5536ea89ebe8ab2a","repo":"prestodb/presto","slug":"output-column-s-definition-not-found-in-input-s","errorCode":null,"errorMessage":"Output column (%s) definition not found in input selections: %s","messagePattern":"Output column \\((.+?)\\) definition not found in input selections: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/query/PinotQueryGeneratorContext.java","lineNumber":421,"sourceCode":"    }\n\n    private List<Integer> getIndicesMappingFromPinotSchemaToPrestoSchema(String query, Map<VariableReferenceExpression, PinotColumnHandle> assignments)\n    {\n        LinkedHashMap<VariableReferenceExpression, Selection> expressionsInPinotOrder = new LinkedHashMap<>();\n        for (VariableReferenceExpression groupByColumn : groupByColumns) {\n            Selection groupByColumnDefinition = selections.get(groupByColumn);\n            if (groupByColumnDefinition == null) {\n                throw new IllegalStateException(format(\n                        \"Group By column (%s) definition not found in input selections: %s\",\n                        groupByColumn,\n                        Joiner.on(\",\").withKeyValueSeparator(\":\").join(selections)));\n            }\n            expressionsInPinotOrder.put(groupByColumn, groupByColumnDefinition);\n        }\n        for (VariableReferenceExpression outputColumn : outputs) {\n            Selection outputColumnDefinition = selections.get(outputColumn);\n            if (outputColumnDefinition == null) {\n                throw new IllegalStateException(format(\n                        \"Output column (%s) definition not found in input selections: %s\",\n                        outputColumn,\n                        Joiner.on(\",\").withKeyValueSeparator(\":\").join(selections)));\n            }\n            expressionsInPinotOrder.put(outputColumn, outputColumnDefinition);\n        }\n\n        checkSupported(\n                assignments.size() <= expressionsInPinotOrder.keySet().stream().filter(key -> !hiddenColumnSet.contains(key)).count(),\n                \"Expected returned expressions %s is a superset of selections %s\",\n                Joiner.on(\",\").withKeyValueSeparator(\":\").join(expressionsInPinotOrder),\n                Joiner.on(\",\").withKeyValueSeparator(\"=\").join(assignments));\n\n        Map<VariableReferenceExpression, Integer> assignmentToIndex = new HashMap<>();\n        Iterator<Map.Entry<VariableReferenceExpression, PinotColumnHandle>> assignmentsIterator = assignments.entrySet().iterator();\n        for (int i = 0; i < assignments.size(); i++) {\n            VariableReferenceExpression key = assignmentsIterator.next().getKey();\n            Integer previous = assignmentToIndex.put(key, i);","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/query/PinotQueryGeneratorContext.java#L403-L439","documentation":"In the same index-mapping routine, each output variable must have a Selection registered in the context. When an output column variable is missing from the selections map the mapping cannot be built and an IllegalStateException is thrown, listing the whole selections map for debugging. This signals the query generator produced an output column without recording its definition.","triggerScenarios":"An output variable of the AggregationNode/ProjectNode is not present in selections when indices() runs, e.g. an aggregation output or hidden/derived column that was never inserted via withAggregation/withOutputColumns.","commonSituations":"Queries selecting aggregates plus grouping columns where one output was produced by an unsupported or unregistered projection; connector bugs after planner rewrites (e.g. pruning/renaming) rather than user error.","solutions":["Simplify the SELECT list to plain columns and supported aggregates over table columns.","Retry with a query that avoids derived output expressions so every output maps to a known selection.","Inspect the 'Output column (%s) definition not found' payload and file a bug with the query if a plain column reference triggers it."],"exampleFix":"// before\nSELECT upper(user_region) AS r, count(*) FROM events GROUP BY 1;\n// after\nSELECT user_region, count(*) FROM events GROUP BY user_region;","handlingStrategy":"try-catch","validationCode":"// Keep SELECT lists to plain columns and supported aggregates so every output has a selection\nboolean outputsResolvable = selectTerms.stream().allMatch(t -> tableColumns.contains(t) || isSupportedAggregate(t));\nif (!outputsResolvable) { disablePushdown(); }","typeGuard":null,"tryCatchPattern":"try {\n    runQuery(sql);\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Output column\")) {\n        runQueryWithoutPushdown(sql);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Avoid computed/renamed expressions in the SELECT list of Pinot-pushed queries.","Simplify projections over aggregations; post-process in Presto.","File a bug with the selections dump if plain outputs trigger it."],"tags":["pinot","pushdown","projection","internal-state"],"backgroundTag":"missing-column-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"}