{"record":{"id":"23673dc0d11b1965","repo":"apache/beam","slug":"must-have-at-least-one-input-to-a-keyedpcollections","errorCode":null,"errorMessage":"must have at least one input to a KeyedPCollections","messagePattern":"must have at least one input to a KeyedPCollections","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/join/CoGroupByKey.java","lineNumber":87,"sourceCode":" * @param <K> the type of the keys in the input and output {@code PCollection}s\n */\npublic class CoGroupByKey<K>\n    extends PTransform<KeyedPCollectionTuple<K>, PCollection<KV<K, CoGbkResult>>> {\n  /**\n   * Returns a {@code CoGroupByKey<K>} {@code PTransform}.\n   *\n   * @param <K> the type of the keys in the input and output {@code PCollection}s\n   */\n  public static <K> CoGroupByKey<K> create() {\n    return new CoGroupByKey<>();\n  }\n\n  private CoGroupByKey() {}\n\n  @Override\n  public PCollection<KV<K, CoGbkResult>> expand(KeyedPCollectionTuple<K> input) {\n    if (input.isEmpty()) {\n      throw new IllegalArgumentException(\"must have at least one input to a KeyedPCollections\");\n    }\n\n    // First build the union coder.\n    // TODO: Look at better integration of union types with the\n    // schema specified in the input.\n    List<Coder<?>> codersList = new ArrayList<>();\n    for (TaggedKeyedPCollection<K, ?> entry : input.getKeyedCollections()) {\n      codersList.add(getValueCoder(entry.pCollection));\n    }\n    UnionCoder unionCoder = UnionCoder.of(codersList);\n    Coder<K> keyCoder = input.getKeyCoder();\n    KvCoder<K, RawUnionValue> kVCoder = KvCoder.of(keyCoder, unionCoder);\n\n    PCollectionList<KV<K, RawUnionValue>> unionTables = PCollectionList.empty(input.getPipeline());\n\n    // TODO: Use the schema to order the indices rather than depending\n    // on the fact that the schema ordering is identical to the ordering from\n    // input.getJoinCollections().","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/join/CoGroupByKey.java#L69-L105","documentation":"CoGroupByKey.expand was given an empty KeyedPCollectionTuple: a cogroup by definition joins two or more tagged keyed collections, and with zero inputs there is nothing to group and no output schema could be derived. The empty KeyedPCollectionTuple input is at fault.","triggerScenarios":"Applying CoGroupByKey.create() to an empty KeyedPCollectionTuple, e.g. building the tuple in a loop that added zero PCollections (all inputs filtered out or list empty).","commonSituations":"Dynamic pipeline construction where collections are conditionally added; an upstream branch yielded no PCollections to join.","solutions":["Check input.isEmpty() before applying CoGroupByKey and skip the transform","Ensure at least one KeyedPCollectionTuple.and(tag, pc) call always executes","Restructure the pipeline to a default branch when no inputs are available"],"exampleFix":"// before\nPCollection<KV<K, CoGbkResult>> r = input.apply(CoGroupByKey.create());\n// after\nif (!input.isEmpty()) {\n  PCollection<KV<K, CoGbkResult>> r = input.apply(CoGroupByKey.create());\n}","handlingStrategy":"validation","validationCode":"if (input == null || input.isEmpty()) { throw new IllegalArgumentException(\"CoGroupByKey requires at least one input\"); }","typeGuard":null,"tryCatchPattern":"try { return input.apply(CoGroupByKey.create()); } catch (IllegalArgumentException e) { /* handle empty tuple */ }","preventionTips":["Check isEmpty() before applying the transform","Ensure at least one and() call is unconditional in builders","Log builder state when assembling tuples dynamically"],"tags":["beam","cogroupbykey","empty-input","illegal-argument"],"backgroundTag":"missing-required-argument","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"}