{"record":{"id":"dd3d1ba32042b4b2","repo":"apache/beam","slug":"input-must-be-pbegin-or-pcollection","errorCode":null,"errorMessage":"input must be PBegin or PCollection","messagePattern":"input must be PBegin or PCollection","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerIO.java","lineNumber":1247,"sourceCode":"  public abstract static class CreateTransaction\n      extends PTransform<PInput, PCollectionView<Transaction>> {\n\n    abstract SpannerConfig getSpannerConfig();\n\n    abstract @Nullable TimestampBound getTimestampBound();\n\n    abstract Builder toBuilder();\n\n    @Override\n    public PCollectionView<Transaction> expand(PInput input) {\n      getSpannerConfig().validate();\n\n      PCollection<?> collection = input.getPipeline().apply(Create.of(1));\n\n      if (input instanceof PCollection) {\n        collection = collection.apply(Wait.on((PCollection<?>) input));\n      } else if (!(input instanceof PBegin)) {\n        throw new RuntimeException(\"input must be PBegin or PCollection\");\n      }\n\n      return collection\n          .apply(\n              \"Create transaction\",\n              ParDo.of(new CreateTransactionFn(this.getSpannerConfig(), this.getTimestampBound())))\n          .apply(\"As PCollectionView\", View.asSingleton());\n    }\n\n    /** Specifies the Cloud Spanner configuration. */\n    public CreateTransaction withSpannerConfig(SpannerConfig spannerConfig) {\n      return toBuilder().setSpannerConfig(spannerConfig).build();\n    }\n\n    /** Specifies the Cloud Spanner project. */\n    public CreateTransaction withProjectId(String projectId) {\n      return withProjectId(ValueProvider.StaticValueProvider.of(projectId));\n    }","sourceCodeStart":1229,"sourceCodeEnd":1265,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerIO.java#L1229-L1265","documentation":"SpannerIO.CreateTransaction accepts input only of type PBegin (no signal) or PCollection (used as a Wait signal before creating the read-only transaction). Any other PInput type triggers RuntimeException 'input must be PBegin or PCollection'. The type check is done with instanceof in SpannerIO's public inner transform.","triggerScenarios":"Applying CreateTransaction (e.g. via SpannerIO.createTransaction() chained off a PCollectionList, PBegin-derived custom input, or a tagged/multiple-output result) that is neither PBegin nor PCollection.","commonSituations":"Chaining createTransaction after a transform that returns PCollectionTuple or a multi-output POutput; passing a PCollectionList; wiring Wait signals incorrectly.","solutions":["Apply SpannerIO.createTransaction() directly on pipeline.begin() (PBegin) or a single PCollection","Use Wait.on(pcollection) by passing the PCollection, or apply the transform to a PBegin and combine with Wait","Unwrap the desired PCollection from multi-output results before applying"],"exampleFix":"// before\npipeline.apply(multiOutputTransform).apply(SpannerIO.createTransaction());\n// after\nPCollection<T> out = pipeline.apply(multiOutputTransform).get(mainTag);\nout.apply(Wait.on(out)) /* via SpannerIO.read().withWait... */ ;","handlingStrategy":"type-guard","validationCode":"if (!(input instanceof PBegin) && !(input instanceof PCollection)) {\n  throw new IllegalArgumentException(\"CreateTransaction input must be PBegin or PCollection\");\n}","typeGuard":"boolean validCreateTransactionInput(PInput in) { return in instanceof PBegin || in instanceof PCollection; }","tryCatchPattern":"try { in.apply(SpannerIO.createTransaction()); } catch (RuntimeException e) { /* unwrap correct PCollection and retry */ }","preventionTips":["Apply createTransaction only to pipeline.begin() or a single PCollection","Unwrap PCollectionTuple/multi-output results first","Use Wait.on(pcollection) rather than passing composite inputs"],"tags":["java","beam","type-mismatch","pipeline"],"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-14T16:17:12.679Z"}