{"record":{"id":"34923b160224b275","repo":"apache/druid","slug":"stringanyaggregator-does-not-support-getfloat","errorCode":null,"errorMessage":"StringAnyAggregator does not support getFloat()","messagePattern":"StringAnyAggregator does not support getFloat\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/aggregation/any/StringAnyAggregator.java","lineNumber":86,"sourceCode":"      }\n      if (aggregateMultipleValues) {\n        return DimensionHandlerUtils.convertObjectToString(objectList);\n      }\n      return DimensionHandlerUtils.convertObjectToString(objectList.get(0));\n    }\n    return DimensionHandlerUtils.convertObjectToString(object);\n  }\n\n  @Override\n  public Object get()\n  {\n    return foundValue;\n  }\n\n  @Override\n  public float getFloat()\n  {\n    throw new UnsupportedOperationException(\"StringAnyAggregator does not support getFloat()\");\n  }\n\n  @Override\n  public long getLong()\n  {\n    throw new UnsupportedOperationException(\"StringAnyAggregator does not support getLong()\");\n  }\n\n  @Override\n  public double getDouble()\n  {\n    throw new UnsupportedOperationException(\"StringAnyAggregator does not support getDouble()\");\n  }\n\n  @Override\n  public void close()\n  {\n    // no-op","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/aggregation/any/StringAnyAggregator.java#L68-L104","documentation":"StringAnyAggregator stores an arbitrary string value, so its getFloat() accessor is meaningless and deliberately throws UnsupportedOperationException with this message. The aggregator API exposes typed getters and calling a numeric getter on a string aggregator is an API misuse that the class rejects eagerly rather than returning a wrong value.","triggerScenarios":"A query's post-aggregator or result layer calls getFloat() on the result of a stringAny (or filtered any over a string column) aggregator; e.g. a numeric post-aggregator (arithmetic, cast) wired to a string-typed any-aggregator output.","commonSituations":"Building native JSON queries by hand and pointing a doubleSum/arithmetic post-aggregator at a stringAny metric; SQL layer mis-mapping where a VARCHAR expression is aggregated with any and then treated numerically downstream.","solutions":["Use getString() on the aggregator's result instead of getFloat(); adjust post-aggregators to string-capable ones (stringFormat/cast post-aggregators)","If a numeric value is required, aggregate the underlying numeric column directly (doubleAny/doubleSum) instead of its string form","Wrap the string result with a cast post-aggregator (e.g. string-to-double) before feeding numeric post-aggregators","Fix the query planner/spec so the aggregator's result type matches what downstream code reads"],"exampleFix":"// before\nnew ArithmeticPostAggregator(\"p\", \"+\", List.of(new FieldAccessPostAggregator(\"a\", \"stringAnyMetric\")))\n// after\nnew CastPostAggregator(\"aAsDouble\", new FieldAccessPostAggregator(\"a\", \"stringAnyMetric\"), \"DOUBLE\", null)","handlingStrategy":"type-guard","validationCode":"// Confirm metric type before wiring a numeric post-aggregator\nif (aggregator instanceof StringAnyAggregator) {\n  throw new ISE(\"stringAny metric cannot feed a numeric post-aggregator\");\n}","typeGuard":"boolean isStringAggregator(Aggregator a) { return a instanceof StringAnyAggregator; }","tryCatchPattern":"try {\n  float f = aggregator.getFloat();\n} catch (UnsupportedOperationException e) {\n  String s = aggregator.getString();\n  // fall back to string handling / cast\n}","preventionTips":["Match post-aggregator input types to aggregator output types (string vs numeric)","Use CastPostAggregator to convert string results before numeric operations","Prefer aggregating the numeric column directly over string representations","Add type checks in query-building code that consumes aggregator results generically"],"tags":["aggregation","unsupported-operation","type-mismatch","druid"],"backgroundTag":"unsupported-operation","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}