{"record":{"id":"65be091e2427a7d1","repo":"apache/beam","slug":"the-accumulators-cannot-be-merged-e-getmessage","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/ApproximateDistinct.java","lineNumber":478,"sourceCode":"      }\n      return acc;\n    }\n\n    /** Output the whole structure so it can be queried, reused or stored easily. */\n    @Override\n    public HyperLogLogPlus extractOutput(HyperLogLogPlus accumulator) {\n      return accumulator;\n    }\n\n    @Override\n    public HyperLogLogPlus mergeAccumulators(Iterable<HyperLogLogPlus> accumulators) {\n      HyperLogLogPlus mergedAccum = createAccumulator();\n      for (HyperLogLogPlus accum : accumulators) {\n        try {\n          mergedAccum.addAll(accum);\n        } catch (CardinalityMergeException e) {\n          // Should never happen because only HyperLogLogPlus accumulators are instantiated.\n          throw new IllegalStateException(\n              \"The accumulators cannot be merged: \" + e.getMessage(), e);\n        }\n      }\n      return mergedAccum;\n    }\n\n    @Override\n    public void populateDisplayData(DisplayData.Builder builder) {\n      super.populateDisplayData(builder);\n      builder\n          .add(DisplayData.item(\"p\", p).withLabel(\"precision\"))\n          .add(DisplayData.item(\"sp\", sp).withLabel(\"sparse representation precision\"));\n    }\n  }\n\n  /** Coder for {@link HyperLogLogPlus} class. */\n  public static class HyperLogLogPlusCoder extends CustomCoder<HyperLogLogPlus> {\n","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sketching/src/main/java/org/apache/beam/sdk/extensions/sketching/ApproximateDistinct.java#L460-L496","documentation":"ApproximateDistinctFn.mergeAccumulators merges HyperLogLogPlus accumulators via addAll, which can throw CardinalityMergeException when sketches have incompatible parameters (different p/sp registers). The code comments this 'should never happen' because only HyperLogLogPlus accumulators are instantiated, so the IllegalStateException signals an internal invariant violation.","triggerScenarios":"Merging accumulators that were created with different precision/bias parameters — practically only when accumulator state was deserialized from data written with a different configuration (changed p2 parameter or sketch version between pipeline runs).","commonSituations":"Resuming/updating a streaming pipeline whose stored accumulator state was produced by a different version of the sketching extension or with different HLL++ parameters; mixing sketch outputs from jobs with different configs.","solutions":["Do not mix accumulator state from pipeline versions with different ApproximateDistinct configuration; restart with fresh state.","Keep the sketching extension version consistent between save and restore of streaming state.","If reproducible, file a Beam issue — this path is expected to be unreachable."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { mergedAccum.addAll(accum); } catch (CardinalityMergeException e) { /* restart with fresh state; should be unreachable */ }","preventionTips":["Do not reuse accumulator state across configuration/version changes","Pin Beam sketching extension versions","Treat this exception as a bug report trigger, not a handled case"],"tags":["java","beam","sketching","hyperloglog","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"}