{"record":{"id":"a81520423c88c382","repo":"apache/beam","slug":"s-is-not-supported-in-avg","errorCode":null,"errorMessage":"[%s] is not supported in AVG","messagePattern":"\\[(.+?)\\] is not supported in AVG","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":227,"sourceCode":"  /** {@link CombineFn} for AVG. */\n  static CombineFn createAvg(Schema.FieldType fieldType) {\n    switch (fieldType.getTypeName()) {\n      case INT32:\n        return new IntegerAvg();\n      case INT16:\n        return new ShortAvg();\n      case BYTE:\n        return new ByteAvg();\n      case INT64:\n        return new LongAvg();\n      case FLOAT:\n        return new FloatAvg();\n      case DOUBLE:\n        return new DoubleAvg();\n      case DECIMAL:\n        return new BigDecimalAvg();\n      default:\n        throw new UnsupportedOperationException(\n            String.format(\"[%s] is not supported in AVG\", fieldType));\n    }\n  }\n\n  static CombineFn createBitOr(Schema.FieldType fieldType) {\n    if (fieldType.getTypeName() == TypeName.INT64) {\n      return new BitOr();\n    }\n    throw new UnsupportedOperationException(\n        String.format(\"[%s] is not supported in BIT_OR\", fieldType));\n  }\n\n  static CombineFn createBitAnd(Schema.FieldType fieldType) {\n    if (fieldType.getTypeName() == TypeName.INT64) {\n      return new BitAnd();\n    }\n    throw new UnsupportedOperationException(\n        String.format(\"[%s] is not supported in BIT_AND\", fieldType));","sourceCodeStart":209,"sourceCodeEnd":245,"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#L209-L245","documentation":"createAvg builds the CombineFn for SQL AVG, supporting INTEGER-family (FloatAvg/IntAvg), DOUBLE (DoubleAvg), and DECIMAL (BigDecimalAvg). Any other Schema.FieldType hits the default branch and throws UnsupportedOperationException naming the type. AVG requires a numeric type with a supported mean combiner.","triggerScenarios":"Calling BeamBuiltinAggregations.createAvg(fieldType) with a non-numeric or unsupported numeric TypeName (STRING, BOOLEAN, DATE, etc.) — typically from SELECT AVG(varchar_col) or programmatic pipeline construction with a wrong field type.","commonSituations":"AVG over a string or boolean column from a query mistake; AVG over TIMESTAMP/DATE which many engines allow but this implementation does not; schema inferred as DECIMAL variant not covered by the switch.","solutions":["Cast the column to DOUBLE or DECIMAL in the query: SELECT AVG(CAST(ts AS DOUBLE)) ...","Restrict AVG to numeric columns; compute averages for other types manually with a Map/Combine pipeline.","Supply a custom CombineFn computing sum/count for the desired type."],"exampleFix":"// before\nCombineFn fn = BeamBuiltinAggregations.createAvg(Schema.FieldType.STRING); // throws\n\n// after\nCombineFn fn = BeamBuiltinAggregations.createAvg(Schema.FieldType.DOUBLE);\n// SQL: SELECT AVG(CAST(score 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(\"AVG unsupported for \" + fieldType);\n}","typeGuard":"boolean avgSupported(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.createAvg(fieldType);\n} catch (UnsupportedOperationException e) {\n  // fall back to CAST(col AS DOUBLE) then AVG, or custom sum/count combiner\n}","preventionTips":["Only AVG numeric columns; cast timestamps/dates explicitly if averaging durations.","Prefer DOUBLE or DECIMAL casts for AVG over integer columns.","Validate schema types at pipeline construction time, not runtime."],"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"}