{"record":{"id":"cfd916a11c6b109c","repo":"apache/druid","slug":"casting-to-long-type-is-not-supported-cfd916","errorCode":null,"errorMessage":"Casting to long type is not supported","messagePattern":"Casting to long type is not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregator.java","lineNumber":97,"sourceCode":"  }\n\n  @Nullable\n  @Override\n  public synchronized Object get()\n  {\n    return histogram;\n  }\n\n  @Override\n  public float getFloat()\n  {\n    throw new UnsupportedOperationException(\"Casting to float type is not supported\");\n  }\n\n  @Override\n  public long getLong()\n  {\n    throw new UnsupportedOperationException(\"Casting to long type is not supported\");\n  }\n\n  @Override\n  public synchronized void close()\n  {\n    histogram = null;\n  }\n}\n","sourceCodeStart":79,"sourceCodeEnd":106,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregator.java#L79-L106","documentation":"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.","triggerScenarios":"Query requesting LONG output from a tdigestsketch aggregator: native query outputType long, SQL CAST(... AS BIGINT), or a long post-aggregator consuming the sketch.","commonSituations":"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.","solutions":["Use sketch-aware post-aggregators (quantile, min, max) to obtain a numeric value.","Remove the BIGINT/long cast on the sketch column.","Aggregate the raw numeric column with standard long aggregators if a long is truly needed."],"exampleFix":"// SQL before\nSELECT CAST(sketch_col AS BIGINT) FROM t\n// after\nSELECT TDIGEST_QUANTILE(sketch_col, 0.9) FROM t","handlingStrategy":"type-guard","validationCode":"if (factory instanceof TDigestSketchAggregatorFactory && outputType.equals(\"LONG\")) { throw new IllegalArgumentException(\"tdigestsketch cannot be cast to LONG; use quantile/min/max post-aggregators\"); }","typeGuard":null,"tryCatchPattern":"try { result = agg.getLong(); } catch (UnsupportedOperationException e) { result = (long) quantilePostAggregator.compute(agg.getObject()); }","preventionTips":["Avoid BIGINT casts on sketch columns.","Use sketch post-aggregators for numeric extraction.","Configure native query outputType compatible with complex metrics."],"tags":["java","druid","tdigest","unsupported-cast"],"backgroundTag":"unsupported-operation","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}