Fixed NPE in `array_overlap` and `array_contains`. (#17465)

This commit is contained in:
Vivek Dhiman 2024-11-08 20:39:14 -08:00 committed by GitHub
parent 5764183d4e
commit 0dcc2bc469
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -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);

View File

@ -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