apache/druid · error · UnsupportedOperationException

Casting to float type is not supported

Error message

Casting to float type is not supported

What it means

DDSketchAggregator.getFloat() throws UnsupportedOperationException because a DDSketch histogram cannot be meaningfully coerced to a single float; sketches are only exposed as complex objects. This fires when a query requests the sketch aggregation's result as a float (e.g. a float finalizer or float accessor).

Source

Thrown at extensions-contrib/ddsketch/src/main/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregator.java:87

            "Expected a number or an instance of DDSketch, but received [%s] of type [%s]",
            obj,
            obj.getClass()
        );
      }
    }
  }

  @Nullable
  @Override
  public synchronized Object get()
  {
    return histogram;
  }

  @Override
  public float getFloat()
  {
    throw new UnsupportedOperationException("Casting to float type is not supported");
  }

  @Override
  public long getLong()
  {
    throw new UnsupportedOperationException("Casting to long type is not supported");
  }

  @Override
  public synchronized void close()
  {
    this.histogram = null;
  }
}

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Wrap the sketch in the ddsketchQuantiles/ddsketchQuantile post-aggregator to extract numeric quantiles.
  2. Do not treat the ddsketch aggregation result as a numeric metric; use it only as an input to sketch post-aggregators or store it as a sketch column.
  3. If you only need simple stats, use doubleSum/doubleMin/doubleMax aggregators instead of ddsketch.

Example fix

// before
aggregations: [{"type": "ddsketch", "name": "sk", "fieldName": "latency"}], postAggregations: [{"type": "finalizer", "name": "sk"}]
// after
postAggregations: [{"type": "ddsketchQuantile", "name": "p95", "field": {"type": "ddsketchField", "fieldName": "sk"}, "fraction": 0.95}]
Defensive patterns

Strategy: type-guard

Type guard

Object r = agg.get();
if (r instanceof DDSketch) { /* extract via quantile post-agg */ } else { /* use numeric aggregator */ }

Try / catch

try {
  Number v = result.getFloat();
} catch (UnsupportedOperationException e) {
  // re-read as DDSketch and compute quantiles instead
}

Prevention

When it happens

Trigger: Using the ddsketch aggregator's output as a plain float: querying it with a float-typed accessor, applying a finalizer that reads getFloat(), or using it where the engine expects a primitive metric value instead of a complex object.

Common situations: Querying the sketch column directly without the ddsketchQuantile post-aggregator, or older queries written for numeric aggregators reused against ddsketch.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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