{"record":{"id":"6ac6e32f3c86e0d3","repo":"apache/beam","slug":"pcollections-come-from-different-pipelines-pcollectiontuple","errorCode":null,"errorMessage":"PCollections come from different Pipelines","messagePattern":"PCollections come from different Pipelines","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/values/PCollectionTuple.java","lineNumber":175,"sourceCode":"    return of(tag1, pc1, tag2, pc2, tag3, pc3, tag4, pc4).and(tag5, pc5);\n  }\n\n  // To create a PCollectionTuple with more than five inputs, use the and() builder method.\n\n  /**\n   * Returns a new {@link PCollectionTuple} that has each {@link PCollection} and {@link TupleTag}\n   * of this {@link PCollectionTuple} plus the given {@link PCollection} associated with the given\n   * {@link TupleTag}.\n   *\n   * <p>The given {@link TupleTag} should not already be mapped to a {@link PCollection} in this\n   * {@link PCollectionTuple}.\n   *\n   * <p>Each {@link PCollection} in the resulting {@link PCollectionTuple} must be part of the same\n   * {@link Pipeline}.\n   */\n  public <T> PCollectionTuple and(TupleTag<T> tag, PCollection<T> pc) {\n    if (pc.getPipeline() != pipeline) {\n      throw new IllegalArgumentException(\"PCollections come from different Pipelines\");\n    }\n\n    return new PCollectionTuple(\n        pipeline,\n        new ImmutableMap.Builder<TupleTag<?>, PCollection<?>>()\n            .putAll(pcollectionMap)\n            .put(tag, pc)\n            .build());\n  }\n\n  /**\n   * A version of {@link #and(TupleTag, PCollection)} that takes in a String instead of a TupleTag.\n   *\n   * <p>This method is simpler for cases when a typed tuple-tag is not needed to extract a\n   * PCollection, for example when using schema transforms.\n   */\n  public <T> PCollectionTuple and(String tag, PCollection<T> pc) {\n    return and(new TupleTag<>(tag), pc);","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/values/PCollectionTuple.java#L157-L193","documentation":"PCollectionTuple.and verified that the appended PCollection belongs to the same Pipeline instance as the existing tuple entries; it did not, so the tuple would be internally inconsistent (a pipeline proto cannot reference PCollections from another Pipeline). The incoming PCollection from the different Pipeline is the input at fault.","triggerScenarios":"Adding a PCollection from a different Pipeline instance to a PCollectionTuple via and(tag, pc), including recursive calls from mapToTuple-style helpers.","commonSituations":"Assembling multi-output transforms where some outputs were computed on a different Pipeline; unit tests mixing a TestPipeline with a programmatically created Pipeline.","solutions":["Create all PCollections from the same Pipeline instance as the tuple","Derive the PCollection from tuple.getPipeline() when adding new outputs","Refactor helpers to accept and use a single Pipeline argument"],"exampleFix":"// before\ntuple.and(tag, pcBuiltOnOtherPipeline); // throws\n// after\nPCollection<T> pc = tuple.getPipeline().apply(...);\ntuple.and(tag, pc);","handlingStrategy":"validation","validationCode":"if (pc.getPipeline() != tuple.getPipeline()) { throw new IllegalArgumentException(\"wrong pipeline\"); }","typeGuard":"boolean samePipeline(PCollection<?> pc, PCollectionTuple t) { return pc.getPipeline() == t.getPipeline(); }","tryCatchPattern":"try { return tuple.and(tag, pc); } catch (IllegalArgumentException e) { /* re-create pc on tuple's pipeline */ }","preventionTips":["Use one Pipeline instance for all tuple members","In tests, use TestPipeline consistently, not ad-hoc Pipelines","Validate pipeline identity in multi-output transform helpers"],"tags":["java","apache-beam","pipeline","illegal-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-15T13:17:12.816Z"}