{"record":{"id":"05f8ed39cbbf6e96","repo":"apache/beam","slug":"s-is-not-supported-in-max","errorCode":null,"errorMessage":"[%s] is not supported in MAX","messagePattern":"\\[(.+?)\\] is not supported in MAX","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":129,"sourceCode":"      return new CustMax<>();\n    }\n    switch (fieldType.getTypeName()) {\n      case BOOLEAN:\n      case INT16:\n      case BYTE:\n      case FLOAT:\n      case DATETIME:\n      case DECIMAL:\n      case STRING:\n        return new CustMax<>();\n      case INT32:\n        return Max.ofIntegers();\n      case INT64:\n        return Max.ofLongs();\n      case DOUBLE:\n        return Max.ofDoubles();\n      default:\n        throw new UnsupportedOperationException(\n            String.format(\"[%s] is not supported in MAX\", fieldType));\n    }\n  }\n\n  /** {@link CombineFn} for MIN based on {@link Min} and {@link Combine.BinaryCombineFn}. */\n  static CombineFn createMin(Schema.FieldType fieldType) {\n    if (CalciteUtils.isDateTimeType(fieldType)) {\n      return new CustMin();\n    }\n    switch (fieldType.getTypeName()) {\n      case BOOLEAN:\n      case BYTE:\n      case INT16:\n      case FLOAT:\n      case DATETIME:\n      case DECIMAL:\n      case STRING:\n        return new CustMin();","sourceCodeStart":111,"sourceCodeEnd":147,"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#L111-L147","documentation":"Beam SQL's createMax builds a CombineFn for the MAX aggregation but only supports INTEGER (Max.ofIntegers), INT64 (Max.ofLongs), and DOUBLE (Max.ofDoubles) field types. Any other Schema.FieldType reaching the default branch throws UnsupportedOperationException with the field type in the message. This is a compile-time-unsupported-type guard: the aggregation was planned with a type MAX cannot combine natively.","triggerScenarios":"Calling BeamBuiltinAggregations.createMax(fieldType) with a fieldType whose TypeName is not INTEGER, INT64, or DOUBLE (e.g. DECIMAL, FLOAT, STRING, DATE) — typically via a SQL query like SELECT MAX(varchar_col) or MAX(decimal_col) through zetasql/calcite translation.","commonSituations":"Writing Beam SQL queries where MAX is applied to a DECIMAL/NUMERIC column, a string column, or a timestamp column whose inferred schema type is not one of the three supported TypeNames; also occurs after schema evolution changes a column type away from INT32/INT64/DOUBLE.","solutions":["Change the query to apply MAX only to integer or double columns; cast the column first, e.g. SELECT MAX(CAST(col AS DOUBLE)) FROM ...","If MAX over DECIMAL is needed, implement a custom CombineFn (e.g. extend Combine.BinaryCombineFn<BigDecimal> with compareTo) and register it instead of relying on the builtin MAX.","Check the inferred schema type of the source (PCollection schema or table provider) and adjust it so the column maps to INTEGER/INT64/DOUBLE."],"exampleFix":"// before\nSchema.FieldType t = Schema.FieldType.DECIMAL; // MAX over DECIMAL unsupported\nCombineFn fn = BeamBuiltinAggregations.createMax(t); // throws\n\n// after\n// Query side: SELECT MAX(CAST(amount AS DOUBLE)) ...\n// or custom combiner:\nCombineFn<BigDecimal, ?, BigDecimal> fn =\n    Combine.BinaryCombineFn<BigDecimal>::apply == null ? null\n        : new CustMax<>(BigDecimal.class); // CustMax<T extends Comparable<T>> exists in this class","handlingStrategy":"validation","validationCode":"// before planning MAX\njava.util.Set<Schema.TypeName> ok =\n    java.util.Set.of(Schema.TypeName.INTEGER, Schema.TypeName.INT64, Schema.TypeName.DOUBLE);\nif (!ok.contains(fieldType.getTypeName())) {\n  throw new IllegalArgumentException(\"MAX unsupported for \" + fieldType);\n}","typeGuard":"boolean maxSupported(Schema.FieldType t) {\n  return t.getTypeName() == Schema.TypeName.INTEGER\n      || t.getTypeName() == Schema.TypeName.INT64\n      || t.getTypeName() == Schema.TypeName.DOUBLE;\n}","tryCatchPattern":"try {\n  CombineFn fn = BeamBuiltinAggregations.createMax(fieldType);\n} catch (UnsupportedOperationException e) {\n  // fall back to cast-to-double pipeline or custom combiner\n}","preventionTips":["Apply MAX/MIN/SUM/AVG only to INT32/INT64/DOUBLE/DECIMAL columns in Beam SQL.","Cast non-conforming columns (CAST(... AS DOUBLE/BIGINT)) at query time.","Verify inferred schema types of your source before writing aggregations."],"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"}