apache/beam · error · IllegalArgumentException

No schema provided for getSchema(GenericRecord)

Error message

No schema provided for getSchema(GenericRecord)

What it means

AvroUtils.getSchema(Class) derives a Beam Schema from a Java/Avro class. For GenericRecord the Beam schema cannot be inferred from the class alone because it lives entirely in the Avro Schema object; calling without a schema is therefore a programming error and throws this IllegalArgumentException.

Source

Thrown at sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/schemas/utils/AvroUtils.java:699

    }
  }

  @SuppressWarnings("unchecked")
  public static <T> SerializableFunction<Row, T> getFromRowFunction(Class<T> clazz) {
    return GenericRecord.class.equals(clazz)
        ? (SerializableFunction<Row, T>) getRowToGenericRecordFunction(null)
        : new AvroRecordSchema().fromRowFunction(TypeDescriptor.of(clazz));
  }

  public static @Nullable <T> Schema getSchema(
      Class<T> clazz, org.apache.avro.@Nullable Schema schema) {
    if (schema != null) {
      return schema.getType().equals(org.apache.avro.Schema.Type.RECORD)
          ? toBeamSchema(schema)
          : null;
    }
    if (GenericRecord.class.equals(clazz)) {
      throw new IllegalArgumentException("No schema provided for getSchema(GenericRecord)");
    }
    return new AvroRecordSchema().schemaFor(TypeDescriptor.of(clazz));
  }

  /** Returns a function mapping encoded AVRO {@link GenericRecord}s to Beam {@link Row}s. */
  public static SimpleFunction<byte[], Row> getAvroBytesToRowFunction(Schema beamSchema) {
    return new AvroBytesToRowFn(beamSchema);
  }

  private static class AvroBytesToRowFn extends SimpleFunction<byte[], Row> {
    private final AvroCoder<GenericRecord> coder;
    private final Schema beamSchema;

    AvroBytesToRowFn(Schema beamSchema) {
      org.apache.avro.Schema avroSchema = toAvroSchema(beamSchema);
      coder = AvroCoder.of(avroSchema);
      this.beamSchema = beamSchema;
    }

View on GitHub (pinned to 12126d8942)

Solutions

  1. Use AvroUtils.schemaCoder(GenericRecord.class, avroSchema), passing the concrete Avro Schema.
  2. If you have a typed Avro class (SpecificRecord), use that class instead of GenericRecord so the schema can be derived automatically.
  3. Wire the Avro schema explicitly into coder registration for the pipeline (coder.setAvroSchema / schemaCoder overload).
  4. Obtain the schema from the source (e.g. schema registry, data file footer) before constructing the coder.

Example fix

// before
Coder<GenericRecord> coder = AvroUtils.schemaCoder(GenericRecord.class); // throws
// after
Coder<GenericRecord> coder = AvroUtils.schemaCoder(GenericRecord.class, avroSchema);
Defensive patterns

Strategy: type-guard

Validate before calling

if (GenericRecord.class.equals(clazz)) {
  Objects.requireNonNull(avroSchema, "An Avro schema is required to get a Beam schema for GenericRecord");
}

Type guard

Optional<Schema> beamSchemaFor(Class<?> clazz, Schema avroSchema) {
  return GenericRecord.class.equals(clazz) && avroSchema != null
      ? Optional.of(AvroUtils.getSchema(GenericRecord.class, avroSchema))
      : Optional.empty();
}

Try / catch

try {
  return AvroUtils.schemaCoder(GenericRecord.class);
} catch (IllegalArgumentException e) {
  throw new IllegalStateException("Provide the AVRO schema: schemaCoder(GenericRecord.class, schema)", e);
}

Prevention

When it happens

Trigger: Calling AvroUtils.getSchema(GenericRecord.class) with schema == null, e.g. invoking schemaCoder(clazz) or schemaCoder(TypeDescriptor) for GenericRecord without supplying the Avro schema via schemaCoder(GenericRecord.class, avroSchema).

Common situations: Creating a Coder for GenericRecord records in a pipeline (CoderRegistry, DoFn output types) where Beam resolves coders by class only, so the required Avro schema is never provided; using getSchema in a custom coder without wiring the schema through.

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/1f7119cc6dc4e680. Report an issue: GitHub.