{"record":{"id":"1967ad82d0d77f33","repo":"apache/beam","slug":"parse-can-t-be-used-for-reading-as-genericrecord","errorCode":null,"errorMessage":"Parse can't be used for reading as GenericRecord.","messagePattern":"Parse can't be used for reading as GenericRecord\\.","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":582,"sourceCode":"    }\n\n    /** Returns true if expected output is {@code PCollection<GenericRecord>}. */\n    private boolean isGenericRecordOutput() {\n      String outputType = TypeDescriptors.outputOf(getParseFn()).getType().getTypeName();\n      return outputType.equals(GenericRecord.class.getTypeName());\n    }\n\n    /**\n     * Identifies the {@code Coder} to be used for the output PCollection.\n     *\n     * <p>throws an exception if expected output is of type {@link GenericRecord}.\n     *\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","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/parquet/src/main/java/org/apache/beam/sdk/io/parquet/ParquetIO.java#L564-L600","documentation":"ParquetIO's inferCoder is invoked from expand() when reading with a parse function. If the output type is GenericRecord AND a parseFn has been set, the transform cannot both parse and emit GenericRecords — parsing necessarily produces the parseFn's output type — so it throws IllegalArgumentException telling you Parse is incompatible with GenericRecord output.","triggerScenarios":"Calling .withParseFn(...) on a ParquetIO.Read whose element type T is GenericRecord (isGenericRecordOutput() true), then expanding the transform.","commonSituations":"Starting from GenericRecord-based reading code and adding a parseFn without changing the element type; generics erasure hiding that T is still GenericRecord; copy-paste between readGenericRecords() and read() flows.","solutions":["Change the transform's element type: use ParquetIO.<MyType>readFrom(...) with .withParseFn(parse -> MyType) instead of GenericRecord.","Or drop .withParseFn(...) and read raw GenericRecords via readGenericRecords().","Ensure generics are explicit so T is the parsed type, not GenericRecord."],"exampleFix":"// before\nParquetIO.<GenericRecord>readFrom(path).withParseFn(record -> parse(record)) // illegal\n// after\nParquetIO.<MyPojo>readFrom(path).withParseFn(record -> parse(record))","handlingStrategy":"validation","validationCode":"if (parseFn != null && elementClass.equals(GenericRecord.class)) throw new IllegalStateException(\"withParseFn requires a non-GenericRecord element type\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use readGenericRecords() when you want GenericRecord; use typed read + withParseFn otherwise.","Always specify explicit generics on ParquetIO.<T>readFrom."],"tags":["java","parquet","apache-beam","invalid-configuration"],"backgroundTag":"conflicting-config-options","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"}