apache/druid · error · java.lang.UnsupportedOperationException

StringAnyBufferAggregator does not support getLong()

Error message

StringAnyBufferAggregator does not support getLong()

What it means

StringAnyBufferAggregator aggregates strings; numeric accessors are meaningless for its UTF-8 string buffer, so getLong() unconditionally throws UnsupportedOperationException. This fires when a query plan or SQL layer requests a long-typed finalization of a string 'ANY'/'LATEST' style aggregate — a type mismatch in the aggregation contract.

Solutions

  1. Do not cast the string ANY()/aggregated column to BIGINT; treat the result as VARCHAR.
  2. If a numeric value is needed, aggregate the underlying numeric column instead of the string form.
  3. Check the SQL planner output if a numeric type was wrongly inferred for the aggregator.

Example fix

// before
long v = bufferAggregator.getLong(buf, position);
// after
Object v = bufferAggregator.get(buf, position); // string result
Defensive patterns

Strategy: validation

Validate before calling

if (aggFactory instanceof StringAnyAggregatorFactory) { /* read via get(), not getLong */ }

Type guard

if (factory instanceof StringAnyAggregatorFactory) {
    Object v = bufferAggregator.get(buf, position);
} else {
    long v = bufferAggregator.getLong(buf, position);
}

Try / catch

try {
    v = bufferAggregator.getLong(buf, position);
} catch (UnsupportedOperationException e) {
    v = 0L; // or fall back to string get() + parse
}

Prevention

When it happens

Trigger: Calling bufferAggregator.getLong(buf, position) on a StringAnyAggregatorFactory-created aggregator, typically when the query engine or a caller assumes a numeric output type.

Common situations: Numeric extraction of a string any-aggregation result; misconfigured query where the 'any' aggregator is used in place of a numeric aggregator.

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

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/query/aggregation/any/StringAnyBufferAggregator.java:115

    if (stringSizeBytes >= 0) {
      byte[] valueBytes = new byte[stringSizeBytes];
      copyBuffer.get(valueBytes, 0, stringSizeBytes);
      return StringUtils.fromUtf8(valueBytes);
    } else {
      return null;
    }
  }

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

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

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

  @Override
  public void close()
  {
    // no-op
  }
}

View on GitHub (pinned to 9b90983fd2)