{"record":{"id":"e084a2d637bac69b","repo":"apache/beam","slug":"the-accumulators-cannot-be-merged-e-getmessage-e084a2","errorCode":null,"errorMessage":"The accumulators cannot be merged:${e.getMessage()}","messagePattern":"The accumulators cannot be merged:(.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sketching/src/main/java/org/apache/beam/sdk/extensions/sketching/SketchFrequencies.java","lineNumber":415,"sourceCode":"    @Override\n    public Sketch<InputT> addInput(Sketch<InputT> accumulator, InputT element) {\n      accumulator.add(element, inputCoder);\n\n      return accumulator;\n    }\n\n    @Override\n    public Sketch<InputT> mergeAccumulators(Iterable<Sketch<InputT>> accumulators) {\n      Iterator<Sketch<InputT>> it = accumulators.iterator();\n      Sketch<InputT> first = it.next();\n      CountMinSketch mergedSketches = first.sketch();\n      try {\n        while (it.hasNext()) {\n          mergedSketches = CountMinSketch.merge(mergedSketches, it.next().sketch());\n        }\n      } catch (FrequencyMergeException e) {\n        // Should never happen because every instantiated accumulator are of the same type.\n        throw new IllegalStateException(\"The accumulators cannot be merged:\" + e.getMessage());\n      }\n\n      return Sketch.create(mergedSketches);\n    }\n\n    /** Output the whole structure so it can be queried, reused or stored easily. */\n    @Override\n    public Sketch<InputT> extractOutput(Sketch<InputT> accumulator) {\n      return accumulator;\n    }\n\n    @Override\n    public Coder<Sketch<InputT>> getAccumulatorCoder(CoderRegistry registry, Coder inputCoder) {\n      return new CountMinSketchCoder<>();\n    }\n\n    @Override\n    public void populateDisplayData(DisplayData.Builder builder) {","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sketching/src/main/java/org/apache/beam/sdk/extensions/sketching/SketchFrequencies.java#L397-L433","documentation":"SketchFrequencies mergeAccumulators merges CountMinSketch instances via CountMinSketch.merge, which throws FrequencyMergeException when sketches were built with incompatible parameters (different depth/width/confidence). The code treats this as unreachable because all accumulators come from the same configured CountMinSketchFn, so it becomes an IllegalStateException indicating inconsistent accumulator state.","triggerScenarios":"Merging accumulators whose sketch parameters differ — practically only when accumulator state was persisted by a pipeline run using a different withAccuracy configuration or a different sketching-extension version and then merged in a resumed run.","commonSituations":"Streaming pipeline state upgraded between runs where epsilon/confidence changed; mixing checkpoints from jobs with different SketchFrequencies settings; dependency version drift of the sketching extension or stream-lib.","solutions":["Keep the withAccuracy(epsilon, confidence) configuration identical across pipeline restarts that resume stored state.","Pin the sketching extension (and stream-lib) version so serialized sketches remain compatible.","Discard old accumulator state and restart the job if the sketch configuration changed.","If reproducible with consistent configuration, report it as a Beam bug — this path should be unreachable."],"exampleFix":"// before\n.withAccuracy(0.05, 0.95) // changed after checkpoint was written with 0.01/0.999\n// after\n.withAccuracy(0.01, 0.999) // keep parameters stable across resuming runs, or start with fresh state","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { merged = CountMinSketch.merge(merged, next); } catch (FrequencyMergeException e) { /* restart with fresh state; should be unreachable */ }","preventionTips":["Keep withAccuracy parameters identical across stateful pipeline restarts","Pin sketching extension and stream-lib versions","Clear checkpointed state when changing sketch configuration"],"tags":["java","beam","sketching","count-min-sketch","merge"],"backgroundTag":"internal-invariant-violation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}