prestodb/presto · error · PrestoException

FUNCTION_IMPLEMENTATION_ERROR

FUNCTION_IMPLEMENTATION_ERROR

Error message

expected group enum type %s

What it means

HistogramStateFactory.createGroupedState selects the group-state implementation based on a HistogramGroupMode enum. If the mode is neither NEW nor LEGACY (an unexpected/unhandled enum value, e.g. from a stale serialized state factory or an internal bug), the factory cannot instantiate state and throws FUNCTION_IMPLEMENTATION_ERROR — a signal of an internal implementation inconsistency rather than user input error.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/histogram/HistogramStateFactory.java:65

    @Override
    public Class<? extends HistogramState> getSingleStateClass()
    {
        return SingleHistogramState.class;
    }

    @Override
    public HistogramState createGroupedState()
    {
        if (mode == NEW) {
            return new GroupedHistogramState(keyType, expectedEntriesCount);
        }

        if (mode == LEGACY) {
            return new LegacyHistogramGroupState(keyType, expectedEntriesCount);
        }

        throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, format("expected group enum type %s", mode));
    }

    @Override
    public Class<? extends HistogramState> getGroupedStateClass()
    {
        if (mode == NEW) {
            return GroupedHistogramState.class;
        }

        if (mode == LEGACY) {
            return LegacyHistogramGroupState.class;
        }

        throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, format("expected group enum type %s", mode));
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Restart the cluster so all nodes run the same Presto version.
  2. Invalidate cached plans / retry the query; report a bug if it reproduces on a uniform version.
  3. Ensure coordinator and workers are not mixed across versions during upgrade.

Example fix

// before
// enum has new value but factory only handles NEW/LEGACY
// after
if (mode == NEW) { ... } else if (mode == LEGACY) { ... } else if (mode == NEW_VALUE) { ... } else { throw ... }
Defensive patterns

Strategy: try-catch

Validate before calling

-- ensure uniform Presto versions
-- run `SELECT node_version FROM system.runtime.nodes;` and confirm a single version

Try / catch

try { result = query(...); } catch (PrestoException e) { if (e.getErrorCode().getName().equals("FUNCTION_IMPLEMENTATION_ERROR")) { /* retry after version alignment / plan cache clear */ } else { throw e; } }

Prevention

When it happens

Trigger: createGroupedState invoked with a HistogramGroupMode other than NEW or LEGACY, typically from an incompatibly serialized plan/state or an internal regression adding a new enum constant without updating this switch.

Common situations: Rolling upgrades where a coordinator/worker version mismatch introduces a new mode; stale cached plans referencing an old/new histogram implementation.

Related errors


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