yyanyy commented on pull request #2069:
URL: https://github.com/apache/iceberg/pull/2069#issuecomment-761266457
> Odd, maybe we're trying different things. What does this print for you?
>
> ```
> public class Comp {
> public static void main(String[] args) {
> System.out.println(Double.NaN > 0.0);
> }
> }
> ```
>
> I'm on OpenJDK 1.8, and this prints `false` for me.
Yeah this prints `false` for me too, as well as `Double.NaN == Double.NaN`.
I think we workaround this problem in evaluators by using a
[`Comparator.naturalOrder()`](https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/expressions/Literals.java#L156)
instead of direct operator comparison, as the following code prints the
behavior that NaN is considered larger than positive infinity as described in
[here](https://docs.oracle.com/javase/8/docs/api/java/lang/Double.html#compareTo-java.lang.Double-)(by
returning -1, 1, 1, -1, 0 respectively)
```
Comparator comparator = Comparator.naturalOrder();
System.out.println(comparator.compare(1.2F, Float.NaN));
System.out.println(comparator.compare(Float.NaN, 1.2F));
System.out.println(comparator.compare(Float.NaN,
Float.POSITIVE_INFINITY));
System.out.println(comparator.compare(Float.POSITIVE_INFINITY,
Float.NaN));
System.out.println(comparator.compare(Float.NaN, Float.NaN));
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]