apache/druid · error · IAE
operator ' ' in expression ( ) is not supported on type…
Error message
operator '%s' in expression (%s %s %s) is not supported on type STRING.
What it means
Binary operator expressions (e.g. '+', '&&', comparisons) in Druid expressions cannot be applied to STRING-typed operands. When the binary op's eval path dispatches to evalString, it unconditionally throws IllegalArgumentException because the operator has no defined string semantics.
Solutions
- Add an explicit cast in the expression, e.g. CAST(a AS DOUBLE) + CAST(b AS DOUBLE) or use numeric parse functions like ParseLong/ParseDouble
- Verify the actual column types in the datasource; fix ingestion specs so the column is ingested as long/double instead of string
- Rewrite the expression to use string-appropriate operators/functions instead of arithmetic/comparison ops
Example fix
// before: expression "dim1 + dim2" with string columns // after "CAST(dim1 AS DOUBLE) + CAST(dim2 AS DOUBLE)"
Defensive patterns
Strategy: type-guard
Validate before calling
// Java-side guard before evaluating
if (leftType.is(ExpressionType.STRING) || rightType.is(ExpressionType.STRING)) {
throw new IllegalArgumentException("string operands need CAST before binary operator");
} Try / catch
try {
result = expr.eval(bindings);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().contains("not supported on type STRING")) {
// re-evaluate with casts or fail gracefully
} else { throw e; }
} Prevention
- Never apply arithmetic/comparison ops directly on string columns
- Use CAST or ParseLong/ParseDouble on string inputs
- Validate column types against the expression before deployment
When it happens
Trigger: Evaluating a Druid native expression such as 'a + b' or 'a < b' where left or right operand evaluates to type STRING instead of a numeric/boolean type.
Common situations: Ingestion spec transforms/filters or SQL-level virtual columns referencing a string column with arithmetic; a column that was expected to be numeric is actually stored as string (schema drift); missing a CAST in the expression.
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
- Cannot cast [ ] to [ ] (Types.InvalidCastException from…
- Cannot create type [ ]
- Cannot implicitly cast
- Expected key [ ] to be a String, but got [ ]
- needs a LONG as its second argument but got
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/5a2eed38e2ba72e8.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/math/expr/BinaryEvalOpExprBase.java:155
ExpressionType type = ExpressionTypeConversion.autoDetect(leftVal, rightVal);
switch (type.getType()) {
case STRING:
return evalString(leftVal.asString(), rightVal.asString());
case LONG:
return ExprEval.of(evalLong(leftVal.asLong(), rightVal.asLong()));
case DOUBLE:
default:
if (leftVal.isNumericNull() || rightVal.isNumericNull()) {
return ExprEval.ofMissing();
}
return ExprEval.of(evalDouble(leftVal.asDouble(), rightVal.asDouble()));
}
}
protected ExprEval evalString(@Nullable String left, @Nullable String right)
{
throw new IAE(
"operator '%s' in expression (%s %s %s) is not supported on type STRING.",
this.op,
this.left.stringify(),
this.op,
this.right.stringify()
);
}
protected abstract long evalLong(long left, long right);
protected abstract double evalDouble(double left, double right);
}
@SuppressWarnings("ClassName")
abstract class BinaryBooleanOpExprBase extends BinaryOpExprBase
{
BinaryBooleanOpExprBase(String op, Expr left, Expr right)
{View on GitHub (pinned to 9b90983fd2)