{"record":{"id":"6717943a8b30f159","repo":"prestodb/presto","slug":"invalid-function-argument-671794","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"%s","messagePattern":"%s","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/noisyaggregation/SfmSketchAggregationUtils.java","lineNumber":121,"sourceCode":"        return hash;\n    }\n\n    public static void mergeStates(SfmSketchState state, SfmSketchState otherState)\n    {\n        SfmSketch sketch = state.getSketch();\n        SfmSketch otherSketch = otherState.getSketch();\n        if (sketch == null) {\n            state.setSketch(otherSketch);\n            state.setEpsilon(otherState.getEpsilon());\n        }\n        else {\n            try {\n                // Throws if the sketches are incompatible (e.g., different bucket counts/size)\n                // Catch and throw a PrestoException\n                state.mergeSketch(otherSketch);\n            }\n            catch (IllegalArgumentException e) {\n                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);\n            }\n        }\n    }\n\n    public static void writeCardinality(SfmSketchState state, BlockBuilder out)\n    {\n        SfmSketch sketch = state.getSketch();\n        if (sketch == null) {\n            // In the event we process no rows, output NULL.\n            // Note: Although the SfmSketch is differentially private, this particular output is not.\n            // We cannot output anything DP here because the state will not include epsilon if we processed no rows.\n            out.appendNull();\n        }\n        else {\n            sketch.enablePrivacy(state.getEpsilon());\n            BIGINT.writeLong(out, sketch.cardinality());\n        }\n    }","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/noisyaggregation/SfmSketchAggregationUtils.java#L103-L139","documentation":"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.","triggerScenarios":"Aggregating sfm sketches created with different sketch parameters (bucket count/width, seed) in one GROUP BY, invoked from mergeStates during intermediate-state combination.","commonSituations":"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.","solutions":["Ensure all sfm sketches aggregated together use identical bucket count and bucket size parameters","Rebuild/recompute the sketches with a single consistent configuration","Check the serialized sketch metadata for each source to find the mismatched parameter set"],"exampleFix":"// before\nSELECT sfm_sketch_agg(cardinality Sketch, 0.01) FROM t1 -- buckets=1024\nUNION ALL ... then re-aggregate with buckets=2048 sketch\n// after\nUse the same bucket count/size parameters in every job that produces the sketches","handlingStrategy":"validation","validationCode":"// ensure all sketch-producing jobs share the same config\nassert config1.bucketCount == config2.bucketCount && config1.bucketSize == config2.bucketSize;","typeGuard":null,"tryCatchPattern":"try { query.run(); } catch (PrestoException e) { if (e.getErrorCode().getName().equals(\"INVALID_FUNCTION_ARGUMENT\") && e.getCause() instanceof IllegalArgumentException) { logSketchConfigMismatch(e); } else throw e; }","preventionTips":["Centralize sketch configuration in one shared constants module","Version sketch columns with their parameters in metadata","Rebuild all sketches after changing bucket parameters"],"tags":["presto","aggregation","sketch","argument-validation"],"backgroundTag":"incompatible-sketch-merge","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}