apache/druid · error · UnsupportedOperationException
StringAnyAggregator does not support getLong()
Error message
StringAnyAggregator does not support getLong()
What it means
StringAnyAggregator's getLong() throws UnsupportedOperationException with this message because the aggregator's value is a string and cannot be exposed as a long. The class implements typed accessors only to reject them clearly rather than silently coercing or returning a sentinel value.
Solutions
- Read the value via getString() and cast to long in a CastPostAggregator if numeric consumption is required
- Aggregate the numeric column itself (longAny/longSum) rather than its string representation
- Change downstream post-aggregators to accept string results (string post-aggregators)
- Correct type mappings in ingestion so the column's type matches the aggregator usage
Example fix
// before aggregatorSelector.getLong() on stringAny result // after String v = aggregatorSelector.getString(); long l = v == null ? 0L : Long.parseLong(v); // or a CastPostAggregator to LONG
Defensive patterns
Strategy: type-guard
Validate before calling
if (aggregator instanceof StringAnyAggregator) {
throw new ISE("stringAny metric cannot be read as long");
} Type guard
boolean supportsLong(Aggregator a) { return !(a instanceof StringAnyAggregator); } Try / catch
try {
long l = aggregator.getLong();
} catch (UnsupportedOperationException e) {
String s = aggregator.getString();
long l = s == null ? 0L : Long.parseLong(s);
} Prevention
- Only call getLong() on long-typed aggregators; use getString() for stringAny
- Insert cast post-aggregators when a string value must become numeric
- Verify column types at ingestion so numeric columns are not stored as strings
- Generic result consumers should branch on aggregator type before accessor calls
When it happens
Trigger: A post-aggregator or result-row accessor calls getLong() on the output of a stringAny aggregator; e.g. a longSum post-aggregator or numeric expression expecting a long-typed field wired to a string-valued any aggregation.
Common situations: Hand-written native queries mixing string and numeric aggregators under one post-aggregator; SQL queries where a numeric column was ingested as string and aggregated with any then consumed numerically.
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
- StringAnyAggregator does not support getDouble()
- StringAnyAggregator does not support getFloat()
- Aggregator[ ] cannot vectorize
- ApproximateHistogramBufferAggregator does not support…
- ApproximateHistogramBufferAggregator does not support…
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/f8588bb1e0ccac04.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/query/aggregation/any/StringAnyAggregator.java:92
return DimensionHandlerUtils.convertObjectToString(object);
}
@Override
public Object get()
{
return foundValue;
}
@Override
public float getFloat()
{
throw new UnsupportedOperationException("StringAnyAggregator does not support getFloat()");
}
@Override
public long getLong()
{
throw new UnsupportedOperationException("StringAnyAggregator does not support getLong()");
}
@Override
public double getDouble()
{
throw new UnsupportedOperationException("StringAnyAggregator does not support getDouble()");
}
@Override
public void close()
{
// no-op
}
}
View on GitHub (pinned to 9b90983fd2)