richardstartin commented on code in PR #8563:
URL: https://github.com/apache/pinot/pull/8563#discussion_r853972376
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java:
##########
@@ -153,4 +152,19 @@ public static double truncate(double a, int scale) {
public static double truncate(double a) {
return Math.signum(a) * Math.floor(Math.abs(a));
}
+
+ @ScalarFunction(names = {"gte"})
+ public static boolean greaterThanOrEquals(double a, double b) {
+ return a >= b;
+ }
+
+ @ScalarFunction(names = {"lte"})
+ public static boolean lessThanOrEquals(double a, double b) {
+ return a <= b;
+ }
+
+ @ScalarFunction
+ public static boolean equals(double a, double b) {
+ return a == b;
Review Comment:
No, that would produce odd results too. `double`s should be compared for
equality within a tolerance because they are an _approximation_ of a number and
the error in the approximation should be accounted for.
For example, consider this program, which accumulates 1% 100 times:
```java
double d = 0.00;
for (int i = 0; i < 100; i++) {
d += 0.01;
}
System.out.println(d == 1D);
System.out.println(Double.compare(d, 1D));
System.out.println(Math.abs(d - 1D) < 1e-15);
```
it prints:
```
false
1
true
```
because of 1% isn't finitely expressible in base 2. However, the quantity is
clearly an approximation of 1. In order to make this function robust to
arithmetic performed by transform functions (prior to persistence or at query
time) equality should be verified relative to a small tolerance (1e-7 would be
best).
--
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]