apache/druid · error · IllegalStateException
Cannot return null value as double
Error message
Cannot return null value as double
What it means
NilColumnValueSelector represents a column whose every value is null. Since primitives cannot be null in Java, getDouble() throws IllegalStateException instead of returning a value. Callers must check isNull()/getObject() before requesting primitive access on a null column.
Solutions
- Check selector.isNull() or use getObject() and handle null before calling getDouble()
- Ensure the queried column exists in the datasource/segment (verify with SegmentMetadataQuery)
- Use default value handling in the query (e.g. SQL COALESCE) so missing columns are substituted
- If ingesting, supply a default for the numeric field in the ingestion spec
Example fix
// before double d = selector.getDouble(); // after Object val = selector.isNull() ? null : selector.getObject(); double d = val == null ? 0.0 : ((Number) val).doubleValue();
Defensive patterns
Strategy: type-guard
Validate before calling
if (selector.getObject() == null) { /* treat as missing */ } Type guard
Double safeGetDouble(ColumnValueSelector<?> s) { return s.isNull() ? null : s.getDouble(); } Try / catch
try {
double d = selector.getDouble();
} catch (IllegalStateException e) {
double d = 0.0; // default for null column
} Prevention
- Always call isNull() before primitive getters on selectors
- Use SQL COALESCE for possibly-missing numeric columns
- Verify column existence in datasource schema before querying
When it happens
Trigger: Calling getDouble() on a column selector created by NilColumnValueSelector — e.g. querying a numeric column that does not exist in a row/segment, or accessing a typed selector on rows lacking the value.
Common situations: Queries against datasources where a numeric column is absent in some segments; row-based ingestion where rows omit a numeric field; misconfigured query columns pointing at nonexistent metrics.
Related errors
- Cannot return null value as float
- Cannot return null value as long
- 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/fc44748d36dc2b8a.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/segment/NilColumnValueSelector.java:50
{
private static final NilColumnValueSelector INSTANCE = new NilColumnValueSelector();
public static NilColumnValueSelector instance()
{
return INSTANCE;
}
private NilColumnValueSelector()
{
}
/**
* always throws an exception, all values in this column are null
*/
@Override
public double getDouble()
{
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");View on GitHub (pinned to 9b90983fd2)