gianm commented on code in PR #16311:
URL: https://github.com/apache/druid/pull/16311#discussion_r1581232427
##########
processing/src/main/java/org/apache/druid/math/expr/Function.java:
##########
@@ -3742,23 +3746,95 @@ public ExpressionType
getOutputType(Expr.InputBindingInspector inspector, List<E
@Override
Expr getScalarArgument(List<Expr> args)
{
- return args.get(0);
+ return args.get(SCALAR_ARG);
}
@Override
Expr getArrayArgument(List<Expr> args)
{
- return args.get(1);
+ return args.get(ARRAY_ARG);
}
@Override
- ExprEval doApply(ExprEval arrayExpr, ExprEval scalarExpr)
+ ExprEval doApply(ExprEval arrayEval, ExprEval scalarEval)
{
- final Object[] array =
arrayExpr.castTo(scalarExpr.asArrayType()).asArray();
+ final Object[] array = arrayEval.asArray();
if (array == null) {
return ExprEval.ofLong(null);
}
- return
ExprEval.ofLongBoolean(Arrays.asList(array).contains(scalarExpr.value()));
+
+ if (scalarEval.value() == null) {
+ return Arrays.asList(array).contains(null) ?
ExprEval.ofLongBoolean(true) : ExprEval.ofLong(null);
Review Comment:
The idea is that if the array contains `null` then the comparison acts like
`IS NOT DISTINCT FROM` (always returns `true` or `false`), whereas if the array
does not contain `null`, then the comparison acts like `=` (returns `null` if
the lhs is `null`). It's the same way the native `in` and `inType` filters
behave, so this is designed to align with those.
A future patch would convert from SQL `IN` to this `SCALAR_IN_ARRAY`
function. We'll need to make sure to handle `NULL` appropriately in that
patch-- it would not be ok to rewrite `c IN (2, NULL)` to `SCALAR_IN_ARRAY(c,
ARRAY[2, NULL])`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]