{"record":{"id":"5c1e744ee7e5d5cd","repo":"apache/beam","slug":"s-is-not-supported-in-sum","errorCode":null,"errorMessage":"[%s] is not supported in SUM","messagePattern":"\\[(.+?)\\] is not supported in SUM","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/transform/BeamBuiltinAggregations.java","lineNumber":178,"sourceCode":"  /** {@link CombineFn} for Sum based on {@link Sum} and {@link Combine.BinaryCombineFn}. */\n  static CombineFn createSum(Schema.FieldType fieldType) {\n    switch (fieldType.getTypeName()) {\n      case INT32:\n        return Sum.ofIntegers();\n      case INT16:\n        return new ShortSum();\n      case BYTE:\n        return new ByteSum();\n      case INT64:\n        return new LongSum();\n      case FLOAT:\n        return new FloatSum();\n      case DOUBLE:\n        return Sum.ofDoubles();\n      case DECIMAL:\n        return new BigDecimalSum();\n      default:\n        throw new UnsupportedOperationException(\n            String.format(\"[%s] is not supported in SUM\", fieldType));\n    }\n  }\n\n  /**\n   * {@link CombineFn} for Sum0 where sum of null returns 0 based on {@link Sum} and {@link\n   * Combine.BinaryCombineFn}.\n   */\n  static CombineFn createSum0(Schema.FieldType fieldType) {\n    switch (fieldType.getTypeName()) {\n      case INT32:\n        return new IntegerSum0();\n      case INT16:\n        return new ShortSum0();\n      case BYTE:\n        return new ByteSum0();\n      case INT64:\n        return new LongSum0();","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/transform/BeamBuiltinAggregations.java#L160-L196","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the column type in the query is numeric; fix typos like SUM(flag_col).","Cast to a supported type: SELECT SUM(CAST(col AS DECIMAL)) or AS DOUBLE.","Provide a custom CombineFn (e.g. extend the private FloatSum/BigDecimalSum pattern) and wire it in place of the builtin SUM factory."],"exampleFix":"// before\nCombineFn fn = BeamBuiltinAggregations.createSum(Schema.FieldType.STRING); // throws\n\n// after\nCombineFn fn = BeamBuiltinAggregations.createSum(Schema.FieldType.DOUBLE);\n// SQL: SELECT SUM(CAST(qty AS DOUBLE)) FROM t","handlingStrategy":"validation","validationCode":"java.util.Set<Schema.TypeName> ok =\n    java.util.Set.of(Schema.TypeName.INTEGER, Schema.TypeName.INT64, Schema.TypeName.DOUBLE, Schema.TypeName.DECIMAL);\nif (!ok.contains(fieldType.getTypeName())) {\n  throw new IllegalArgumentException(\"SUM unsupported for \" + fieldType);\n}","typeGuard":"boolean sumSupported(Schema.FieldType t) {\n  switch (t.getTypeName()) {\n    case INTEGER: case INT64: case DOUBLE: case DECIMAL: return true;\n    default: return false;\n  }\n}","tryCatchPattern":"try {\n  CombineFn fn = BeamBuiltinAggregations.createSum(fieldType);\n} catch (UnsupportedOperationException e) {\n  // log the offending type and fall back to a custom numeric combiner\n}","preventionTips":["Confirm the column is numeric before SUM (catches SELECT SUM(varchar) typos).","Cast booleans/dates to numeric explicitly if summation is truly intended.","Keep schemas stable; re-check types after upstream schema evolution."],"tags":["beam-sql","unsupported-type","aggregation","java"],"backgroundTag":"unsupported-enum-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}