apache/beam · error · CoderException

Unknown Type

Error message

Unknown Type

What it means

AttributeValueCoder.encode throws CoderException("Unknown Type") when the DynamoDB AttributeValue being encoded has none of its supported typed fields set (s, n, b, ss, ns, bs, m, l, nul, etc.). It is a defensive terminal branch indicating the AttributeValue is empty or uses a field the coder doesn't handle.

Solutions

  1. Check which AttributeValue triggered it and ensure exactly one typed field is set
  2. Fix upstream code that builds empty AttributeValues (e.g. skip null fields)
  3. Upgrade the Beam AWS2 IO / SDK so the coder covers all AttributeValue variants
  4. Validate items before writing: assert at least one of s/n/b/ss/ns/bs/m/l/nul is non-null

Example fix

// before: empty value slips through
AttributeValue v = AttributeValue.builder().build();
items.put("key", v);
// after: guard before writing
if (v.s() == null && v.n() == null && v.b() == null && v.m() == null
    && v.l() == null && v.ss() == null && v.nul() == null) {
  throw new IllegalArgumentException("AttributeValue has no type set");
}
Defensive patterns

Strategy: validation

Validate before calling

boolean isValid(AttributeValue v) {
  return v.s() != null || v.n() != null || v.b() != null || v.ss() != null
      || v.ns() != null || v.bs() != null || v.m() != null || v.l() != null
      || v.nul() != null;
}

Type guard

boolean hasTypedValue(AttributeValue v) {
  return v.s() != null || v.n() != null || v.b() != null
      || v.m() != null || v.l() != null || v.nul() != null;
}

Try / catch

try {
  coder.encode(value, outStream);
} catch (CoderException e) {
  logger.error("AttributeValue has no supported type set", e);
  throw e;
}

Prevention

When it happens

Trigger: Encoding an AttributeValue built without setting any typed value (e.g. AttributeValue.builder().build()), or an AttributeValue from a newer AWS SDK version carrying a field this coder doesn't recognize.

Common situations: Constructing items programmatically with an accidentally empty AttributeValue; DynamoDB returning a value shape the Beam coder version predates; null/empty maps written to DynamoDB then read back through Beam writes.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/dynamodb/AttributeValueCoder.java:102

      StringUtf8Coder.of().encode(AttributeValueType.ss.toString(), outStream);
      LIST_STRING_CODER.encode(value.ss(), outStream);
    } else if (value.ns() != null && value.ns().size() > 0) {
      StringUtf8Coder.of().encode(AttributeValueType.ns.toString(), outStream);
      LIST_STRING_CODER.encode(value.ns(), outStream);
    } else if (value.bs() != null && value.bs().size() > 0) {
      StringUtf8Coder.of().encode(AttributeValueType.bs.toString(), outStream);
      LIST_BYTE_CODER.encode(convertToListByteArray(value.bs()), outStream);
    } else if (value.l() != null && value.l().size() > 0) {
      StringUtf8Coder.of().encode(AttributeValueType.l.toString(), outStream);
      LIST_ATTRIBUTE_CODER.encode(value.l(), outStream);
    } else if (value.m() != null && value.m().size() > 0) {
      StringUtf8Coder.of().encode(AttributeValueType.m.toString(), outStream);
      MAP_ATTRIBUTE_CODER.encode(value.m(), outStream);
    } else if (value.nul() != null) {
      StringUtf8Coder.of().encode(AttributeValueType.nul.toString(), outStream);
      BooleanCoder.of().encode(value.nul(), outStream);
    } else {
      throw new CoderException("Unknown Type");
    }
  }

  @Override
  public AttributeValue decode(InputStream inStream) throws IOException {
    AttributeValue.Builder attrBuilder = AttributeValue.builder();

    String type = StringUtf8Coder.of().decode(inStream);
    AttributeValueType attrType = AttributeValueType.valueOf(type);

    switch (attrType) {
      case s:
        attrBuilder.s(StringUtf8Coder.of().decode(inStream));
        break;
      case n:
        attrBuilder.n(StringUtf8Coder.of().decode(inStream));
        break;
      case bool:

View on GitHub (pinned to 12126d8942)