apache/beam · error · UnsupportedOperationException

[ ] is not supported in SUM

Error message

[%s] is not supported in SUM

What it means

createSum builds the CombineFn for SQL SUM. It supports INTEGER (FloatSum/IntSum path), DOUBLE (Sum.ofDoubles), and DECIMAL (BigDecimalSum); anything else throws UnsupportedOperationException with the field type. SUM is intentionally restricted to numeric types the library ships combiners for.

Solutions

  1. Verify the column type in the query is numeric; fix typos like SUM(flag_col).
  2. Cast to a supported type: SELECT SUM(CAST(col AS DECIMAL)) or AS DOUBLE.
  3. Provide a custom CombineFn (e.g. extend the private FloatSum/BigDecimalSum pattern) and wire it in place of the builtin SUM factory.

Example fix

// before
CombineFn fn = BeamBuiltinAggregations.createSum(Schema.FieldType.STRING); // throws

// after
CombineFn fn = BeamBuiltinAggregations.createSum(Schema.FieldType.DOUBLE);
// SQL: SELECT SUM(CAST(qty AS DOUBLE)) FROM t
Defensive patterns

Strategy: validation

Validate before calling

java.util.Set<Schema.TypeName> ok =
    java.util.Set.of(Schema.TypeName.INTEGER, Schema.TypeName.INT64, Schema.TypeName.DOUBLE, Schema.TypeName.DECIMAL);
if (!ok.contains(fieldType.getTypeName())) {
  throw new IllegalArgumentException("SUM unsupported for " + fieldType);
}

Type guard

boolean sumSupported(Schema.FieldType t) {
  switch (t.getTypeName()) {
    case INTEGER: case INT64: case DOUBLE: case DECIMAL: return true;
    default: return false;
  }
}

Try / catch

try {
  CombineFn fn = BeamBuiltinAggregations.createSum(fieldType);
} catch (UnsupportedOperationException e) {
  // log the offending type and fall back to a custom numeric combiner
}

Prevention

When it happens

Trigger: Calling BeamBuiltinAggregations.createSum(fieldType) with a non-supported TypeName such as STRING, BOOLEAN, DATE, or an unhandled numeric variant — usually from SELECT SUM(string_col) or a schema whose numeric column is typed outside the supported set.

Common situations: SUM over a boolean/varchar column due to a query typo; a table provider exposing numbers as DECIMAL when the DECIMAL case is present but another custom numeric type is not; schema drift after upstream data type changes.

Related errors


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

Appendix: source

Thrown at sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/transform/BeamBuiltinAggregations.java:178

  /** {@link CombineFn} for Sum based on {@link Sum} and {@link Combine.BinaryCombineFn}. */
  static CombineFn createSum(Schema.FieldType fieldType) {
    switch (fieldType.getTypeName()) {
      case INT32:
        return Sum.ofIntegers();
      case INT16:
        return new ShortSum();
      case BYTE:
        return new ByteSum();
      case INT64:
        return new LongSum();
      case FLOAT:
        return new FloatSum();
      case DOUBLE:
        return Sum.ofDoubles();
      case DECIMAL:
        return new BigDecimalSum();
      default:
        throw new UnsupportedOperationException(
            String.format("[%s] is not supported in SUM", fieldType));
    }
  }

  /**
   * {@link CombineFn} for Sum0 where sum of null returns 0 based on {@link Sum} and {@link
   * Combine.BinaryCombineFn}.
   */
  static CombineFn createSum0(Schema.FieldType fieldType) {
    switch (fieldType.getTypeName()) {
      case INT32:
        return new IntegerSum0();
      case INT16:
        return new ShortSum0();
      case BYTE:
        return new ByteSum0();
      case INT64:
        return new LongSum0();

View on GitHub (pinned to 12126d8942)