redis/jedis · error · UnsupportedAggregationException
AGG_MIN policy requires Comparable types or KeyValue, but…
Error message
AGG_MIN policy requires Comparable types or KeyValue, but got: ${min.getClass().getName()} and ${input.getClass().getName()} What it means
MinAggregator.add throws UnsupportedAggregationException when the current min value is neither Comparable nor a KeyValue, so AGG_MIN cannot order the elements. Same contract as MaxAggregator but for the minimum.
Solutions
- Ensure all values passed to add() are Comparable and mutually comparable, or KeyValue instances
- Normalize types before aggregation (e.g. parse all to Long/Double)
- Handle non-comparable data outside the aggregator
Example fix
// before
minAgg.add(obj);
// after
if (obj instanceof Comparable) { minAgg.add(obj); } else { minAgg.add(Long.valueOf(obj.hashCode())); } Defensive patterns
Strategy: type-guard
Validate before calling
if (!(value instanceof Comparable) && !(value instanceof KeyValue)) { throw new IllegalArgumentException("AGG_MIN needs Comparable or KeyValue"); } Type guard
boolean isMinCompatible(Object o) { return o instanceof Comparable || o instanceof KeyValue; } Try / catch
try { minAgg.add(value); } catch (UnsupportedAggregationException e) { log.error("Non-comparable value: {}", value.getClass()); throw e; } Prevention
- Only aggregate Comparable or KeyValue results
- Normalize to one Comparable type before aggregation
- Avoid mixing String and numeric types across add() calls
When it happens
Trigger: Calling add() with an operand that is not Comparable and not KeyValue, or whose compareTo is incompatible with the accumulated min.
Common situations: Aggregating raw byte arrays or custom objects returned by module commands; mixing types (String then Long) across add() calls.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- AGG_MAX policy requires Comparable types or KeyValue, but…
- AGG_SUM policy requires numeric type, but got
- DEFAULT policy requires List, Set, Map, JedisByteHashMap…
- requires Boolean, Long, ArrayList , or ArrayList , but got
- requires Boolean, Long, ArrayList , or ArrayList , but got…
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/1a24445891a2727d.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/executors/aggregators/MinAggregator.java:40
return;
}
// Handle KeyValue types
if (min instanceof KeyValue && input instanceof KeyValue) {
min = (T) aggregateKeyValueMin((KeyValue<?, ?>) min, (KeyValue<?, ?>) input);
return;
}
// Handle Comparable types
if (min instanceof Comparable && input instanceof Comparable) {
Comparable<Object> minComp = (Comparable<Object>) min;
if (minComp.compareTo(input) > 0) {
min = input;
}
return;
}
throw new UnsupportedAggregationException(
"AGG_MIN policy requires Comparable types or KeyValue, but got: " + min.getClass().getName()
+ " and " + input.getClass().getName());
}
@Override
public T getResult() {
return min;
}
@SuppressWarnings("unchecked")
private KeyValue<?, ?> aggregateKeyValueMin(KeyValue<?, ?> kv1, KeyValue<?, ?> kv2) {
Object minKey = ((Comparable<Object>) kv1.getKey()).compareTo(kv2.getKey()) <= 0 ? kv1.getKey()
: kv2.getKey();
Object minValue = ((Comparable<Object>) kv1.getValue()).compareTo(kv2.getValue()) <= 0
? kv1.getValue()
: kv2.getValue();
return new KeyValue<>(minKey, minValue);
}View on GitHub (pinned to 6dac31d4c2)