apache/druid · error · IllegalStateException

Cannot use lookupNameUtf8 on this selector

Error message

Cannot use lookupNameUtf8 on this selector

What it means

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.

Solutions

  1. Do not call lookupNameUtf8 when extractionFn != null; check the flag first and fall back to getString/getObject.
  2. Remove the extraction function from the selector if raw values are needed, applying extraction separately.
  3. Use lookupNameUtf8 only on selectors known to be extraction-free.

Example fix

// before
final ByteBuffer utf8 = selector.lookupNameUtf8(id); // throws if selector has extractionFn

// after
final ByteBuffer utf8 = selector instanceof DimExtractionFnApplicablePredicate && !selector.hasExtractionFn()
    ? selector.lookupNameUtf8(id)
    : Utf8.fromString(selector.getObject());
Defensive patterns

Strategy: type-guard

Type guard

// Java: only use the UTF-8 fast path on extraction-free selectors
if (selector instanceof BaseStringSelector && ((BaseStringSelector) selector).getExtractionFn() == null) {
  return selector.lookupNameUtf8(id);
}
return Utf8.fromString(selector.getObject());

Prevention

When it happens

Trigger: Calling lookupNameUtf8 on a BaseStringSelector produced by StringFieldReader's Selector after makeDimensionSelector(..., extractionFn) with a non-null ExtractionFn.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/a61672ca99ed1116. Report an issue: GitHub.

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/frame/field/StringFieldReader.java:247

      } else {
        final ByteBuffer byteBuffer = strings.get(id);
        final String s = byteBuffer != null ? StringUtils.fromUtf8(byteBuffer.duplicate()) : null;
        return extractionFn == null ? s : extractionFn.apply(s);
      }
    }

    @Override
    public boolean supportsLookupNameUtf8()
    {
      return extractionFn == null;
    }

    @Nullable
    @Override
    public ByteBuffer lookupNameUtf8(int id)
    {
      if (extractionFn != null) {
        throw new ISE("Cannot use lookupNameUtf8 on this selector");
      }

      final List<ByteBuffer> strings = computeCurrentUtf8Strings();
      return strings == null ? null : strings.get(id);
    }

    @Override
    public int getValueCardinality()
    {
      return CARDINALITY_UNKNOWN;
    }

    @Override
    public boolean nameLookupPossibleInAdvance()
    {
      return false;
    }

View on GitHub (pinned to 9b90983fd2)