apache/beam · error · java.lang.IllegalArgumentException

Unable to infer a coder for type

Error message

Unable to infer a coder for type %s

What it means

SingleStoreIO uses Apache Beam's coder registry to derive a Coder for the output type when no schema can be inferred. If the registry cannot provide a coder (CannotProvideCoderException), inferCoder fails fast with this IllegalArgumentException. It means the element type of your read result is not one Beam can serialize automatically.

Solutions

  1. Annotate the output class with @DefaultSchema(JavaBeanSchema.class) (or AutoValueSchema) and ensure it is a public static class with proper getters, so a schema (and coder) is inferred.
  2. Register a custom coder via CoderRegistry (pipeline.getCoderRegistry().registerCoderForClass(MyType.class, MyCoder.class)) before running the pipeline.
  3. Use a type Beam already supports (e.g. KV, Row, TableRow, a class with an Avro-specific reflection coder).
  4. If a schema is the problem, resolve it explicitly: SchemaCoder.of(schema, typeDescriptor, toRowFn, fromRowFn).

Example fix

// before
PCollection<MyPojo> rows = pipeline.apply(SingleStoreIO.<MyPojo>read()...);

// after
@DefaultSchema(JavaBeanSchema.class)
public class MyPojo { /* public getters/setters, static class */ }
PCollection<MyPojo> rows = pipeline.apply(SingleStoreIO.<MyPojo>read()...);
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the type is schema-annotated before building the read
if (!MyPojo.class.isAnnotationPresent(DefaultSchema.class)) {
  throw new IllegalStateException("Add @DefaultSchema(JavaBeanSchema.class) to " + MyPojo.class);
}

Prevention

When it happens

Trigger: Calling SingleStoreIO.read() (or apply of the read transform) with a generic output type such as a POJO without @DefaultSchema/@SchemaCreate annotation, a non-static inner class, a type without a registered Coder, or raw/generic type parameters erased to Object.

Common situations: Users map SingleStore rows into custom domain classes that Beam cannot infer coders for; using complex types (LocalDateTime, BigDecimal wrappers, interfaces) without schema annotation; running with generic type erasure so registry.getCoder(Object) fails.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at sdks/java/io/singlestore/src/main/java/org/apache/beam/sdk/io/singlestore/SingleStoreUtil.java:69

    }

    TypeDescriptor<OutputT> outputType =
        TypeDescriptors.extractFromTypeParameters(
            rowMapper,
            SingleStoreIO.RowMapper.class,
            new TypeDescriptors.TypeVariableExtractor<
                SingleStoreIO.RowMapper<OutputT>, OutputT>() {});
    try {
      return schemaRegistry.getSchemaCoder(outputType);
    } catch (NoSuchSchemaException e) {
      log.warn(
          "Unable to infer a schema for type {}. Attempting to infer a coder without a schema.",
          outputType);
    }
    try {
      return registry.getCoder(outputType);
    } catch (CannotProvideCoderException e) {
      throw new IllegalArgumentException(
          String.format("Unable to infer a coder for type %s", outputType));
    }
  }

  public static String getSelectQuery(@Nullable String table, @Nullable String query) {
    if (table != null && query != null) {
      throw new IllegalArgumentException("withTable() can not be used together with withQuery()");
    } else if (table != null) {
      return "SELECT * FROM " + SingleStoreUtil.escapeIdentifier(table);
    } else if (query != null) {
      return query;
    } else {
      throw new IllegalArgumentException("One of withTable() or withQuery() is required");
    }
  }

  public static <OutputT> OutputT getArgumentWithDefault(
      @Nullable OutputT value, OutputT defaultValue) {

View on GitHub (pinned to 12126d8942)