apache/druid · error · IllegalStateException

Cannot return float for Null Value

Error message

Cannot return float for Null Value

What it means

NullableNumericAggregator wraps an underlying aggregator and tracks whether the aggregated result is null via isNullResult. Druid treats a null numeric result as a distinct state, so calling getFloat() while the result is null would silently return 0.0f, hiding the null. This IllegalStateException is thrown instead to force callers to check isNull() before reading a primitive value.

Source

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

      delegate.aggregate();
    }
  }

  @Override
  @Nullable
  public Object get()
  {
    if (isNullResult) {
      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");

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Call aggregator.isNull() first and only call getFloat() when it returns false
  2. Check that the query/column should really be non-null; a fully-null input column means the result is legitimately null
  3. If implementing a wrapper, ensure isNullResult is reset in reset()/init() so stale null state does not persist
  4. Upgrade/verify Druid version — mismatches between null-handling in the query engine and the aggregator have been fixed over time

Example fix

// before
float v = agg.getFloat();
// after
Float v = agg.isNull() ? null : agg.getFloat();
Defensive patterns

Strategy: type-guard

Validate before calling

// before extracting a primitive
if (agg.isNull()) {
  return null; // or a default
}

Type guard

Float value = agg.isNull() ? null : agg.getFloat();

Try / catch

try {
  return agg.getFloat();
} catch (IllegalStateException e) {
  if (e.getMessage().contains("Cannot return float for Null Value")) {
    return null; // treat as null result
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling getFloat() on a NullableNumericAggregator whose delegate aggregator produced no non-null values (isNullResult == true), typically during result materialization of an aggregation over a column where every row was null.

Common situations: Queries aggregating (sum/min/max/count of numerics) over a column that is entirely null or missing in the segment; custom code iterating aggregation results without consulting aggregator.isNull(); SQL-layer regressions where null handling was expected but the vectorized/non-vectorized path mismatched.

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/16f35a331cf21eb6. Report an issue: GitHub.