{"record":{"id":"203609d907cd3e7d","repo":"apache/druid","slug":"second-argument-must-be-a-a-scalar-type-but-got-s","errorCode":null,"errorMessage":"second argument must be a a scalar type but got %s instead","messagePattern":"second argument must be a a scalar type but got (.+?) instead","errorType":"validation","errorClass":"ExpressionValidationException","httpStatus":400,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/Function.java","lineNumber":3741,"sourceCode":"    @Override\n    ExprEval doApply(ExprEval arrayExpr, ExprEval scalarExpr)\n    {\n      final Object[] array = arrayExpr.asArray();\n\n      switch (scalarExpr.type().getType()) {\n        case STRING:\n        case LONG:\n        case DOUBLE:\n          int index = -1;\n          for (int i = 0; i < array.length; i++) {\n            if (Objects.equals(array[i], scalarExpr.value())) {\n              index = i;\n              break;\n            }\n          }\n          return index < 0 ? ExprEval.ofLong(null) : ExprEval.ofLong(index);\n        default:\n          throw validationFailed(\n              \"second argument must be a a scalar type but got %s instead\",\n              scalarExpr.type()\n          );\n      }\n    }\n  }\n\n  class ArrayOrdinalOfFunction extends ArrayScalarFunction\n  {\n    @Override\n    public String name()\n    {\n      return \"array_ordinal_of\";\n    }\n\n    @Nullable\n    @Override\n    public ExpressionType getOutputType(Expr.InputBindingInspector inspector, List<Expr> args)","sourceCodeStart":3723,"sourceCodeEnd":3759,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/Function.java#L3723-L3759","documentation":"Thrown by Druid's array_offset-like expression function when the second argument (the element to search / index lookup value) has a non-scalar type, i.e. it is itself an array or complex type. The search key must be a LONG, STRING, DOUBLE, etc. — never an array.","triggerScenarios":"Evaluating array_offset(arr, nestedArray) where the second argument is an ARRAY ExprType, e.g. passing another array column or an array() construction as the search value.","commonSituations":"Confusing array_offset with functions that take an index; accidentally passing an array literal instead of a scalar; schema changes turning a formerly scalar column into an array.","solutions":["Pass a scalar value (literal or scalar column) as the second argument, e.g. array_offset(arr, 'target').","If you intended an index lookup, use array_offset(arr, 0) with a numeric index.","Unwrap the nested array first (e.g. with array_offset on the outer array) before using the result as the search key.","Verify column types in the schema; cast the argument to VARCHAR/BIGINT if it is a complex type mishap."],"exampleFix":"// before\narray_offset(arr, array('a','b'))\n// after\narray_offset(arr, 'a')","handlingStrategy":"type-guard","validationCode":"// ensure search key is scalar in SQL\nCASE WHEN CARDINALITY(key) > 0 THEN ... ELSE NULL END -- or just never pass arrays","typeGuard":"// reject array-typed arguments before calling\nif (isArrayType(argType)) throw new IllegalArgumentException(\"search key must be scalar\");","tryCatchPattern":null,"preventionTips":["Never pass array columns or array(...) as the search value","Confirm column types in the datasource schema","Use UNNEST to flatten nested arrays first"],"tags":["druid","expressions","arrays","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}