findepi commented on PR #16745: URL: https://github.com/apache/datafusion/pull/16745#issuecomment-3108936064
You're absolutely right. The ORDER BY ordering and `<` operator are not the same thing. The ORDER BY places NaN as higher than +inf, while `<` operator _should likely_ return false for any `<` comparison involving NaN (same for `=`). > However, SQL comparisons follow IEEE 754 ordering semantics, so -0.0 == 0.0 is true, and both -0.0 < 0.0 and -0.0 > 0.0 are false. Not sure whether you mean SQL spec, or what's implemented in DataFusion, or what DataFusion should be implementing? What's currently implemented seems to be this: ``` > WITH fs AS (SELECT t::float AS f FROM (values ('0'), ('-0'), ('NaN')) _(t)) SELECT f1, f2, f1 = f2, f1 < f2, f2 < f1 FROM fs _(f1), fs _(f2); +------+------+-------------+-------------+-------------+ | f1 | f2 | _.f1 = _.f2 | _.f1 < _.f2 | _.f2 < _.f1 | +------+------+-------------+-------------+-------------+ | 0.0 | 0.0 | true | false | false | | 0.0 | -0.0 | false | false | true | -- apparently 0 compares greater than -0 | 0.0 | NaN | false | true | false | -- apparently 0 compares less than NaN | -0.0 | 0.0 | false | true | false | -- apparently -0 compares less than 0 | -0.0 | -0.0 | true | false | false | | -0.0 | NaN | false | true | false | | NaN | 0.0 | false | false | true | | NaN | -0.0 | false | false | true | | NaN | NaN | true | false | false | -- Is NaN = NaN following IEEE 754? at least in C it's false +------+------+-------------+-------------+-------------+ 9 row(s) fetched. Elapsed 0.016 seconds. ``` -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org