{"record":{"id":"a61672ca99ed1116","repo":"apache/druid","slug":"cannot-use-lookupnameutf8-on-this-selector","errorCode":null,"errorMessage":"Cannot use lookupNameUtf8 on this selector","messagePattern":"Cannot use lookupNameUtf8 on this selector","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/frame/field/StringFieldReader.java","lineNumber":247,"sourceCode":"      } else {\n        final ByteBuffer byteBuffer = strings.get(id);\n        final String s = byteBuffer != null ? StringUtils.fromUtf8(byteBuffer.duplicate()) : null;\n        return extractionFn == null ? s : extractionFn.apply(s);\n      }\n    }\n\n    @Override\n    public boolean supportsLookupNameUtf8()\n    {\n      return extractionFn == null;\n    }\n\n    @Nullable\n    @Override\n    public ByteBuffer lookupNameUtf8(int id)\n    {\n      if (extractionFn != null) {\n        throw new ISE(\"Cannot use lookupNameUtf8 on this selector\");\n      }\n\n      final List<ByteBuffer> strings = computeCurrentUtf8Strings();\n      return strings == null ? null : strings.get(id);\n    }\n\n    @Override\n    public int getValueCardinality()\n    {\n      return CARDINALITY_UNKNOWN;\n    }\n\n    @Override\n    public boolean nameLookupPossibleInAdvance()\n    {\n      return false;\n    }\n","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/frame/field/StringFieldReader.java#L229-L265","documentation":"The Selector's lookupNameUtf8 returns raw UTF-8 bytes for dictionary-less string values, but when an ExtractionFn is configured the values in the frame are not the final output values (extraction is applied later), so returning raw UTF-8 would be incorrect. The method therefore refuses with ISE. Callers must use the regular getObject/getString path when an extraction function is present.","triggerScenarios":"Calling lookupNameUtf8 on a BaseStringSelector produced by StringFieldReader's Selector after makeDimensionSelector(..., extractionFn) with a non-null ExtractionFn.","commonSituations":"Engine code optimized for the UTF-8 fast path (e.g. group-by v2 dimension readers) hitting frames whose selectors were wrapped with extraction functions such as regex, lookup, or time-format extraction.","solutions":["Do not call lookupNameUtf8 when extractionFn != null; check the flag first and fall back to getString/getObject.","Remove the extraction function from the selector if raw values are needed, applying extraction separately.","Use lookupNameUtf8 only on selectors known to be extraction-free."],"exampleFix":"// before\nfinal ByteBuffer utf8 = selector.lookupNameUtf8(id); // throws if selector has extractionFn\n\n// after\nfinal ByteBuffer utf8 = selector instanceof DimExtractionFnApplicablePredicate && !selector.hasExtractionFn()\n    ? selector.lookupNameUtf8(id)\n    : Utf8.fromString(selector.getObject());","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Java: only use the UTF-8 fast path on extraction-free selectors\nif (selector instanceof BaseStringSelector && ((BaseStringSelector) selector).getExtractionFn() == null) {\n  return selector.lookupNameUtf8(id);\n}\nreturn Utf8.fromString(selector.getObject());","tryCatchPattern":null,"preventionTips":["Gate lookupNameUtf8 calls on the absence of an ExtractionFn.","Prefer getObject/getString on selectors that may be wrapped with extraction functions."],"tags":["selector","utf8","extraction-fn","unsupported-operation","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"}