{"record":{"id":"de3006f714dabe25","repo":"prestodb/presto","slug":"group-by-column-s-definition-not-found-in-input","errorCode":null,"errorMessage":"Group By column (%s) definition not found in input selections: %s","messagePattern":"Group By 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":411,"sourceCode":"        return new PinotQueryGenerator.GeneratedPinotQuery(tableName, query, indices, filter.isPresent(), forBroker);\n    }\n\n    private String updateSelection(String definition, ConnectorSession session)\n    {\n        final String overrideDistinctCountFunction = PinotSessionProperties.getOverrideDistinctCountFunction(session);\n        if (!PINOT_DISTINCT_COUNT_FUNCTION_NAME.equalsIgnoreCase(overrideDistinctCountFunction)) {\n            return definition.replaceFirst(PINOT_DISTINCT_COUNT_FUNCTION_NAME.toUpperCase() + \"\\\\(\", overrideDistinctCountFunction.toUpperCase() + \"\\\\(\");\n        }\n        return definition;\n    }\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(","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/query/PinotQueryGeneratorContext.java#L393-L429","documentation":"While building the column-index mapping from Pinot's output order to Presto's expected order, getIndicesMappingFromPinotSchemaToPrestoSchema looks up each group-by column in the accumulated selections. A missing definition means the group-by variable was never registered as a selection, indicating an internal inconsistency in the generated plan/context; it is thrown as IllegalStateException (no specific error code).","triggerScenarios":"A GROUP BY column variable is absent from the context's selections map, typically after a chain of project/aggregation nodes where the group-by column was renamed or derived but not added to selections before indices() is called.","commonSituations":"Queries grouping by an expression alias computed in a projection; connector/planner version mismatches where variable naming changed; internal bug reports rather than user-level query mistakes.","solutions":["Rewrite the query to group by a plain column reference from the table instead of a derived/renamed expression alias.","If derived grouping is needed, materialize it via a supported project pattern the connector recognizes, or fall back to Presto-side grouping.","Capture the query and the selections listed in the message and file a bug against the Pinot connector; this indicates a generator bug."],"exampleFix":"// before\nSELECT user_region AS region, count(*) FROM events GROUP BY region; // alias not in selections\n// after\nSELECT user_region, count(*) FROM events GROUP BY user_region;","handlingStrategy":"try-catch","validationCode":"// Prefer grouping by plain column references, not aliases of projections\n// Verify each GROUP BY term matches a base column name of the table\nboolean plain = groupByTerms.stream().allMatch(tableColumns::contains);\nif (!plain) { disablePushdown(); }","typeGuard":null,"tryCatchPattern":"try {\n    runQuery(sql);\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Group By column\")) {\n        runQueryWithoutPushdown(sql); // report bug + fallback\n    } else {\n        throw e;\n    }\n}","preventionTips":["Group by base table columns, not derived aliases.","Avoid relying on GROUP BY ordinal/alias of computed expressions on Pinot tables.","Report occurrences — this indicates a connector generator bug."],"tags":["pinot","pushdown","group-by","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"}