{"record":{"id":"f8588bb1e0ccac04","repo":"apache/druid","slug":"stringanyaggregator-does-not-support-getlong","errorCode":null,"errorMessage":"StringAnyAggregator does not support getLong()","messagePattern":"StringAnyAggregator does not support getLong\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/aggregation/any/StringAnyAggregator.java","lineNumber":92,"sourceCode":"    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\n  }\n}\n","sourceCodeStart":74,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/aggregation/any/StringAnyAggregator.java#L74-L107","documentation":"StringAnyAggregator's getLong() throws UnsupportedOperationException with this message because the aggregator's value is a string and cannot be exposed as a long. The class implements typed accessors only to reject them clearly rather than silently coercing or returning a sentinel value.","triggerScenarios":"A post-aggregator or result-row accessor calls getLong() on the output of a stringAny aggregator; e.g. a longSum post-aggregator or numeric expression expecting a long-typed field wired to a string-valued any aggregation.","commonSituations":"Hand-written native queries mixing string and numeric aggregators under one post-aggregator; SQL queries where a numeric column was ingested as string and aggregated with any then consumed numerically.","solutions":["Read the value via getString() and cast to long in a CastPostAggregator if numeric consumption is required","Aggregate the numeric column itself (longAny/longSum) rather than its string representation","Change downstream post-aggregators to accept string results (string post-aggregators)","Correct type mappings in ingestion so the column's type matches the aggregator usage"],"exampleFix":"// before\naggregatorSelector.getLong() on stringAny result\n// after\nString v = aggregatorSelector.getString();\nlong l = v == null ? 0L : Long.parseLong(v); // or a CastPostAggregator to LONG","handlingStrategy":"type-guard","validationCode":"if (aggregator instanceof StringAnyAggregator) {\n  throw new ISE(\"stringAny metric cannot be read as long\");\n}","typeGuard":"boolean supportsLong(Aggregator a) { return !(a instanceof StringAnyAggregator); }","tryCatchPattern":"try {\n  long l = aggregator.getLong();\n} catch (UnsupportedOperationException e) {\n  String s = aggregator.getString();\n  long l = s == null ? 0L : Long.parseLong(s);\n}","preventionTips":["Only call getLong() on long-typed aggregators; use getString() for stringAny","Insert cast post-aggregators when a string value must become numeric","Verify column types at ingestion so numeric columns are not stored as strings","Generic result consumers should branch on aggregator type before accessor calls"],"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"}