apache/druid · error · UnsupportedOperationException

Casting to long type is not supported

Error message

Casting to long type is not supported

What it means

Same rationale as the float case: a TDigestSketch cannot be represented as a single long, so getLong() always throws UnsupportedOperationException. The query is asking for a long-typed scalar from a distribution-typed aggregate.

Source

Thrown at extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregator.java:97

  }

  @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()
  {
    histogram = null;
  }
}

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Use sketch-aware post-aggregators (quantile, min, max) to obtain a numeric value.
  2. Remove the BIGINT/long cast on the sketch column.
  3. Aggregate the raw numeric column with standard long aggregators if a long is truly needed.

Example fix

// SQL before
SELECT CAST(sketch_col AS BIGINT) FROM t
// after
SELECT TDIGEST_QUANTILE(sketch_col, 0.9) FROM t
Defensive patterns

Strategy: type-guard

Validate before calling

if (factory instanceof TDigestSketchAggregatorFactory && outputType.equals("LONG")) { throw new IllegalArgumentException("tdigestsketch cannot be cast to LONG; use quantile/min/max post-aggregators"); }

Try / catch

try { result = agg.getLong(); } catch (UnsupportedOperationException e) { result = (long) quantilePostAggregator.compute(agg.getObject()); }

Prevention

When it happens

Trigger: Query requesting LONG output from a tdigestsketch aggregator: native query outputType long, SQL CAST(... AS BIGINT), or a long post-aggregator consuming the sketch.

Common situations: Casting sketch results to BIGINT in SQL; framework code defaulting to long output type for aggregators; nested group-by treating the sketch as a numeric metric.

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