clintropolis commented on code in PR #15974:
URL: https://github.com/apache/druid/pull/15974#discussion_r1509554121
##########
processing/src/main/java/org/apache/druid/math/expr/Function.java:
##########
@@ -3803,16 +3854,56 @@ public ExpressionType
getOutputType(Expr.InputBindingInspector inspector, List<E
}
@Override
- ExprEval doApply(ExprEval lhsExpr, ExprEval rhsExpr)
+ public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings)
{
- final Object[] array1 = lhsExpr.asArray();
- final List<Object> array2 = Arrays.asList(rhsExpr.asArray());
+ final ExprEval arrayExpr1 = args.get(0).eval(bindings);
+ final ExprEval arrayExpr2 = args.get(1).eval(bindings);
+
+ final Object[] array1 = arrayExpr1.asArray();
+ final Object[] array2 = arrayExpr2.asArray();
+ if (array1 == null) {
+ return ExprEval.ofLong(null);
Review Comment:
heh, good question. So if I remember correctly, by default for an expression
like `MV_CONTAINS` the value `NULL` would just be `NULL`, so this would be
checking `MV_CONTAINS(NULL, ARRAY[NULL, 'abc', 'def'])`.
This is controlled
https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/segment/virtual/ExpressionSelectors.java#L344
where the 'homogenize' flag which translates stuff like `NULL` and `[]` into
`[NULL]` is only done for scalar expressions which are transformed to apply the
expression across the MVD, but since `MV_CONTAINS` is `array_contains` native
expression, this transformation does not happen because we are using the MVD as
an array instead.
So, in all of these cases it returns `UNKNOWN` when evaluated as an
expression.
Looking at MV_CONTAINS as a filter in the sql operator conversions, it
should behave the same way except in one case I think due to how we rewrite it
into native filters. The case where I think it would be different is
`MV_CONTAINS(mvd, [NULL])` would rewrite into basically `mvd is null`, which
would return true instead of unknown. Maybe we should prevent the
`MV_CONTAINS(mvd, [NULL])` case from being allowed to rewrite in this case?
--
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]