{"record":{"id":"a2b893adf9d0b78d","repo":"apache/beam","slug":"unable-to-infer-coder-for-output-of-parsefn-specify-it-a2b893","errorCode":null,"errorMessage":"Unable to infer coder for output of parseFn. Specify it explicitly using .withCoder().","messagePattern":"Unable to infer coder for output of parseFn\\. Specify it explicitly using \\.withCoder\\(\\)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/parquet/src/main/java/org/apache/beam/sdk/io/parquet/ParquetIO.java","lineNumber":594,"sourceCode":"     *\n     * @param coderRegistry the {@link org.apache.beam.sdk.Pipeline}'s CoderRegistry to identify\n     *     Coder for expected output type of {@link #getParseFn()}\n     */\n    private Coder<T> inferCoder(CoderRegistry coderRegistry) {\n      if (isGenericRecordOutput()) {\n        throw new IllegalArgumentException(\"Parse can't be used for reading as GenericRecord.\");\n      }\n\n      // Use explicitly provided coder\n      if (getCoder() != null) {\n        return getCoder();\n      }\n\n      // If not GenericRecord infer it from ParseFn.\n      try {\n        return coderRegistry.getCoder(TypeDescriptors.outputOf(getParseFn()));\n      } catch (CannotProvideCoderException e) {\n        throw new IllegalArgumentException(\n            \"Unable to infer coder for output of parseFn. Specify it explicitly using .withCoder().\",\n            e);\n      }\n    }\n  }\n\n  /** Implementation of {@link #readFiles(Schema)}. */\n  @AutoValue\n  public abstract static class ReadFiles\n      extends PTransform<PCollection<ReadableFile>, PCollection<GenericRecord>> {\n\n    abstract @Nullable Schema getSchema();\n\n    abstract @Nullable GenericData getAvroDataModel();\n\n    abstract @Nullable Schema getEncoderSchema();\n\n    abstract @Nullable Schema getProjectionSchema();","sourceCodeStart":576,"sourceCodeEnd":612,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/parquet/src/main/java/org/apache/beam/sdk/io/parquet/ParquetIO.java#L576-L612","documentation":"After ruling out GenericRecord, inferCoder tries to derive the Coder for parseFn's output type from the pipeline's CoderRegistry. If the registry cannot provide a coder (unregistered custom type, non-codable fields, generic types), ParquetIO throws IllegalArgumentException advising an explicit coder via .withCoder().","triggerScenarios":"Expanding a ParquetIO read with a parseFn whose output type T has no registered/default coder — e.g. a custom POJO without a Coder, ambiguous generic types, or a type the registry's TypeDescriptor-based inference cannot handle.","commonSituations":"Custom domain objects not registered with the CoderRegistry; using Avro/POJO types needing explicit coders; Kotlin/complex generic outputs confusing TypeDescriptors.","solutions":["Call .withCoder(myCoder) explicitly on the ParquetIO.Read builder.","Register a coder for the output type via coderRegistry.registerCoderForClass(...).","Make the output a simple Serializable/Avro/POJO type the registry can infer automatically."],"exampleFix":"// before\nParquetIO.<MyPojo>readFrom(path).withParseFn(ParquetReadTest::parse)\n// after\nParquetIO.<MyPojo>readFrom(path)\n  .withParseFn(ParquetReadTest::parse)\n  .withCoder(SerializableCoder.of(MyPojo.class))","handlingStrategy":"validation","validationCode":"try { coderRegistry.getCoder(TypeDescriptors.outputOf(parseFn)); } catch (CannotProvideCoderException e) { /* add .withCoder(...) */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer SerializableCoder/AvroCoder-capable output types.","Register custom coders with the CoderRegistry at pipeline setup.","Always attach .withCoder() when parseFn emits a custom type."],"tags":["java","parquet","apache-beam","coder-inference"],"backgroundTag":"missing-required-config-field","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"}