redis/jedis · error · UnsupportedAggregationException

AGG_MAX policy requires Comparable types or KeyValue, but…

Error message

AGG_MAX policy requires Comparable types or KeyValue, but got: ${max.getClass().getName()} and ${input.getClass().getName()}

What it means

MaxAggregator.add throws UnsupportedAggregationException when the current max value is neither Comparable nor a KeyValue, so no comparison can be performed. AGG_MAX requires elements that can be ordered against each other.

Solutions

  1. Feed Comparable types (String, Long, Double, etc.) or redis.clients.jedis.args.KeyValue instances into the aggregator
  2. Convert/parse the value into a Comparable form before calling add()
  3. Use a custom aggregation outside this aggregator for non-comparable data

Example fix

// before
maxAgg.add(new byte[]{1});
// after
maxAgg.add(Long.valueOf(bytes.length));
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(value instanceof Comparable) && !(value instanceof KeyValue)) { throw new IllegalArgumentException("AGG_MAX needs Comparable or KeyValue"); }

Type guard

boolean isMaxCompatible(Object o) { return o instanceof Comparable || o instanceof KeyValue; }

Try / catch

try { maxAgg.add(value); } catch (UnsupportedAggregationException e) { log.error("Non-comparable value: {}", value.getClass()); throw e; }

Prevention

When it happens

Trigger: Calling add() with a non-Comparable, non-KeyValue object, e.g. a byte[] or a POJO without Comparable implementation, or a Comparable whose compareTo throws ClassCastException against the input.

Common situations: Aggregating heterogeneous command results; feeding serialized values (String vs binary) into AGG_MAX; custom result types not wrapped in KeyValue.

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


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/932b3a2ed9f70121. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/executors/aggregators/MaxAggregator.java:40

      return;
    }

    // Handle KeyValue types
    if (max instanceof KeyValue && input instanceof KeyValue) {
      max = (T) aggregateKeyValueMax((KeyValue<?, ?>) max, (KeyValue<?, ?>) input);
      return;
    }

    // Handle Comparable types
    if (max instanceof Comparable && input instanceof Comparable) {
      Comparable<Object> maxComp = (Comparable<Object>) max;
      if (maxComp.compareTo(input) < 0) {
        max = input;
      }
      return;
    }

    throw new UnsupportedAggregationException(
        "AGG_MAX policy requires Comparable types or KeyValue, but got: " + max.getClass().getName()
            + " and " + input.getClass().getName());
  }

  @Override
  public T getResult() {
    return max;
  }

  @SuppressWarnings("unchecked")
  private KeyValue<?, ?> aggregateKeyValueMax(KeyValue<?, ?> kv1, KeyValue<?, ?> kv2) {
    Object maxKey = ((Comparable<Object>) kv1.getKey()).compareTo(kv2.getKey()) >= 0 ? kv1.getKey()
        : kv2.getKey();
    Object maxValue = ((Comparable<Object>) kv1.getValue()).compareTo(kv2.getValue()) >= 0
        ? kv1.getValue()
        : kv2.getValue();
    return new KeyValue<>(maxKey, maxValue);
  }

View on GitHub (pinned to 6dac31d4c2)