apache/druid · error · java.lang.UnsupportedOperationException

StringFirstAggregator does not support getLong()

Error message

StringFirstAggregator does not support getLong()

What it means

StringFirstBufferAggregator's per-group cell holds a serialized string pair, so getLong(ByteBuffer,int) is unsupported and always throws UnsupportedOperationException. Numeric long reads of string-first aggregates are invalid.

Source

Thrown at processing/src/main/java/org/apache/druid/query/aggregation/firstlast/first/StringFirstBufferAggregator.java:121

    }
  }

  @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
  }

  @Override
  public void inspectRuntimeShape(RuntimeShapeInspector inspector)
  {
    inspector.visit("timeSelector", timeSelector);

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Use get(buf, position) to obtain the deserialized string pair.
  2. Correct the outputType or post-aggregator to expect a string.
  3. Switch to longFirst aggregation when a numeric earliest value is required.
  4. Branch on aggregator type before calling numeric getters.

Example fix

// before
long v = bufAggregator.getLong(buf, pos);
// after
Object v = bufAggregator.get(buf, pos); // SerializablePairLongString
Defensive patterns

Strategy: type-guard

Validate before calling

if (bufAggregator instanceof StringFirstBufferAggregator) {
  Object v = bufAggregator.get(buf, position);
} else {
  long v = bufAggregator.getLong(buf, position);
}

Type guard

boolean supportsLong(BufferAggregator a) {
  return !(a instanceof StringFirstBufferAggregator);
}

Try / catch

try {
  return agg.getLong(buf, pos);
} catch (UnsupportedOperationException e) {
  Object pair = agg.get(buf, pos);
  return pair == null ? 0L : Long.parseLong(String.valueOf(((SerializablePairLongString) pair).rhs));
}

Prevention

When it happens

Trigger: Calling getLong(buf, position) on a StringFirstBufferAggregator — e.g. code path assuming long-typed aggregator output, or outputType LONG configured for stringFirst with buffer aggregation enabled.

Common situations: Vectorized/buffered group-by queries with a numeric outputType on stringFirst; generic result-reading utilities calling getLong for all aggregators.

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