abhishekagarwal87 commented on code in PR #14976:
URL: https://github.com/apache/druid/pull/14976#discussion_r1325449120
##########
processing/src/main/java/org/apache/druid/math/expr/Function.java:
##########
@@ -2224,6 +2224,89 @@ public <T> ExprVectorProcessor<T>
asVectorProcessor(Expr.VectorInputBindingInspe
}
}
+ /**
+ * SQL function "x IS NOT DISTINCT FROM y". Very similar to "x = y", i.e.
{@link BinEqExpr}, except this function
+ * never returns null, and this function considers NULL itself to be
not-distinct-from NULL.
Review Comment:
`this function considers NULL itself to be not-distinct-from NULL` - this
part is a bit unclear. How about
`this function considers NULL as a value`
##########
processing/src/main/java/org/apache/druid/math/expr/Function.java:
##########
@@ -2224,6 +2224,89 @@ public <T> ExprVectorProcessor<T>
asVectorProcessor(Expr.VectorInputBindingInspe
}
}
+ /**
+ * SQL function "x IS NOT DISTINCT FROM y". Very similar to "x = y", i.e.
{@link BinEqExpr}, except this function
+ * never returns null, and this function considers NULL itself to be
not-distinct-from NULL.
+ */
+ class IsNotDistinctFromFunc implements Function
+ {
+ @Override
+ public String name()
+ {
+ return "notdistinctfrom";
+ }
+
+ @Override
+ public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings)
+ {
+ final ExprEval leftVal = args.get(0).eval(bindings);
+ final ExprEval rightVal = args.get(1).eval(bindings);
+
+ if (leftVal.value() == null || rightVal.value() == null) {
+ return ExprEval.ofLongBoolean(leftVal.value() == null &&
rightVal.value() == null);
+ }
+
+ final ExpressionType comparisonType =
ExpressionTypeConversion.autoDetect(leftVal, rightVal);
+ switch (comparisonType.getType()) {
+ case STRING:
+ return ExprEval.ofLongBoolean(Objects.equals(leftVal.asString(),
rightVal.asString()));
+ case LONG:
+ return ExprEval.ofLongBoolean(leftVal.asLong() == rightVal.asLong());
+ case DOUBLE:
+ default:
+ if (leftVal.isNumericNull() || rightVal.isNumericNull()) {
+ return ExprEval.ofLongBoolean(leftVal.isNumericNull() &&
rightVal.isNumericNull());
+ } else {
+ return ExprEval.ofLongBoolean(leftVal.asDouble() ==
rightVal.asDouble());
+ }
+ }
+ }
+
+ @Override
+ public void validateArguments(List<Expr> args)
+ {
+ validationHelperCheckArgumentCount(args, 2);
+ }
+
+ @Nullable
+ @Override
+ public ExpressionType getOutputType(Expr.InputBindingInspector inspector,
List<Expr> args)
+ {
+ return ExpressionType.LONG;
+ }
+ }
+
+ /**
+ * SQL function "x IS DISTINCT FROM y". Very similar to "x <> y", i.e.
{@link BinNeqExpr}, except this function
+ * never returns null.
+ */
+ class IsDistinctFromFunc extends IsNotDistinctFromFunc
+ {
+ @Override
+ public String name()
+ {
+ return "isdistinctfrom";
Review Comment:
```suggestion
return "is_distinct_from";
```
##########
processing/src/main/java/org/apache/druid/math/expr/Function.java:
##########
@@ -2224,6 +2224,89 @@ public <T> ExprVectorProcessor<T>
asVectorProcessor(Expr.VectorInputBindingInspe
}
}
+ /**
+ * SQL function "x IS NOT DISTINCT FROM y". Very similar to "x = y", i.e.
{@link BinEqExpr}, except this function
+ * never returns null, and this function considers NULL itself to be
not-distinct-from NULL.
+ */
+ class IsNotDistinctFromFunc implements Function
+ {
+ @Override
+ public String name()
+ {
+ return "notdistinctfrom";
Review Comment:
```suggestion
return "is_not_distinct_from";
```
##########
processing/src/main/java/org/apache/druid/math/expr/Function.java:
##########
@@ -2224,6 +2224,89 @@ public <T> ExprVectorProcessor<T>
asVectorProcessor(Expr.VectorInputBindingInspe
}
}
+ /**
+ * SQL function "x IS NOT DISTINCT FROM y". Very similar to "x = y", i.e.
{@link BinEqExpr}, except this function
+ * never returns null, and this function considers NULL itself to be
not-distinct-from NULL.
+ */
+ class IsNotDistinctFromFunc implements Function
+ {
+ @Override
+ public String name()
+ {
+ return "notdistinctfrom";
+ }
+
+ @Override
+ public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings)
+ {
+ final ExprEval leftVal = args.get(0).eval(bindings);
+ final ExprEval rightVal = args.get(1).eval(bindings);
+
+ if (leftVal.value() == null || rightVal.value() == null) {
+ return ExprEval.ofLongBoolean(leftVal.value() == null &&
rightVal.value() == null);
+ }
+
+ final ExpressionType comparisonType =
ExpressionTypeConversion.autoDetect(leftVal, rightVal);
+ switch (comparisonType.getType()) {
+ case STRING:
+ return ExprEval.ofLongBoolean(Objects.equals(leftVal.asString(),
rightVal.asString()));
+ case LONG:
+ return ExprEval.ofLongBoolean(leftVal.asLong() == rightVal.asLong());
+ case DOUBLE:
+ default:
+ if (leftVal.isNumericNull() || rightVal.isNumericNull()) {
+ return ExprEval.ofLongBoolean(leftVal.isNumericNull() &&
rightVal.isNumericNull());
Review Comment:
I am curious why this wasn't done if the comparison type was Long.
--
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]