{"record":{"id":"8127f3adc8398a72","repo":"apache/druid","slug":"failed-to-convert-array-type-s-to-expression-type","errorCode":null,"errorMessage":"Failed to convert array type %s to expression type","messagePattern":"Failed to convert array type (.+?) to expression type","errorType":"validation","errorClass":"RE","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/ExprListenerImpl.java","lineNumber":414,"sourceCode":"      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);\n        // if value is a string, escape quoting\n        final String toParse;\n        if (elementContext.STRING() != null) {\n          toParse = escapeStringLiteral(elementContext.STRING().getText());\n        } else {\n          toParse = elementContext.getText();\n        }\n        switch (type.getElementType().getType()) {\n          case LONG:\n            values[i] = Numbers.parseLongObject(toParse);\n            break;","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/ExprListenerImpl.java#L396-L432","documentation":"Thrown when an explicitly typed array literal declares an ARRAY<TYPE> whose type name cannot be resolved to an ExpressionType (ExpressionType.fromString returned null). The declared array type is not a known Druid expression type.","triggerScenarios":"Parsing an expression like ARRAY<WRONGTYPE>[...] where the token inside <> does not match a known type string (long, double, string, and their array forms).","commonSituations":"Typos in type names (ARRAY<INT> instead of ARRAY<LONG>); using SQL types like INT/VARCHAR in native expressions; copy-pasting SQL typed-array syntax into native expressions.","solutions":["Use a supported type keyword: LONG, DOUBLE, or STRING for typed array literals","Remove the type annotation and use an untyped ARRAY literal","Map SQL types to expression types (INT->LONG, VARCHAR->STRING) before generating the expression"],"exampleFix":"// before\nARRAY<INT>[1, 2, 3]\n// after\nARRAY<LONG>[1, 2, 3]","handlingStrategy":"validation","validationCode":"// Java: whitelist typed-array keywords before emitting\nstatic final java.util.Set<String> ARRAY_TYPES = java.util.Set.of(\"LONG\",\"DOUBLE\",\"STRING\");\nboolean isSupportedArrayType(String t) {\n  return ARRAY_TYPES.contains(t.trim().toUpperCase());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only LONG, DOUBLE, STRING as ARRAY<T> type annotations","Map SQL types (INT, VARCHAR, BIGINT) to expression types before generating","Prefer untyped ARRAY literals unless a typed one is required","Keep a central mapping table for type-name translation"],"tags":["druid","expression-parser","array-literal","type-mismatch"],"backgroundTag":"invalid-enum-value","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"}