apache/druid · error · IllegalStateException

Cannot return double for Null Value

Error message

Cannot return double for Null Value

What it means

NullableNumericAggregator throws this IllegalStateException from getDouble() when the aggregated result is null (isNullResult == true). Druid models null numerics explicitly; returning NaN or 0.0 would be ambiguous, so callers must check isNull() first.

Source

Thrown at processing/src/main/java/org/apache/druid/query/aggregation/NullableNumericAggregator.java:101

      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();
  }

  @Override
  public void close()
  {
    delegate.close();
  }
}

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Guard with agg.isNull() before calling getDouble()
  2. Confirm the query targets the right column and segments actually contain non-null data
  3. Check that the nullable wrapper is being used with a null-aware metric factory as intended
  4. If results should never be null, coalesce the input (e.g., use a nullToDefault expression or filter nulls)

Example fix

// before
double v = agg.getDouble();
// after
double v = agg.isNull() ? 0.0d /* or handle null */ : agg.getDouble();
Defensive patterns

Strategy: type-guard

Validate before calling

if (agg.isNull()) {
  return null;
}

Type guard

Double value = agg.isNull() ? null : agg.getDouble();

Try / catch

try {
  return agg.getDouble();
} catch (IllegalStateException e) {
  if (e.getMessage().contains("Cannot return double for Null Value")) {
    return null;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling getDouble() on an aggregator whose underlying aggregation saw only null values during init/aggregate lifecycle.

Common situations: Double aggregations (doubleSum, doubleMin/Max, doubleFirst/Last, average) over all-null or missing columns; custom extraction code bypassing the null check; post-aggregator code reading raw aggregator state.

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


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/fcea13b82898d470. Report an issue: GitHub.