diff --git a/processing/src/main/java/org/apache/druid/math/expr/Function.java b/processing/src/main/java/org/apache/druid/math/expr/Function.java index f79a0fc5a74..a4171cc8b35 100644 --- a/processing/src/main/java/org/apache/druid/math/expr/Function.java +++ b/processing/src/main/java/org/apache/druid/math/expr/Function.java @@ -3974,7 +3974,7 @@ public interface Function extends NamedFunction { if (args.get(1).isLiteral()) { final ExpressionType lhsType = args.get(0).getOutputType(inspector); - if (lhsType == null) { + if (lhsType == null || !(lhsType.isPrimitive() || lhsType.isPrimitiveArray())) { return this; } final ExpressionType lhsArrayType = ExpressionType.asArrayType(lhsType); @@ -4107,7 +4107,7 @@ public interface Function extends NamedFunction { if (args.get(1).isLiteral()) { final ExpressionType lhsType = args.get(0).getOutputType(inspector); - if (lhsType == null) { + if (lhsType == null || !(lhsType.isPrimitive() || lhsType.isPrimitiveArray())) { return this; } final ExpressionType lhsArrayType = ExpressionType.asArrayType(lhsType); diff --git a/processing/src/test/java/org/apache/druid/query/expression/NestedDataExpressionsTest.java b/processing/src/test/java/org/apache/druid/query/expression/NestedDataExpressionsTest.java index c9fe553469a..269f4b63372 100644 --- a/processing/src/test/java/org/apache/druid/query/expression/NestedDataExpressionsTest.java +++ b/processing/src/test/java/org/apache/druid/query/expression/NestedDataExpressionsTest.java @@ -419,6 +419,22 @@ public class NestedDataExpressionsTest extends InitializedNullHandlingTest eval = expr.eval(inputBindings); Assert.assertEquals(3L, eval.value()); Assert.assertEquals(ExpressionType.LONG, eval.type()); + + expr = Parser.parse("array_contains(json_query_array(nest, '$.x'), 100)", MACRO_TABLE); + expr = expr.asSingleThreaded(inputBindings); + Assert.assertEquals(1L, expr.eval(inputBindings).value()); + + expr = Parser.parse("array_contains(json_query_array(nest, '$.x'), 101)", MACRO_TABLE); + expr = expr.asSingleThreaded(inputBindings); + Assert.assertEquals(0L, expr.eval(inputBindings).value()); + + expr = Parser.parse("array_overlap(json_query_array(nest, '$.x'), [100, 101])", MACRO_TABLE); + expr = expr.asSingleThreaded(inputBindings); + Assert.assertEquals(1L, expr.eval(inputBindings).value()); + + expr = Parser.parse("array_overlap(json_query_array(nest, '$.x'), [101, 102])", MACRO_TABLE); + expr = expr.asSingleThreaded(inputBindings); + Assert.assertEquals(0L, expr.eval(inputBindings).value()); } @Test