apache/druid · error · org.apache.druid.java.util.common.IAE

Unknwon types [%s] and [%s]

Error message

Unknwon types [%s] and [%s]

What it means

SketchHolder.COMPARATOR (used for ordering/merging sketch values) only knows how to compare Sketch and Memory objects; comparing SketchHolders holding any other object type throws this IllegalArgumentException (note the typo "Unknwon"). It surfaces when two incompatible value types meet in a comparator, typically during sorting or query result combination.

Source

Thrown at extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/SketchHolder.java:79

          SketchHolder h2 = (SketchHolder) o2;

          if (h1.obj instanceof Sketch || h1.obj instanceof Union) {
            if (h2.obj instanceof Sketch || h2.obj instanceof Union) {
              return SKETCH_COMPARATOR.compare(h1.getSketch(), h2.getSketch());
            } else {
              return -1;
            }
          }

          if (h1.obj instanceof Memory) {
            if (h2.obj instanceof Memory) {
              return MEMORY_COMPARATOR.compare((Memory) h1.obj, (Memory) h2.obj);
            } else {
              return 1;
            }
          }

          throw new IAE("Unknwon types [%s] and [%s]", h1.obj.getClass().getName(), h2.obj.getClass().getName());
        }
      }
  ).nullsFirst();

  private static final Comparator<Sketch> SKETCH_COMPARATOR = new Comparator<>()
  {
    @Override
    public int compare(Sketch o1, Sketch o2)
    {
      return Doubles.compare(o1.getEstimate(), o2.getEstimate());
    }
  };

  private static final Comparator<Memory> MEMORY_COMPARATOR = new Comparator<>()
  {
    @SuppressWarnings("SubtractionInCompareTo")
    @Override
    public int compare(Memory o1, Memory o2)

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Normalize sketch values to a common representation (deserialize Memory/String to Sketch before comparing)
  2. Ensure all segments/columns involved hold the same theta sketch type and serialization
  3. Catch and pre-convert string-encoded sketches before operations that sort or compare them

Example fix

// before
SketchHolder a = SketchHolder.of(sketch); SketchHolder b = SketchHolder.of("deadbeef"); // String
a.compareTo(b); // IAE
// after
SketchHolder b2 = SketchHolder.of(Sketches.wrapSketch(SketchSerialization.decode((String) b.obj)));
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(h1.obj.getClass().equals(h2.obj.getClass())) || !(h1.obj instanceof Sketch || h1.obj instanceof Memory)) { throw new IllegalArgumentException("Incompatible sketch holder types: " + h1.obj.getClass() + " vs " + h2.obj.getClass()); }

Type guard

boolean comparableHolders(SketchHolder a, SketchHolder b) { return (a.obj instanceof Sketch && b.obj instanceof Sketch) || (a.obj instanceof Memory && b.obj instanceof Memory); }

Try / catch

try { c = a.compareTo(b); } catch (IllegalArgumentException e) { if (e.getMessage().contains("Unknwon types")) { c = compareAsSketches(a, b); } else throw e; }

Prevention

When it happens

Trigger: Comparing two SketchHolder instances whose obj fields are neither both Sketch nor both Memory — e.g. one is a String (serialized sketch) and the other a Sketch, or one is from a different sketch family.

Common situations: Order-by over a theta sketch column with heterogeneous serialized forms; merging results where one segment stored Memory-wrapped sketches and another stored deserialized Sketches or strings; joining outputs of different sketch types.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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