{"record":{"id":"d92f7c8417db3197","repo":"apache/druid","slug":"failed-to-parse-array-element-s-is-not-a-string","errorCode":null,"errorMessage":"Failed to parse array: element %s is not a string","messagePattern":"Failed to parse array: element (.+?) is not a string","errorType":"validation","errorClass":"RE","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/ExprListenerImpl.java","lineNumber":491,"sourceCode":"        values[i] = Numbers.parseLongObject(ctx.numericElement(i).DOUBLE().getText());\n      } else {\n        throw new RE(\"Failed to parse array element %s as a long\", ctx.numericElement(i).getText());\n      }\n    }\n    nodes.put(ctx, new ArrayExpr(ExpressionType.LONG_ARRAY, values));\n  }\n\n  @Override\n  public void exitStringArray(ExprParser.StringArrayContext ctx)\n  {\n    Object[] values = new Object[ctx.stringElement().size()];\n    for (int i = 0; i < values.length; i++) {\n      if (ctx.stringElement(i).NULL() != null) {\n        values[i] = null;\n      } else if (ctx.stringElement(i).STRING() != null) {\n        values[i] = escapeStringLiteral(ctx.stringElement(i).STRING().getText());\n      } else {\n        throw new RE(\"Failed to parse array: element %s is not a string\", ctx.stringElement(i).getText());\n      }\n    }\n    nodes.put(ctx, new ArrayExpr(ExpressionType.STRING_ARRAY, values));\n  }\n\n  @Override\n  public void exitExplicitStringArray(ExprParser.ExplicitStringArrayContext ctx)\n  {\n    Object[] values = new Object[ctx.literalElement().size()];\n    for (int i = 0; i < values.length; i++) {\n      if (ctx.literalElement(i).NULL() != null) {\n        values[i] = null;\n      } else if (ctx.literalElement(i).STRING() != null) {\n        values[i] = escapeStringLiteral(ctx.literalElement(i).STRING().getText());\n      } else if (ctx.literalElement(i).DOUBLE() != null) {\n        values[i] = ctx.literalElement(i).DOUBLE().getText();\n      } else if (ctx.literalElement(i).LONG() != null) {\n        values[i] = ctx.literalElement(i).LONG().getText();","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/ExprListenerImpl.java#L473-L509","documentation":"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.","triggerScenarios":"Parsing ARRAY<STRING>[1, 2] or ARRAY<STRING>[abc] — elements that are not quoted string literals in the string-array grammar path.","commonSituations":"Unquoted identifiers or numbers in string arrays; generated expressions that skip quoting; copying JSON arrays (unquoted numbers) into expression string arrays.","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."],"exampleFix":"// before\nARRAY<STRING>[foo, 123]\n// after\nARRAY<STRING>['foo', '123']","handlingStrategy":"validation","validationCode":"// Java: ensure every element is a quoted string or NULL\nstatic boolean isStringArrayLiteral(java.util.List<String> elems) {\n  return elems.stream().allMatch(e -> e.equals(\"NULL\")\n      || (e.startsWith(\"'\") && e.endsWith(\"'\") && e.length() >= 2));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["druid","expression-parser","array-literal","string-literal"],"backgroundTag":"invalid-argument-format","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}