{"record":{"id":"231fc674d3eb075d","repo":"apache/druid","slug":"casting-to-long-type-is-not-supported","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/ddsketch/src/main/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregator.java","lineNumber":93,"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    this.histogram = null;\n  }\n}\n","sourceCodeStart":75,"sourceCodeEnd":102,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/ddsketch/src/main/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregator.java#L75-L102","documentation":"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.","triggerScenarios":"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.","commonSituations":"Reusing query JSON built for longSum-style aggregators against ddsketch, or sorting/grouping on the raw sketch value.","solutions":["Extract values via ddsketchQuantile / ddsketchQuantiles post-aggregators rather than reading the sketch as a number.","Treat the aggregation result strictly as a sketch object for further sketch post-aggregation.","Switch to longSum or another numeric aggregator if a scalar long is actually what you need."],"exampleFix":"// before\npostAggs: [{\"type\": \"accessor\", \"name\": \"sk\", \"fieldName\": \"sk\"}] // reads long -> throws\n// after\npostAggs: [{\"type\": \"ddsketchQuantile\", \"name\": \"median\", \"field\": {\"type\": \"ddsketchField\", \"fieldName\": \"sk\"}, \"fraction\": 0.5}]","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"Object r = agg.get();\nif (!(r instanceof DDSketch)) { /* not a sketch; handle numerically */ }","tryCatchPattern":"try {\n  long v = result.getLong();\n} catch (UnsupportedOperationException e) {\n  // use ddsketchQuantile post-aggregator to get a long/numeric value\n}","preventionTips":["Treat ddsketch results as complex objects only.","Extract quantiles explicitly in post-aggregation.","Use longSum for plain long metrics."],"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"}