{"record":{"id":"589654f0593585a1","repo":"apache/druid","slug":"cardinalityaggregator-does-not-support-getdouble","errorCode":null,"errorMessage":"CardinalityAggregator does not support getDouble()","messagePattern":"CardinalityAggregator does not support getDouble\\(\\)","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/aggregation/cardinality/CardinalityAggregator.java","lineNumber":118,"sourceCode":"    return HyperLogLogCollector.makeCollectorSharingStorage(collector);\n  }\n\n  @Override\n  public float getFloat()\n  {\n    throw new UnsupportedOperationException(\"CardinalityAggregator does not support getFloat()\");\n  }\n\n  @Override\n  public long getLong()\n  {\n    throw new UnsupportedOperationException(\"CardinalityAggregator does not support getLong()\");\n  }\n\n  @Override\n  public double getDouble()\n  {\n    throw new UnsupportedOperationException(\"CardinalityAggregator does not support getDouble()\");\n  }\n\n  @Override\n  public void close()\n  {\n    // no resources to cleanup\n  }\n}\n","sourceCodeStart":100,"sourceCodeEnd":127,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/aggregation/cardinality/CardinalityAggregator.java#L100-L127","documentation":"Same unsupported-accessor guard for the double case: CardinalityAggregator.getDouble() always throws UnsupportedOperationException because a HyperLogLog sketch cannot yield a double; only the sketch object (get()) and its later estimateDouble() are meaningful.","triggerScenarios":"Calling aggregator.getDouble() on a CardinalityAggregator when a double-typed result is assumed by the caller.","commonSituations":"Treating cardinality aggregations as numeric in custom query code or post-aggregators; engine paths that request double output for all aggregations.","solutions":["Use a HyperLogLogBucketConversion or finalizing post-aggregator that calls estimate on the sketch instead of getDouble().","Keep cardinality aggregate columns typed as HLL sketch/complex in the plan.","Report a planner bug if the engine coerces a cardinality aggregate to DOUBLE during aggregation."],"exampleFix":"// before\ndouble v = aggregator.getDouble();\n// after\nObject v = aggregator.get(); // HyperLogLogCollector / estimate","handlingStrategy":"validation","validationCode":"if (!(aggFactory instanceof CardinalityAggregatorFactory)) { double v = aggregator.getDouble(); }","typeGuard":"if (aggregator instanceof CardinalityAggregator) {\n    Object v = aggregator.get();\n} else {\n    double v = aggregator.getDouble();\n}","tryCatchPattern":"try {\n    v = aggregator.getDouble();\n} catch (UnsupportedOperationException e) {\n    v = Double.NaN; // or extract estimate from get()\n}","preventionTips":["Use double aggregators for double output","Do not cast cardinality results to numeric primitives directly","Document cardinality aggregator output type in custom aggregation code"],"tags":["java","druid","aggregation","cardinality","unsupported"],"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"}