prestodb/presto · error · UnsupportedOperationException

LEARN must run on a single machine

Error message

LEARN must run on a single machine

What it means

LearnClassifierAggregation.combine (the @CombineFunction for LEARN) unconditionally throws UnsupportedOperationException because training a LibSVM classifier cannot be partitioned — partial aggregation states cannot be merged across machines. The LEARN aggregation must therefore execute entirely on one node.

Source

Thrown at presto-ml/src/main/java/com/facebook/presto/ml/LearnClassifierAggregation.java:55

            @SqlType(BIGINT) long label,
            @SqlType("map(bigint,double)") Block features)
    {
        input(state, (double) label, features);
    }

    @InputFunction
    public static void input(
            @AggregationState LearnState state,
            @SqlType(DOUBLE) double label,
            @SqlType("map(bigint,double)") Block features)
    {
        LearnLibSvmClassifierAggregation.input(state, label, features, Slices.utf8Slice(""));
    }

    @CombineFunction
    public static void combine(@AggregationState LearnState state, @AggregationState LearnState otherState)
    {
        throw new UnsupportedOperationException("LEARN must run on a single machine");
    }

    @OutputFunction("Classifier<bigint>")
    public static void output(@AggregationState LearnState state, BlockBuilder out)
    {
        LearnLibSvmClassifierAggregation.output(state, out);
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Force single-node execution for the query, e.g. session properties/plan hints that keep the aggregation on one worker (or run against a single-node cluster).
  2. Set the aggregation to run partially... no — instead ensure the aggregation isn't split: use session property query.max-run-time-safe... concretely, restrict execution with 'single_node' style session configuration available in your Presto version.
  3. Reduce input size (sample the training data) so single-node execution is feasible.
  4. Use a training path that supports distributed execution if available in your Presto version.

Example fix

-- before (distributed)
SELECT LEARN(label, features) FROM training_data;
-- after (pin to one node where supported)
SET SESSION query_execution_policy = SINGLE_NODE; -- or run on a single-worker cluster
SELECT LEARN(label, features) FROM training_data;
Defensive patterns

Strategy: validation

Validate before calling

// pre-check plan/cluster before running LEARN
if (workerCount > 1 && !singleNodeSessionConfigured) throw new IllegalStateException("LEARN requires single-node execution");

Try / catch

try { runLearnQuery() } catch (UnsupportedOperationException e) { if (e.getMessage().contains("LEARN must run on a single machine")) { rerunSingleNode(); } else throw e; }

Prevention

When it happens

Trigger: Running SELECT LEARN(label, features) ... on a distributed plan where the aggregation is split into partial/final stages across workers, so combine() gets invoked.

Common situations: Large training datasets where the planner parallelizes the aggregation; clusters where session singleNode/single-thread constraints are absent; users upgrading Presto and hitting the restriction on multi-worker setups.

Related errors


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