apache/druid · error · IllegalStateException

Cannot return null value as float

Error message

Cannot return null value as float

What it means

NilColumnValueSelector.getFloat() throws IllegalStateException because every value in this column is null and there is no valid float to return. Java primitives cannot represent null, so the selector signals the error rather than returning 0. Callers must test for null before primitive access.

Solutions

  1. Check isNull() or read via getObject() and convert defensively
  2. Verify the float column exists in the segment/datasource before querying
  3. Use query-level defaulting (SQL COALESCE) for missing columns
  4. Provide defaults for float fields during ingestion

Example fix

// before
float f = selector.getFloat();
// after
float f = selector.isNull() ? 0.0f : ((Number) selector.getObject()).floatValue();
Defensive patterns

Strategy: type-guard

Validate before calling

if (selector.isNull()) { /* handle missing */ }

Type guard

Float safeGetFloat(ColumnValueSelector<?> s) { return s.isNull() ? null : s.getFloat(); }

Try / catch

try {
  float f = selector.getFloat();
} catch (IllegalStateException e) {
  float f = 0.0f;
}

Prevention

When it happens

Trigger: Calling getFloat() on a selector from a fully-null column — e.g. a missing float column in a segment or a row lacking that field in row-based ingestion.

Common situations: Queries referencing float columns absent from some segments; ingestion rows missing float fields; queries against empty datasources.

Related errors


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

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/segment/NilColumnValueSelector.java:59

  {
  }

  /**
   * 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");
  }

  /**
   * Always returns null.
   */
  @Nullable
  @Override
  public Object getObject()
  {

View on GitHub (pinned to 9b90983fd2)