{"record":{"id":"697d8bfd3fe39095","repo":"apache/druid","slug":"casting-to-float-type-is-not-supported","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/ddsketch/src/main/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregator.java","lineNumber":87,"sourceCode":"            \"Expected a number or an instance of DDSketch, but received [%s] of type [%s]\",\n            obj,\n            obj.getClass()\n        );\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    this.histogram = null;\n  }\n}\n","sourceCodeStart":69,"sourceCodeEnd":102,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/ddsketch/src/main/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregator.java#L69-L102","documentation":"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).","triggerScenarios":"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.","commonSituations":"Querying the sketch column directly without the ddsketchQuantile post-aggregator, or older queries written for numeric aggregators reused against ddsketch.","solutions":["Wrap the sketch in the ddsketchQuantiles/ddsketchQuantile post-aggregator to extract numeric quantiles.","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.","If you only need simple stats, use doubleSum/doubleMin/doubleMax aggregators instead of ddsketch."],"exampleFix":"// before\naggregations: [{\"type\": \"ddsketch\", \"name\": \"sk\", \"fieldName\": \"latency\"}], postAggregations: [{\"type\": \"finalizer\", \"name\": \"sk\"}]\n// after\npostAggregations: [{\"type\": \"ddsketchQuantile\", \"name\": \"p95\", \"field\": {\"type\": \"ddsketchField\", \"fieldName\": \"sk\"}, \"fraction\": 0.95}]","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"Object r = agg.get();\nif (r instanceof DDSketch) { /* extract via quantile post-agg */ } else { /* use numeric aggregator */ }","tryCatchPattern":"try {\n  Number v = result.getFloat();\n} catch (UnsupportedOperationException e) {\n  // re-read as DDSketch and compute quantiles instead\n}","preventionTips":["Never use ddsketch output as a plain numeric metric.","Always finalize with ddsketchQuantile/ddsketchQuantiles post-aggregators.","Pick doubleSum/min/max when a scalar number is what you need."],"tags":["ddsketch","unsupported-operation","aggregation"],"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"}