apache/beam · error · IllegalArgumentException

Unable to infer coder for output of parseFn. Specify it expl

Error message

Unable to infer coder for output of parseFn. Specify it explicitly using withCoder().

What it means

BigQueryIO.TypedRead.inferCoder tries to derive the output Coder from the parseFn's generic type via the CoderRegistry. When neither withCoder() was called nor a Coder can be inferred from the parseFn's type signature (CannotProvideCoderException), this IllegalArgumentException fires, telling the user to supply a coder explicitly.

Source

Thrown at sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.java:1380

       * are available, usually within a few minutes. Batch queries don't count towards your
       * concurrent rate limit.
       */
      BATCH
    }

    @VisibleForTesting
    Coder<T> inferCoder(CoderRegistry coderRegistry) {
      Coder<T> coder = getCoder();
      if (coder != null) {
        return coder;
      }

      try {
        return coderRegistry.getCoder(
            TypeDescriptors.outputOf(
                checkStateNotNull(getParseFn(), "Either withCoder() or a parseFn is required")));
      } catch (CannotProvideCoderException e) {
        throw new IllegalArgumentException(
            "Unable to infer coder for output of parseFn. Specify it explicitly using withCoder().",
            e);
      }
    }

    private BigQuerySourceDef createSourceDef() {
      ValueProvider<String> query = getQuery();
      if (query == null) {
        return BigQueryTableSourceDef.create(
            getBigQueryServices(),
            checkStateNotNull(getTableProvider(), "Either from() or fromQuery() is required"));
      }
      return BigQueryQuerySourceDef.create(
          getBigQueryServices(),
          query,
          checkStateNotNull(
              getFlattenResults(), "flattenResults should not be null if query is set"),
          checkStateNotNull(getUseLegacySql(), "useLegacySql should not be null if query is set"),

View on GitHub (pinned to 12126d8942)

Solutions

  1. Call .withCoder(SerializableCoder.of(MyType.class)) explicitly on the read
  2. Register a default coder for the type via CoderRegistry
  3. Use a supported type (TableRow, TableRecord with schema annotation) so inference works

Example fix

// before
BigQueryIO.read(parseFn).from("proj:ds.tbl");
// after
BigQueryIO.read(parseFn).from("proj:ds.tbl").withCoder(SerializableCoder.of(MyRecord.class));
Defensive patterns

Strategy: validation

Validate before calling

// Ensure a coder can be inferred before building the pipeline
try {
  pipeline.getCoderRegistry().getCoder(TypeDescriptors.outputOf(parseFn));
} catch (CannotProvideCoderException e) {
  throw new IllegalStateException("Register a coder or call withCoder()", e);
}

Prevention

When it happens

Trigger: BigQueryIO.read().withParseFn(parseFn) where parseFn's output type is a custom class with no registered default coder and .withCoder() was not called.

Common situations: Returning custom POJOs or classes without @DefaultSchema/AvroTypeSupplier; using lambdas whose generic type info is erased; missing coder registration for the target type.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/b0cb955e553cd28e. Report an issue: GitHub.