apache/druid · error · IllegalStateException
Cannot return long for Null Value
Error message
Cannot return long for Null Value
What it means
Same contract as getFloat(): NullableNumericAggregator tracks a null result state and refuses to return a primitive long when the aggregated value is null. Returning 0L would mask the null, so an IllegalStateException is thrown from getLong().
Source
Thrown at processing/src/main/java/org/apache/druid/query/aggregation/NullableNumericAggregator.java:92
return null;
}
return delegate.get();
}
@Override
public float getFloat()
{
if (isNullResult) {
throw new IllegalStateException("Cannot return float for Null Value");
}
return delegate.getFloat();
}
@Override
public long getLong()
{
if (isNullResult) {
throw new IllegalStateException("Cannot return long for Null Value");
}
return delegate.getLong();
}
@Override
public double getDouble()
{
if (isNullResult) {
throw new IllegalStateException("Cannot return double for Null Value");
}
return delegate.getDouble();
}
@Override
public boolean isNull()
{
return isNullResult || delegate.isNull();
}View on GitHub (pinned to 9b90983fd2)
Solutions
- Check agg.isNull() before calling getLong() and handle the null branch (e.g., return null or a default)
- Verify the input column actually contains non-null long values in the queried segments
- Ensure aggregator init/reset is called correctly so isNullResult reflects only the current aggregation
- If the null is unexpected, inspect the selector/factory wiring to confirm the base aggregator is reading the intended column
Example fix
// before long v = agg.getLong(); // after Long v = agg.isNull() ? null : agg.getLong();
Defensive patterns
Strategy: type-guard
Validate before calling
if (agg.isNull()) {
return null;
} Type guard
Long value = agg.isNull() ? null : agg.getLong();
Try / catch
try {
return agg.getLong();
} catch (IllegalStateException e) {
if (e.getMessage().contains("Cannot return long for Null Value")) {
return null;
}
throw e;
} Prevention
- Check isNull() before any primitive getter on NullableNumericAggregator
- Handle all-null columns explicitly in query/extract code
- Verify segment schemas for the queried interval (column may be absent/null in some segments)
- Keep aggregator reset/init logic symmetric so null state never leaks between queries
When it happens
Trigger: Calling getLong() while isNullResult is true — i.e., the wrapped aggregator aggregated only null values and no valid long result exists.
Common situations: Long-typed aggregations (sum, longMin/longMax, longFirst/longLast) over columns that are entirely null or missing; result-extraction code that ignores isNull(); mixed-schema segments where a column is absent in some segments.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Cannot return float for Null Value
- Cannot return double for Null Value
- Cannot return float for Null Value
- Cannot return long for Null Value
- Cannot return double for Null Value
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/04fe7380ed91d226.
Report an issue: GitHub.