apache/druid · error · java.lang.UnsupportedOperationException

StringLastAggregator does not support getFloat()

Error message

StringLastAggregator does not support getFloat()

What it means

StringLastAggregator computes the latest string value per group; its result is a string (wrapped in SerializablePairLongString), not numeric. getFloat() is unsupported and always throws UnsupportedOperationException. Numeric reads of string-last output are invalid.

Solutions

  1. Read the value via the aggregator's object/string getter.
  2. Remove numeric outputType or post-aggregators applied to stringLast.
  3. Use FloatLastAggregator (type "floatLast") for a numeric latest value.
  4. Verify the aggregator type before numeric access.

Example fix

// before
{"type":"stringLast","name":"s","fieldName":"col","outputType":"FLOAT"}
// after
{"type":"stringLast","name":"s","fieldName":"col"}
Defensive patterns

Strategy: type-guard

Validate before calling

if (aggregator instanceof StringLastAggregator) {
  Object v = aggregator.get();
} else {
  float v = aggregator.getFloat();
}

Type guard

boolean supportsFloat(Aggregator a) {
  return !(a instanceof StringLastAggregator);
}

Try / catch

try {
  return agg.getFloat();
} catch (UnsupportedOperationException e) {
  Object pair = agg.get();
  return pair == null ? 0f : Float.parseFloat(String.valueOf(((SerializablePairLongString) pair).rhs));
}

Prevention

When it happens

Trigger: Calling getFloat() on StringLastAggregator — e.g. a post-aggregator, finalizer, or generic numeric accessor treating the string-last aggregate as a float.

Common situations: FLOAT outputType configured for stringLast; custom post-aggregation over stringLast; shared code calling all numeric getters on aggregator results.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/411187f2876d5ad2. Report an issue: GitHub.

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/query/aggregation/firstlast/last/StringLastAggregator.java:95

      if (time >= lastTime) {
        final String value = DimensionHandlerUtils.convertObjectToString(valueSelector.getObject());
        lastTime = time;
        lastValue = StringUtils.fastLooseChop(value, maxStringBytes);
      }
    }
  }

  @Override
  public Object get()
  {
    return new SerializablePairLongString(lastTime, StringUtils.chop(lastValue, maxStringBytes));
  }

  @Override
  public float getFloat()
  {
    throw new UnsupportedOperationException("StringLastAggregator does not support getFloat()");
  }

  @Override
  public long getLong()
  {
    throw new UnsupportedOperationException("StringLastAggregator does not support getLong()");
  }

  @Override
  public double getDouble()
  {
    throw new UnsupportedOperationException("StringLastAggregator does not support getDouble()");
  }

  @Override
  public void close()
  {
    // no resources to cleanup

View on GitHub (pinned to 9b90983fd2)