prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

e.getMessage()

What it means

The SfmSketchMergeAggregation @InputFunction merges an incoming sketch into the state's sketch. If the sketches are incompatible (different bucket count/size), mergeSketch throws IllegalArgumentException, which is caught and rethrown as INVALID_FUNCTION_ARGUMENT with the original message.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/noisyaggregation/SfmSketchMergeAggregation.java:53

    @InputFunction
    public static void input(@AggregationState SfmSketchState state, @SqlType(SfmSketchType.NAME) Slice value)
    {
        SfmSketch sketch = SfmSketch.deserialize(value);
        SfmSketch previous = state.getSketch();
        if (previous == null) {
            // if state sketch is empty, add this sketch to the state
            state.setSketch(sketch);
            state.setEpsilon(0); // not used
        }
        else {
            // if state already has a sketch, merge in the current sketch
            try {
                // throws if the sketches are incompatible (e.g., different bucket count/size)
                state.mergeSketch(sketch);
            }
            catch (IllegalArgumentException e) {
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
            }
        }
    }

    @CombineFunction
    public static void combine(@AggregationState SfmSketchState state, @AggregationState SfmSketchState otherState)
    {
        SfmSketchAggregationUtils.mergeStates(state, otherState);
    }

    @OutputFunction(SfmSketchType.NAME)
    public static void output(@AggregationState SfmSketchState state, BlockBuilder out)
    {
        VARBINARY.writeSlice(out, state.getSketch().serialize());
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Regenerate all sketches with the same bucket count/size configuration
  2. Verify sketch construction parameters across data producers
  3. Catch this error in the client and surface which job produced the mismatched sketch

Example fix

// before
INSERT INTO t VALUES (sfm_sketch(x, buckets=1024)); -- later aggregated with buckets=2048 inputs
// after
INSERT INTO t VALUES (sfm_sketch(x, buckets=2048));
Defensive patterns

Strategy: validation

Validate before calling

// verify sketch inputs share parameters before aggregating
if (!sketchA.sameParameters(sketchB)) throw new IllegalStateException("sketch params differ");

Try / catch

try { rows.stream().collect(sfSketchCollector); } catch (PrestoException e) { if (e.getMessage().contains("bucket")) { rebuildSketchsWithUniformConfig(); } else throw e; }

Prevention

When it happens

Trigger: Calling the sfm sketch aggregation (@InputFunction input) over rows whose sketch values were built with different bucket counts or sizes.

Common situations: Sketches from jobs with different configurations, or sketch columns populated across schema/config changes, aggregated in one query.

Related errors


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