{"record":{"id":"bf3ad74d5d158ae9","repo":"apache/druid","slug":"failed-to-parse-array-element-s-as-a-double","errorCode":null,"errorMessage":"Failed to parse array element %s as a double","messagePattern":"Failed to parse array element (.+?) as a double","errorType":"validation","errorClass":"RE","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/ExprListenerImpl.java","lineNumber":403,"sourceCode":"  @Override\n  public void exitNull(ExprParser.NullContext ctx)\n  {\n    nodes.put(ctx, new NullLongExpr());\n  }\n\n  @Override\n  public void exitDoubleArray(ExprParser.DoubleArrayContext ctx)\n  {\n    Object[] values = new Object[ctx.numericElement().size()];\n    for (int i = 0; i < values.length; i++) {\n      if (ctx.numericElement(i).NULL() != null) {\n        values[i] = null;\n      } else if (ctx.numericElement(i).LONG() != null) {\n        values[i] = Numbers.parseDoubleObject(ctx.numericElement(i).LONG().getText());\n      } else if (ctx.numericElement(i).DOUBLE() != null) {\n        values[i] = Numbers.parseDoubleObject(ctx.numericElement(i).DOUBLE().getText());\n      } else {\n        throw new RE(\"Failed to parse array element %s as a double\", ctx.numericElement(i).getText());\n      }\n    }\n    nodes.put(ctx, new ArrayExpr(ExpressionType.DOUBLE_ARRAY, values));\n  }\n\n  @Override\n  public void exitExplicitArray(ExprParser.ExplicitArrayContext ctx)\n  {\n    ExpressionType type = ExpressionType.fromString(ctx.ARRAY_TYPE().getText());\n    if (type == null) {\n      throw new RE(\"Failed to convert array type %s to expression type\", ctx.ARRAY_TYPE().getText());\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 {\n        final ExprParser.LiteralElementContext elementContext = ctx.literalElement(i);","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/ExprListenerImpl.java#L385-L421","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nARRAY<DOUBLE>['1.5', 2]\n// after\nARRAY<DOUBLE>[1.5, 2.0]","handlingStrategy":"validation","validationCode":"// Java: validate double-array literal elements before emitting the expression\nstatic boolean isValidDoubleArrayLiteral(java.util.List<String> elems) {\n  return elems.stream().allMatch(e -> {\n    try { com.google.common.primitives.Doubles.tryParse(e.replace(\"NULL\",\"\").trim()); return true; }\n    catch (Exception ex) { return false; }\n  });\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["druid","expression-parser","array-literal","type-mismatch"],"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"}