apache/druid · error · RE
Failed to parse array: element
Error message
Failed to parse array: element %s is not a string
What it means
Raised in ExprListenerImpl.exitStringArray when an element of a STRING array literal is not a recognized STRING token (and not NULL), so the listener cannot build the VARCHAR array's value. The array literal grammar expected string elements but found some other token type, meaning malformed array syntax or wrong element types in the expression.
Solutions
- Ensure every element of the array literal is a quoted string or NULL, e.g. ARRAY['a', 'b', NULL].
- Quote numeric or identifier elements if a string array is intended.
- Fix unbalanced quotes or stray tokens that break the string-element parse.
Example fix
// before ARRAY<STRING>[foo, 123] // after ARRAY<STRING>['foo', '123']
Defensive patterns
Strategy: validation
Validate before calling
// Java: ensure every element is a quoted string or NULL
static boolean isStringArrayLiteral(java.util.List<String> elems) {
return elems.stream().allMatch(e -> e.equals("NULL")
|| (e.startsWith("'") && e.endsWith("'") && e.length() >= 2));
} Prevention
- Always quote string array elements with single quotes
- Escape embedded quotes when generating expressions
- Do not reuse JSON array rendering for Druid string arrays
- Test generated arrays containing numbers and special characters
When it happens
Trigger: Parsing ARRAY<STRING>[1, 2] or ARRAY<STRING>[abc] — elements that are not quoted string literals in the string-array grammar path.
Common situations: Unquoted identifiers or numbers in string arrays; generated expressions that skip quoting; copying JSON arrays (unquoted numbers) into expression string 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 parse array element
- Failed to convert array type
- 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/d92f7c8417db3197.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/math/expr/ExprListenerImpl.java:491
values[i] = Numbers.parseLongObject(ctx.numericElement(i).DOUBLE().getText());
} else {
throw new RE("Failed to parse array element %s as a long", ctx.numericElement(i).getText());
}
}
nodes.put(ctx, new ArrayExpr(ExpressionType.LONG_ARRAY, values));
}
@Override
public void exitStringArray(ExprParser.StringArrayContext ctx)
{
Object[] values = new Object[ctx.stringElement().size()];
for (int i = 0; i < values.length; i++) {
if (ctx.stringElement(i).NULL() != null) {
values[i] = null;
} else if (ctx.stringElement(i).STRING() != null) {
values[i] = escapeStringLiteral(ctx.stringElement(i).STRING().getText());
} else {
throw new RE("Failed to parse array: element %s is not a string", ctx.stringElement(i).getText());
}
}
nodes.put(ctx, new ArrayExpr(ExpressionType.STRING_ARRAY, values));
}
@Override
public void exitExplicitStringArray(ExprParser.ExplicitStringArrayContext ctx)
{
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 if (ctx.literalElement(i).STRING() != null) {
values[i] = escapeStringLiteral(ctx.literalElement(i).STRING().getText());
} else if (ctx.literalElement(i).DOUBLE() != null) {
values[i] = ctx.literalElement(i).DOUBLE().getText();
} else if (ctx.literalElement(i).LONG() != null) {
values[i] = ctx.literalElement(i).LONG().getText();View on GitHub (pinned to 9b90983fd2)