apache/druid · error · IllegalStateException
Cannot return null value as long
Error message
Cannot return null value as long
What it means
NilColumnValueSelector.getLong() throws IllegalStateException since all values in the column are null and long primitives cannot express null. The selector intentionally fails fast instead of silently returning 0. Check null status before primitive access.
Solutions
- Use isNull()/getObject() before calling getLong()
- Confirm the column exists (SegmentMetadataQuery or datasource schema)
- Apply SQL COALESCE or query defaults for missing columns
- Set default values for long fields in the ingestion spec
Example fix
// before long l = selector.getLong(); // after long l = selector.isNull() ? 0L : ((Number) selector.getObject()).longValue();
Defensive patterns
Strategy: type-guard
Validate before calling
if (selector.isNull()) { /* handle missing */ } Type guard
Long safeGetLong(ColumnValueSelector<?> s) { return s.isNull() ? null : s.getLong(); } Try / catch
try {
long l = selector.getLong();
} catch (IllegalStateException e) {
long l = 0L;
} Prevention
- Check isNull() before getLong()
- Use getObject() and null-check for nullable long metrics
- Validate column names against the datasource schema
When it happens
Trigger: Calling getLong() on a selector for a fully-null long column — e.g. a missing metric column in a segment or rows omitting the field.
Common situations: Queries against datasources where the long metric is missing in some segments; row-based ingestion with absent fields; typo'd column names in queries.
Related errors
- Cannot return null value as double
- Cannot return null value as float
- A table definition must include a table spec.
- Could not transform value for __time.
- Unexpected null value in BloomFilterMergeAggregator
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/c78947adf3905a71.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/segment/NilColumnValueSelector.java:68
throw new IllegalStateException("Cannot return null value as double");
}
/**
* always throws an exception, all values in this column are null
*/
@Override
public float getFloat()
{
throw new IllegalStateException("Cannot return null value as float");
}
/**
* always throws an exception, all values in this column are null
*/
@Override
public long getLong()
{
throw new IllegalStateException("Cannot return null value as long");
}
/**
* Always returns null.
*/
@Nullable
@Override
public Object getObject()
{
return null;
}
/**
* Returns Object.class.
*/
@Override
public Class classOfObject()
{View on GitHub (pinned to 9b90983fd2)