apache/druid · error · IAE

cannot stringify array type

Error message

cannot stringify array type %s

What it means

ConstantExpr.stringify can render array constants whose elements are arrays (nested arrays), but if outputType is an array type with an element type it does not recognize in its switch, it throws IllegalArgumentException saying the array type cannot be stringified. It is an internal representation limitation of the expression printer.

Solutions

  1. Avoid nested array constants in expressions; flatten to a single-level array literal
  2. Upgrade Druid to a version where the element type is supported in stringify
  3. Write the expression using array(...) constructor syntax over scalar elements instead of a pre-built constant

Example fix

// before: constant nested array expr ARRAY[ARRAY[1,2]]
// after
"ARRAY_CONCAT(ARRAY[1], ARRAY[2])" // keep expressions single-level
Defensive patterns

Strategy: try-catch

Validate before calling

if (expr instanceof ConstantExpr) {
  ExpressionType t = ((ConstantExpr) expr).outputType();
  if (t.isArray() && !isSupportedArrayElementType(t.getElementType())) { /* avoid stringify */ }
}

Try / catch

try {
  s = constantExpr.stringify();
} catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().contains("cannot stringify array type")) {
    s = expr.toString(); // fallback representation
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling stringify() (directly or via error messages/EXPLAIN that print expressions) on an array-typed ConstantExpr whose element type isn't one of the handled primitive array element types.

Common situations: Nested array literals in expressions hitting an unhandled ExpressionType element type; printing expressions for logging or plan display; new array types added before stringify support caught up.

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/e3f958b7be58279b. Report an issue: GitHub.

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/math/expr/ConstantExpr.java:505

      );
    } else if (outputType.getElementType().isNumeric()) {
      return outputType.asTypeString() + Arrays.toString(value);
    } else if (outputType.getElementType().is(ExprType.COMPLEX)) {
      Object[] stringified = new Object[value.length];
      for (int i = 0; i < value.length; i++) {
        stringified[i] = new ComplexExpr((ExpressionType) outputType.getElementType(), value[i]).stringify();
      }
      // use array function to rebuild since we can't stringify complex types directly
      return StringUtils.format("array(%s)", Arrays.toString(stringified));
    } else if (outputType.getElementType().isArray()) {
      // use array function to rebuild since the parser can't yet recognize nested arrays e.g. [['foo', 'bar'],['baz']]
      Object[] stringified = new Object[value.length];
      for (int i = 0; i < value.length; i++) {
        stringified[i] = new ArrayExpr((ExpressionType) outputType.getElementType(), (Object[]) value[i]).stringify();
      }
      return StringUtils.format("array(%s)", Arrays.toString(stringified));
    }
    throw new IAE("cannot stringify array type %s", outputType);
  }

  @Override
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    ArrayExpr that = (ArrayExpr) o;
    return outputType.equals(that.outputType) && Arrays.equals(value, that.value);
  }

  @Override
  public int hashCode()
  {

View on GitHub (pinned to 9b90983fd2)