apache/beam · error · UnsupportedOperationException
[ ] is not supported in AVG
Error message
[%s] is not supported in AVG
What it means
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.
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.
Example fix
// before CombineFn fn = BeamBuiltinAggregations.createAvg(Schema.FieldType.STRING); // throws // after CombineFn fn = BeamBuiltinAggregations.createAvg(Schema.FieldType.DOUBLE); // SQL: SELECT AVG(CAST(score 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("AVG unsupported for " + fieldType);
} Type guard
boolean avgSupported(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.createAvg(fieldType);
} catch (UnsupportedOperationException e) {
// fall back to CAST(col AS DOUBLE) then AVG, or custom sum/count combiner
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- [ ] is not supported in MAX
- [ ] is not supported in MIN
- [ ] is not supported in SUM
- [ ] is not supported in SUM0
- [ ] is not supported in BIT_AND
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/a81520423c88c382.
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:227
/** {@link CombineFn} for AVG. */
static CombineFn createAvg(Schema.FieldType fieldType) {
switch (fieldType.getTypeName()) {
case INT32:
return new IntegerAvg();
case INT16:
return new ShortAvg();
case BYTE:
return new ByteAvg();
case INT64:
return new LongAvg();
case FLOAT:
return new FloatAvg();
case DOUBLE:
return new DoubleAvg();
case DECIMAL:
return new BigDecimalAvg();
default:
throw new UnsupportedOperationException(
String.format("[%s] is not supported in AVG", fieldType));
}
}
static CombineFn createBitOr(Schema.FieldType fieldType) {
if (fieldType.getTypeName() == TypeName.INT64) {
return new BitOr();
}
throw new UnsupportedOperationException(
String.format("[%s] is not supported in BIT_OR", fieldType));
}
static CombineFn createBitAnd(Schema.FieldType fieldType) {
if (fieldType.getTypeName() == TypeName.INT64) {
return new BitAnd();
}
throw new UnsupportedOperationException(
String.format("[%s] is not supported in BIT_AND", fieldType));View on GitHub (pinned to 12126d8942)