prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

%s

What it means

SfmSketchAggregationUtils.mergeStates merges two Sfm (single-frequent/min-count sketch) states during aggregation. state.mergeSketch throws IllegalArgumentException when the two sketches are structurally incompatible (different bucket counts or bucket size); the library catches it and rewraps it as INVALID_FUNCTION_ARGUMENT.

Source

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

        return hash;
    }

    public static void mergeStates(SfmSketchState state, SfmSketchState otherState)
    {
        SfmSketch sketch = state.getSketch();
        SfmSketch otherSketch = otherState.getSketch();
        if (sketch == null) {
            state.setSketch(otherSketch);
            state.setEpsilon(otherState.getEpsilon());
        }
        else {
            try {
                // Throws if the sketches are incompatible (e.g., different bucket counts/size)
                // Catch and throw a PrestoException
                state.mergeSketch(otherSketch);
            }
            catch (IllegalArgumentException e) {
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
            }
        }
    }

    public static void writeCardinality(SfmSketchState state, BlockBuilder out)
    {
        SfmSketch sketch = state.getSketch();
        if (sketch == null) {
            // In the event we process no rows, output NULL.
            // Note: Although the SfmSketch is differentially private, this particular output is not.
            // We cannot output anything DP here because the state will not include epsilon if we processed no rows.
            out.appendNull();
        }
        else {
            sketch.enablePrivacy(state.getEpsilon());
            BIGINT.writeLong(out, sketch.cardinality());
        }
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Ensure all sfm sketches aggregated together use identical bucket count and bucket size parameters
  2. Rebuild/recompute the sketches with a single consistent configuration
  3. Check the serialized sketch metadata for each source to find the mismatched parameter set

Example fix

// before
SELECT sfm_sketch_agg(cardinality Sketch, 0.01) FROM t1 -- buckets=1024
UNION ALL ... then re-aggregate with buckets=2048 sketch
// after
Use the same bucket count/size parameters in every job that produces the sketches
Defensive patterns

Strategy: validation

Validate before calling

// ensure all sketch-producing jobs share the same config
assert config1.bucketCount == config2.bucketCount && config1.bucketSize == config2.bucketSize;

Try / catch

try { query.run(); } catch (PrestoException e) { if (e.getErrorCode().getName().equals("INVALID_FUNCTION_ARGUMENT") && e.getCause() instanceof IllegalArgumentException) { logSketchConfigMismatch(e); } else throw e; }

Prevention

When it happens

Trigger: Aggregating sfm sketches created with different sketch parameters (bucket count/width, seed) in one GROUP BY, invoked from mergeStates during intermediate-state combination.

Common situations: Rows produced by two different queries/jobs with different sketch configurations fed into one aggregation; parameter changed between runs and states combined in a later query.

Related errors


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