{"record":{"id":"449a57e704a7ad1a","repo":"apache/druid","slug":"stringanybufferaggregator-does-not-support-getlong","errorCode":null,"errorMessage":"StringAnyBufferAggregator does not support getLong()","messagePattern":"StringAnyBufferAggregator does not support getLong\\(\\)","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/aggregation/any/StringAnyBufferAggregator.java","lineNumber":115,"sourceCode":"    if (stringSizeBytes >= 0) {\n      byte[] valueBytes = new byte[stringSizeBytes];\n      copyBuffer.get(valueBytes, 0, stringSizeBytes);\n      return StringUtils.fromUtf8(valueBytes);\n    } else {\n      return null;\n    }\n  }\n\n  @Override\n  public float getFloat(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"StringAnyBufferAggregator does not support getFloat()\");\n  }\n\n  @Override\n  public long getLong(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"StringAnyBufferAggregator does not support getLong()\");\n  }\n\n  @Override\n  public double getDouble(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"StringAnyBufferAggregator does not support getDouble()\");\n  }\n\n  @Override\n  public void close()\n  {\n    // no-op\n  }\n}\n","sourceCodeStart":97,"sourceCodeEnd":130,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/aggregation/any/StringAnyBufferAggregator.java#L97-L130","documentation":"StringAnyBufferAggregator aggregates strings; numeric accessors are meaningless for its UTF-8 string buffer, so getLong() unconditionally throws UnsupportedOperationException. This fires when a query plan or SQL layer requests a long-typed finalization of a string 'ANY'/'LATEST' style aggregate — a type mismatch in the aggregation contract.","triggerScenarios":"Calling bufferAggregator.getLong(buf, position) on a StringAnyAggregatorFactory-created aggregator, typically when the query engine or a caller assumes a numeric output type.","commonSituations":"Numeric extraction of a string any-aggregation result; misconfigured query where the 'any' aggregator is used in place of a numeric aggregator.","solutions":["Do not cast the string ANY()/aggregated column to BIGINT; treat the result as VARCHAR.","If a numeric value is needed, aggregate the underlying numeric column instead of the string form.","Check the SQL planner output if a numeric type was wrongly inferred for the aggregator."],"exampleFix":"// before\nlong v = bufferAggregator.getLong(buf, position);\n// after\nObject v = bufferAggregator.get(buf, position); // string result","handlingStrategy":"validation","validationCode":"if (aggFactory instanceof StringAnyAggregatorFactory) { /* read via get(), not getLong */ }","typeGuard":"if (factory instanceof StringAnyAggregatorFactory) {\n    Object v = bufferAggregator.get(buf, position);\n} else {\n    long v = bufferAggregator.getLong(buf, position);\n}","tryCatchPattern":"try {\n    v = bufferAggregator.getLong(buf, position);\n} catch (UnsupportedOperationException e) {\n    v = 0L; // or fall back to string get() + parse\n}","preventionTips":["Use a long aggregator when long output is needed","Check the aggregation output type before numeric extraction","Avoid mixing 'any' aggregators with numeric result-row readers"],"tags":["java","druid","aggregation","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-17T15:17:12.973Z"}