{"record":{"id":"8a4f36d82e181b0a","repo":"apache/beam","slug":"combine-groupedvalues-requires-its-input-values-to-use","errorCode":null,"errorMessage":"Combine.GroupedValues requires its input values to use IterableCoder","messagePattern":"Combine\\.GroupedValues requires its input values to use IterableCoder","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Combine.java","lineNumber":2297,"sourceCode":"    public AppliedCombineFn<? super K, ? super InputT, ?, OutputT> getAppliedFn(\n        CoderRegistry registry,\n        Coder<? extends KV<K, ? extends Iterable<InputT>>> inputCoder,\n        WindowingStrategy<?, ?> windowingStrategy) {\n      KvCoder<K, InputT> kvCoder = getKvCoder(inputCoder);\n      return AppliedCombineFn.withInputCoder(fn, registry, kvCoder, sideInputs, windowingStrategy);\n    }\n\n    private KvCoder<K, InputT> getKvCoder(\n        Coder<? extends KV<K, ? extends Iterable<InputT>>> inputCoder) {\n      if (!(inputCoder instanceof KvCoder)) {\n        throw new IllegalStateException(\"Combine.GroupedValues requires its input to use KvCoder\");\n      }\n      @SuppressWarnings({\"unchecked\", \"rawtypes\"})\n      KvCoder<K, ? extends Iterable<InputT>> kvCoder = (KvCoder) inputCoder;\n      Coder<K> keyCoder = kvCoder.getKeyCoder();\n      Coder<? extends Iterable<InputT>> kvValueCoder = kvCoder.getValueCoder();\n      if (!(kvValueCoder instanceof IterableCoder)) {\n        throw new IllegalStateException(\n            \"Combine.GroupedValues requires its input values to use \" + \"IterableCoder\");\n      }\n      @SuppressWarnings(\"unchecked\")\n      IterableCoder<InputT> inputValuesCoder = (IterableCoder<InputT>) kvValueCoder;\n      Coder<InputT> inputValueCoder = inputValuesCoder.getElemCoder();\n      return KvCoder.of(keyCoder, inputValueCoder);\n    }\n\n    @Override\n    public void populateDisplayData(DisplayData.Builder builder) {\n      super.populateDisplayData(builder);\n      Combine.populateDisplayData(builder, fn, fnDisplayData);\n    }\n  }\n}\n","sourceCodeStart":2279,"sourceCodeEnd":2313,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Combine.java#L2279-L2313","documentation":"Combine.GroupedValues requires the value side of the input KvCoder to be an IterableCoder, since its input is KV<K, Iterable<V>> after grouping. When the value coder is any other coder (e.g. a ListCoder, or a raw element coder), Beam throws IllegalStateException because it cannot extract the element coder needed to build the output coder.","triggerScenarios":"Applying Combine.GroupedValues to a KV collection whose value coder is not IterableCoder — e.g. manually setting the coder to ListCoder, or applying GroupedValues directly to KV<K, List<V>> built by a custom transform that coded values as a list rather than an Iterable.","commonSituations":"Custom transforms producing grouped values with List/Collection coders instead of IterableCoder; replacing the inferred coder after GroupByKey; misuse of GroupedValues on non-grouped data.","solutions":["Produce the input with GroupByKey so the value coder is IterableCoder<V>.","If setting coders manually, use IterableCoder.of(elemCoder) for the value side, not ListCoder.","Reorder: apply GroupedValues only to the output of GroupByKey (or GroupByKey-derived transforms like Combine.perKey).","For list-valued inputs, switch the value coder to IterableCoder.of(...), which GroupedValues recognizes."],"exampleFix":"// before\nkvInput.setCoder(KvCoder.of(StringUtf8Coder.of(), ListCoder.of(VarIntCoder.of())));\nkvInput.apply(Combine.groupedValues(sumFn));\n// after\nkvInput.setCoder(KvCoder.of(StringUtf8Coder.of(), IterableCoder.of(VarIntCoder.of())));\nkvInput.apply(Combine.groupedValues(sumFn));","handlingStrategy":"type-guard","validationCode":"Coder<?> valCoder = ((KvCoder<?,?>) grouped.getCoder()).getValueCoder(); if (!(valCoder instanceof IterableCoder)) { throw new IllegalStateException(\"value coder must be IterableCoder, got \" + valCoder); }","typeGuard":"boolean hasIterableValueCoder(PCollection<?> pc) { return pc.getCoder() instanceof KvCoder && ((KvCoder<?,?>) pc.getCoder()).getValueCoder() instanceof IterableCoder; }","tryCatchPattern":"try { grouped.apply(Combine.groupedValues(fn)); } catch (IllegalStateException e) { if (e.getMessage().contains(\"IterableCoder\")) { /* switch value coder to IterableCoder.of(elemCoder) */ } throw e; }","preventionTips":["Use IterableCoder (not ListCoder) for grouped-value collections","Keep GroupByKey as the producer of GroupedValues inputs","Assert coder types in pipeline-construction tests"],"tags":["java","apache-beam","combine","coder"],"backgroundTag":"incompatible-source-type","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}