{"record":{"id":"6ebe3d51b3f223eb","repo":"apache/beam","slug":"cannot-use-beampcollectiontable-as-target","errorCode":null,"errorMessage":"cannot use [BeamPCollectionTable] as target","messagePattern":"cannot use \\[BeamPCollectionTable\\] as target","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/schema/BeamPCollectionTable.java","lineNumber":55,"sourceCode":"      throw new IllegalArgumentException(\"SQL can only run over PCollections that have schemas.\");\n    }\n    this.upstream = upstream;\n  }\n\n  @Override\n  public PCollection.IsBounded isBounded() {\n    return upstream.isBounded();\n  }\n\n  @Override\n  public PCollection<Row> buildIOReader(PBegin begin) {\n    assert begin.getPipeline() == upstream.getPipeline();\n    return upstream.apply(Convert.toRows());\n  }\n\n  @Override\n  public POutput buildIOWriter(PCollection<Row> input) {\n    throw new IllegalArgumentException(\"cannot use [BeamPCollectionTable] as target\");\n  }\n}\n","sourceCodeStart":37,"sourceCodeEnd":58,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/schema/BeamPCollectionTable.java#L37-L58","documentation":"BeamPCollectionTable is read-only: it wraps an in-memory PCollection that already exists, so there is no way to write query results back into it. buildIOWriter therefore always throws IllegalArgumentException.","triggerScenarios":"Executing an INSERT or CREATE TABLE AS SELECT with a registered BeamPCollectionTable as the sink; using sqlContext.executeInsert or similar write APIs targeting this table type.","commonSituations":"Users assuming any registered table can be a write target; trying to persist query output back into the original in-memory PCollection.","solutions":["Write results to a real sink table (e.g. BeamTextTable or a file/database IO) instead","Collect results via PCollection output of sqlContext.executeQuery and handle them programmatically","Register a writable BeamTable implementation as the target"],"exampleFix":"// before\nsqlContext.executeInsert(\"pcollection_table\", \"INSERT INTO pcollection_table SELECT ...\")\n// after\nPCollection<Row> result = sqlContext.executeQuery(\"SELECT ...\");\nresult.apply(TextIO.write().to(\"/output\"));","handlingStrategy":"validation","validationCode":"if (table instanceof BeamPCollectionTable) { throw new UnsupportedOperationException(\"choose a writable sink table\"); }","typeGuard":"boolean isWritable(BeamTable t) { return !(t instanceof BeamPCollectionTable); }","tryCatchPattern":"try { sqlContext.executeInsert(...) } catch (IllegalArgumentException e) { /* redirect output to file/db sink */ }","preventionTips":["Never target BeamPCollectionTable in INSERT statements","Use BeamTextTable or database IO tables as sinks","Materialize query results via executeQuery PCollection output"],"tags":["sql","schema","read-only"],"backgroundTag":"operation-not-supported","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"}