{"record":{"id":"9313501c1b82801f","repo":"apache/beam","slug":"sqltransform-can-only-be-applied-to-schema-d-transforms","errorCode":null,"errorMessage":"SqlTransform can only be applied to schema'd transforms. Please ensure the input PCollection(s) have a RowCoder, or pass a prototypical element in as the second argument of SqlTransform so that one can be inferred.","messagePattern":"SqlTransform can only be applied to schema'd transforms\\. Please ensure the input PCollection\\(s\\) have a RowCoder, or pass a prototypical element in as the second argument of SqlTransform so that one can be inferred\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"sdks/typescript/src/apache_beam/transforms/sql.ts","lineNumber":59,"sourceCode":" *    ));\n */\nexport function sqlTransform<\n  InputT extends PCollection<any> | { [key: string]: PCollection<any> },\n>(\n  query: string,\n  inputTypes = null,\n): transform.AsyncPTransform<InputT, PCollection<any>> {\n  // TOOD: (API) (Typescript): How to infer input_types, or at least make it optional.\n  async function expandInternal(input: InputT): Promise<PCollection<any>> {\n    function withCoder<T>(pcoll: PCollection<T>, type): PCollection<T> {\n      if (type) {\n        if (\n          !(\n            pcoll.pipeline.context.getPCollectionCoder(pcoll) instanceof\n            row_coder.RowCoder\n          )\n        ) {\n          throw new Error(\n            \"SqlTransform can only be applied to schema'd transforms. \" +\n              \"Please ensure the input PCollection(s) have a RowCoder, \" +\n              \"or pass a prototypical element in as the second argument \" +\n              \"of SqlTransform so that one can be inferred.\",\n          );\n        }\n        return pcoll;\n      }\n      return pcoll.apply(internal.withRowCoder(type));\n    }\n\n    if (input instanceof PCollection) {\n      input = withCoder(input, inputTypes) as InputT;\n    } else {\n      input = Object.fromEntries(\n        Object.keys(input).map((tag) => [\n          tag,\n          withCoder(","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/typescript/src/apache_beam/transforms/sql.ts#L41-L77","documentation":"SqlTransform requires its input PCollections to carry a schema, represented in the TypeScript SDK by a RowCoder. Before expanding the SQL transform, the SDK checks each input's coder; if it is not a RowCoder (e.g. plain JSON objects or primitives without an explicit schema), the SQL engine cannot map elements to columns, so it throws. Supplying a prototypical element lets the SDK infer a schema and attach a RowCoder.","triggerScenarios":"Applying SqlTransform to a PCollection of plain objects/primitives with no inferred schema, and not passing the prototype (second) argument to SqlTransform.","commonSituations":"Running SQL over PCollection<any> of parsed JSON where the SDK cannot infer a schema; passing class instances without schema annotations; using primitives like strings as SQL input.","solutions":["Pass a prototypical element as the second argument of SqlTransform so a RowCoder can be inferred.","Ensure inputs are instances of typed classes so the SDK can infer a schema (RowCoder).","Replace the raw coder with a RowCoder via withCoder on the input PCollection.","Re-check the input type: SQL needs schema'd elements, not untyped JSON."],"exampleFix":"// before\npcoll.apply(SqlTransform.query('SELECT f1 FROM PCOLLECTION'));\n\n// after: provide a prototype so a RowCoder is inferred\npcoll.apply(SqlTransform.query('SELECT f1 FROM PCOLLECTION', new MyRow('', 0)));","handlingStrategy":"validation","validationCode":"// before applying SqlTransform, ensure inputs carry a RowCoder schema\nif (!(pcoll.pipeline.context.getPCollectionCoder(pcoll) instanceof row_coder.RowCoder)) {\n  // pass a prototype: SqlTransform.query(sql, new MyRow('', 0))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a prototypical element to SqlTransform for untyped inputs.","Use typed element classes so schemas are inferred automatically.","Never feed raw JSON or primitives into SqlTransform without a schema step."],"tags":["sql","schema","coder","pipeline-build"],"backgroundTag":"schema-validation-failed","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"}