{"record":{"id":"5ce3c161590bd042","repo":"apache/druid","slug":"casting-to-float-type-is-not-supported-5ce3c1","errorCode":null,"errorMessage":"Casting to float type is not supported","messagePattern":"Casting to float 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":91,"sourceCode":"      throw new IAE(\n          \"Expected a number or an instance of MergingDigest, but received [%s] of type [%s]\",\n          obj,\n          obj.getClass()\n      );\n    }\n  }\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":73,"sourceCodeEnd":106,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregator.java#L73-L106","documentation":"The tdigestsketch aggregator's result is a TDigestSketch (a distribution), which cannot be meaningfully cast to a single float. getFloat() therefore always throws UnsupportedOperationException, indicating the requested SQL/output type is incompatible with the aggregation.","triggerScenarios":"Running a query that requests FLOAT output for a tdigestsketch aggregate, e.g. SQL casting the sketch column to FLOAT, or native query with a float post-aggregator / float output type.","commonSituations":"SQL like SELECT CAST(tdigest_col AS FLOAT) ...; using the sketch in a query expecting a scalar numeric result instead of going through sketch accessor post-aggregators (quantile, min, max).","solutions":["Extract a scalar via TDigestSketchQuantilePostAggregator, or min/max post-aggregators instead of casting the sketch.","Remove the cast to FLOAT on the sketch column.","If a number is wanted, aggregate the underlying numeric column directly, not the sketch."],"exampleFix":"// SQL before\nSELECT CAST(sketch_col AS FLOAT) FROM t\n// after\nSELECT TDIGEST_QUANTILE(sketch_col, 0.5) FROM t","handlingStrategy":"type-guard","validationCode":"if (factory instanceof TDigestSketchAggregatorFactory && outputType.equals(\"FLOAT\")) { throw new IllegalArgumentException(\"tdigestsketch cannot be cast to FLOAT; use quantile/min/max post-aggregators\"); }","typeGuard":null,"tryCatchPattern":"try { result = agg.getFloat(); } catch (UnsupportedOperationException e) { result = (float) quantilePostAggregator.compute(agg.getObject()); }","preventionTips":["Never CAST sketch columns to FLOAT/BIGINT in SQL.","Extract scalars with TDIGEST_QUANTILE or min/max post-aggregators.","Check expected output types when writing native queries against sketch 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"}