apache/druid · error · UnsupportedOperationException

Casting to long type is not supported

Error message

Casting to long type is not supported

What it means

DDSketchAggregator.getLong() throws UnsupportedOperationException because a DDSketch histogram cannot be reduced to a single long; the aggregator's result is a complex sketch object. This fires when the query engine asks the aggregation for a long-typed value.

Source

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

  }

  @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. Extract values via ddsketchQuantile / ddsketchQuantiles post-aggregators rather than reading the sketch as a number.
  2. Treat the aggregation result strictly as a sketch object for further sketch post-aggregation.
  3. Switch to longSum or another numeric aggregator if a scalar long is actually what you need.

Example fix

// before
postAggs: [{"type": "accessor", "name": "sk", "fieldName": "sk"}] // reads long -> throws
// after
postAggs: [{"type": "ddsketchQuantile", "name": "median", "field": {"type": "ddsketchField", "fieldName": "sk"}, "fraction": 0.5}]
Defensive patterns

Strategy: type-guard

Type guard

Object r = agg.get();
if (!(r instanceof DDSketch)) { /* not a sketch; handle numerically */ }

Try / catch

try {
  long v = result.getLong();
} catch (UnsupportedOperationException e) {
  // use ddsketchQuantile post-aggregator to get a long/numeric value
}

Prevention

When it happens

Trigger: Consuming the ddsketch aggregation output with a long accessor, using a finalizer expecting a long, or selecting the sketch column where the engine requires a numeric metric.

Common situations: Reusing query JSON built for longSum-style aggregators against ddsketch, or sorting/grouping on the raw sketch value.

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/231fc674d3eb075d. Report an issue: GitHub.