apache/druid · error · java.lang.UnsupportedOperationException

StringFirstAggregator does not support getFloat()

Error message

StringFirstAggregator does not support getFloat()

What it means

StringLastBufferAggregator is the buffer-backed (off-heap) variant of the string-last aggregator. It stores timestamp/string pairs in ByteBuffers and cannot return a float, so getFloat(ByteBuffer,int) throws UnsupportedOperationException. The message text references StringFirstAggregator due to shared/copied message strings in this package.

Source

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

            buf,
            position,
            new SerializablePairLongString(time, value),
            maxStringBytes
        );
      }
    }
  }

  @Override
  public Object get(ByteBuffer buf, int position)
  {
    return StringFirstLastUtils.readPair(buf, position);
  }

  @Override
  public float getFloat(ByteBuffer buf, int position)
  {
    throw new UnsupportedOperationException("StringFirstAggregator does not support getFloat()");
  }

  @Override
  public long getLong(ByteBuffer buf, int position)
  {
    throw new UnsupportedOperationException("StringFirstAggregator does not support getLong()");
  }

  @Override
  public double getDouble(ByteBuffer buf, int position)
  {
    throw new UnsupportedOperationException("StringFirstAggregator does not support getDouble()");
  }

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

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Use the string pair reader (StringFirstLastUtils.readPair) / get() path to obtain the value
  2. Use a float-typed aggregator (floatLast/doubleFirst variants) if a float is required
  3. Branch on the factory's type name before invoking typed accessors

Example fix

// before
float f = bufAgg.getFloat(buf, position); // throws
// after
String[] pair = StringFirstLastUtils.readPair(buf, position); // [time, value]
Object v = bufAgg.get(buf, position);
Defensive patterns

Strategy: type-guard

Validate before calling

if ("string".equals(factory.getTypeName())) { /* use StringFirstLastUtils.readPair */ }

Type guard

static boolean hasFloatAccessor(AggregatorFactory f) { return f.getTypeName().equals("float"); }

Try / catch

try { f = bufAgg.getFloat(buf, pos); } catch (UnsupportedOperationException e) { f = Float.NaN; }

Prevention

When it happens

Trigger: Calling getFloat(buf, position) on a StringLastBufferAggregator, typically when result extraction iterates buffer aggregators assuming numeric column types.

Common situations: Custom query layers or group-by result readers calling float accessors on string metrics; generic aggregation harnesses/tests treating all BufferAggregators as numeric.

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/dddf4e36b21d8526. Report an issue: GitHub.