prestodb/presto · error · PrestoException

INVALID_ARGUMENTS

INVALID_ARGUMENTS

Error message

Missing field reference for expression

What it means

checkAndGetColumnReferenceField looks up the FieldId recorded for an expression node in the analysis-produced columnReferences multimap. If the expression node is absent from that map — it was never resolved as a column reference — it throws PrestoException INVALID_ARGUMENTS 'Missing field reference for expression'. This is an internal consistency check, typically reached via GROUPING or similar operations that require column references.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/ExpressionTreeUtils.java:177

        }
        return Optional.empty();
    }

    public static Object resolveEnumLiteral(DereferenceExpression node, Type nodeType)
    {
        QualifiedName qualifiedName = DereferenceExpression.getQualifiedName(node);

        EnumType enumType = (EnumType) ((TypeWithName) nodeType).getType();
        String enumKey = qualifiedName.getSuffix().toUpperCase(ENGLISH);
        checkArgument(enumType.getEnumMap().containsKey(enumKey), format("No key '%s' in enum '%s'", enumKey, nodeType.getDisplayName()));
        Object enumValue = enumType.getEnumMap().get(enumKey);
        return enumValue instanceof String ? utf8Slice((String) enumValue) : enumValue;
    }

    public static FieldId checkAndGetColumnReferenceField(Expression expression, Multimap<NodeRef<Expression>, FieldId> columnReferences)
    {
        if (!columnReferences.containsKey(NodeRef.of(expression))) {
            throw new PrestoException(INVALID_ARGUMENTS, "Missing field reference for expression");
        }
        if (columnReferences.get(NodeRef.of(expression)).size() != 1) {
            throw new PrestoException(INVALID_ARGUMENTS, "Multiple field references for expression");
        }

        return columnReferences.get(NodeRef.of(expression)).iterator().next();
    }

    public static boolean isNonNullConstant(Expression expression)
    {
        Expression tempExpression = expression;
        while (tempExpression instanceof Cast) {
            tempExpression = ((Cast) tempExpression).getExpression();
        }

        if (tempExpression instanceof NullLiteral) {
            return false;
        }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Ensure the argument is a plain column reference that appears in GROUP BY / GROUPING SETS
  2. Verify the analysis produced columnReferences containing the node (NodeRef.of(expression))
  3. In custom code, guard with columnReferences.containsKey(NodeRef.of(expression)) before calling

Example fix

// before
FieldId id = checkAndGetColumnReferenceField(someDerivedExpr, columnReferences);
// after
NodeRef<Expression> ref = NodeRef.of(someDerivedExpr);
if (!columnReferences.containsKey(ref)) {
    throw new PrestoException(INVALID_ARGUMENTS, "expression is not a grouping column");
}
FieldId id = checkAndGetColumnReferenceField(someDerivedExpr, columnReferences);
Defensive patterns

Strategy: validation

Validate before calling

NodeRef<Expression> ref = NodeRef.of(expr);
if (!columnReferences.containsKey(ref)) {
    throw new PrestoException(INVALID_ARGUMENTS, "expression has no resolved column reference");
}

Type guard

boolean hasSingleField(Expression e, Multimap<NodeRef<Expression>, FieldId> refs) {
    return refs.containsKey(NodeRef.of(e));
}

Try / catch

try {
    FieldId id = checkAndGetColumnReferenceField(expr, columnReferences);
} catch (PrestoException e) {
    if (e.getErrorCode().getCode() == INVALID_ARGUMENTS.toErrorCode().getCode()) {
        throw new IllegalStateException("Expected a resolved grouping column, got: " + expr, e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling checkAndGetColumnReferenceField with an expression that is not a resolved column reference (e.g. an arbitrary expression or an alias, not a plain column), often via GROUPING argument processing where arguments must be grouping columns.

Common situations: GROUPING(<expr>) applied to something that is not a column listed in GROUP BY; optimizer/planner code (or plugins) invoking the helper on non-column expressions.

Related errors


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