apache/druid · error · RE
Failed to parse array element
Error message
Failed to parse array element %s as a double
What it means
Thrown while parsing a typed double array literal when an element token is neither a LONG nor a DOUBLE literal (and not NULL), so it cannot be converted to a double. Indicates malformed array-literal syntax that the grammar accepted structurally but cannot coerce.
Solutions
- Remove or fix the offending element reported in the message so it is a plain numeric literal or NULL
- Use an untyped ARRAY literal or a string array if the data is not numeric
- Convert string values with a cast, e.g. ARRAY<DOUBLE>[CAST('1.5' AS DOUBLE)] via appropriate expression forms
Example fix
// before ARRAY<DOUBLE>['1.5', 2] // after ARRAY<DOUBLE>[1.5, 2.0]
Defensive patterns
Strategy: validation
Validate before calling
// Java: validate double-array literal elements before emitting the expression
static boolean isValidDoubleArrayLiteral(java.util.List<String> elems) {
return elems.stream().allMatch(e -> {
try { com.google.common.primitives.Doubles.tryParse(e.replace("NULL","").trim()); return true; }
catch (Exception ex) { return false; }
});
} Prevention
- Only emit bare numeric literals or NULL inside ARRAY<DOUBLE>
- Never place quoted strings or booleans in typed numeric arrays
- Add unit tests covering all array literals your code generates
- Sanitize values coming from upstream systems before interpolation
When it happens
Trigger: Parsing an expression like ARRAY<DOUBLE>[abc] or a double array containing string/boolean elements; numeric elements that fail Numbers.parseDoubleObject (e.g. out-of-range or malformed).
Common situations: Hand-written expression filters/aggregations with quoted or non-numeric elements in typed double arrays; generated expressions from upstream tools emitting strings into numeric arrays.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to convert array type
- Failed to parse array element
- Failed to parse array element
- Failed to parse array element
- Failed to parse array: element
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/bf3ad74d5d158ae9.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/math/expr/ExprListenerImpl.java:403
@Override
public void exitNull(ExprParser.NullContext ctx)
{
nodes.put(ctx, new NullLongExpr());
}
@Override
public void exitDoubleArray(ExprParser.DoubleArrayContext ctx)
{
Object[] values = new Object[ctx.numericElement().size()];
for (int i = 0; i < values.length; i++) {
if (ctx.numericElement(i).NULL() != null) {
values[i] = null;
} else if (ctx.numericElement(i).LONG() != null) {
values[i] = Numbers.parseDoubleObject(ctx.numericElement(i).LONG().getText());
} else if (ctx.numericElement(i).DOUBLE() != null) {
values[i] = Numbers.parseDoubleObject(ctx.numericElement(i).DOUBLE().getText());
} else {
throw new RE("Failed to parse array element %s as a double", ctx.numericElement(i).getText());
}
}
nodes.put(ctx, new ArrayExpr(ExpressionType.DOUBLE_ARRAY, values));
}
@Override
public void exitExplicitArray(ExprParser.ExplicitArrayContext ctx)
{
ExpressionType type = ExpressionType.fromString(ctx.ARRAY_TYPE().getText());
if (type == null) {
throw new RE("Failed to convert array type %s to expression type", ctx.ARRAY_TYPE().getText());
}
Object[] values = new Object[ctx.literalElement().size()];
for (int i = 0; i < values.length; i++) {
if (ctx.literalElement(i).NULL() != null) {
values[i] = null;
} else {
final ExprParser.LiteralElementContext elementContext = ctx.literalElement(i);View on GitHub (pinned to 9b90983fd2)