apache/beam · error · UnsupportedOperationException

Conversion from to BigDecimal is not supported

Error message

Conversion from %s to BigDecimal is not supported

What it means

BigDecimalConverter.forSqlType looks up a BigDecimal -> Number conversion function in CONVERTER_MAP (INTEGER/BIGINT/FLOAT/DOUBLE/DECIMAL). Unsupported SqlTypeNames are not present in the map, so an UnsupportedOperationException is thrown. This is a deliberately unsupported-conversion guard, not a data error.

Solutions

  1. Only call forSqlType for numeric types (INT16/INT32/INT64, FLOAT, DOUBLE, DECIMAL).
  2. Pre-convert to a supported numeric type before calling.
  3. Add the desired mapping to CONVERTER_MAP if you own the code.
  4. Catch UnsupportedOperationException and fall back to identity/decimal handling.

Example fix

// before
SerializableFunction<BigDecimal, ? extends Number> fn = BigDecimalConverter.forSqlType(TypeName.STRING);
// after
if (field.getType().getTypeName().isNumericType()) {
  fn = BigDecimalConverter.forSqlType(field.getType().getTypeName());
}
Defensive patterns

Strategy: type-guard

Validate before calling

Set<TypeName> supported = Set.of(TypeName.INT16, TypeName.INT32, TypeName.INT64, TypeName.FLOAT, TypeName.DOUBLE, TypeName.DECIMAL);
if (!supported.contains(typeName)) { /* route to non-BigDecimal path */ }

Type guard

boolean isDecimalConvertible(TypeName t) {
  return t != null && EnumSet.of(TypeName.INT16, TypeName.INT32, TypeName.INT64, TypeName.FLOAT, TypeName.DOUBLE, TypeName.DECIMAL).contains(t);
}

Try / catch

try { fn = BigDecimalConverter.forSqlType(typeName); }
catch (UnsupportedOperationException e) { fn = v -> v; /* identity or decimal passthrough */ }

Prevention

When it happens

Trigger: Calling BigDecimalConverter.forSqlType(TypeName) with a type absent from CONVERTER_MAP, e.g. TypeName.STRING, TypeName.BOOLEAN, TypeName.TIMESTAMP, or null.

Common situations: Generic code that maps arbitrary schema field types to a BigDecimal-based representation, or a new Beam TypeName added later that the converter was never extended for.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/utils/BigDecimalConverter.java:46

 * TypeName}.
 */
public class BigDecimalConverter {

  private static final Map<TypeName, SerializableFunction<BigDecimal, ? extends Number>>
      CONVERTER_MAP =
          ImmutableMap.<TypeName, SerializableFunction<BigDecimal, ? extends Number>>builder()
              .put(TypeName.INT32, BigDecimal::intValue)
              .put(TypeName.INT16, BigDecimal::shortValue)
              .put(TypeName.BYTE, BigDecimal::byteValue)
              .put(TypeName.INT64, BigDecimal::longValue)
              .put(TypeName.FLOAT, BigDecimal::floatValue)
              .put(TypeName.DOUBLE, BigDecimal::doubleValue)
              .put(TypeName.DECIMAL, v -> v)
              .build();

  public static SerializableFunction<BigDecimal, ? extends Number> forSqlType(TypeName typeName) {
    if (!CONVERTER_MAP.containsKey(typeName)) {
      throw new UnsupportedOperationException(
          "Conversion from " + typeName + " to BigDecimal is not supported");
    }

    return CONVERTER_MAP.get(typeName);
  }
}

View on GitHub (pinned to 12126d8942)