prestodb/presto · error · IllegalStateException

Output column (%s) definition not found in input selections:

Error message

Output column (%s) definition not found in input selections: %s

What it means

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.

Source

Thrown at presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/query/PinotQueryGeneratorContext.java:421

    }

    private List<Integer> getIndicesMappingFromPinotSchemaToPrestoSchema(String query, Map<VariableReferenceExpression, PinotColumnHandle> assignments)
    {
        LinkedHashMap<VariableReferenceExpression, Selection> expressionsInPinotOrder = new LinkedHashMap<>();
        for (VariableReferenceExpression groupByColumn : groupByColumns) {
            Selection groupByColumnDefinition = selections.get(groupByColumn);
            if (groupByColumnDefinition == null) {
                throw new IllegalStateException(format(
                        "Group By column (%s) definition not found in input selections: %s",
                        groupByColumn,
                        Joiner.on(",").withKeyValueSeparator(":").join(selections)));
            }
            expressionsInPinotOrder.put(groupByColumn, groupByColumnDefinition);
        }
        for (VariableReferenceExpression outputColumn : outputs) {
            Selection outputColumnDefinition = selections.get(outputColumn);
            if (outputColumnDefinition == null) {
                throw new IllegalStateException(format(
                        "Output column (%s) definition not found in input selections: %s",
                        outputColumn,
                        Joiner.on(",").withKeyValueSeparator(":").join(selections)));
            }
            expressionsInPinotOrder.put(outputColumn, outputColumnDefinition);
        }

        checkSupported(
                assignments.size() <= expressionsInPinotOrder.keySet().stream().filter(key -> !hiddenColumnSet.contains(key)).count(),
                "Expected returned expressions %s is a superset of selections %s",
                Joiner.on(",").withKeyValueSeparator(":").join(expressionsInPinotOrder),
                Joiner.on(",").withKeyValueSeparator("=").join(assignments));

        Map<VariableReferenceExpression, Integer> assignmentToIndex = new HashMap<>();
        Iterator<Map.Entry<VariableReferenceExpression, PinotColumnHandle>> assignmentsIterator = assignments.entrySet().iterator();
        for (int i = 0; i < assignments.size(); i++) {
            VariableReferenceExpression key = assignmentsIterator.next().getKey();
            Integer previous = assignmentToIndex.put(key, i);

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Simplify the SELECT list to plain columns and supported aggregates over table columns.
  2. Retry with a query that avoids derived output expressions so every output maps to a known selection.
  3. Inspect the 'Output column (%s) definition not found' payload and file a bug with the query if a plain column reference triggers it.

Example fix

// before
SELECT upper(user_region) AS r, count(*) FROM events GROUP BY 1;
// after
SELECT user_region, count(*) FROM events GROUP BY user_region;
Defensive patterns

Strategy: try-catch

Validate before calling

// Keep SELECT lists to plain columns and supported aggregates so every output has a selection
boolean outputsResolvable = selectTerms.stream().allMatch(t -> tableColumns.contains(t) || isSupportedAggregate(t));
if (!outputsResolvable) { disablePushdown(); }

Try / catch

try {
    runQuery(sql);
} catch (IllegalStateException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Output column")) {
        runQueryWithoutPushdown(sql);
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/5536ea89ebe8ab2a. Report an issue: GitHub.