jayzhan211 commented on code in PR #26595:
URL: https://github.com/apache/datafusion/pull/26595#discussion_r4360533624


##########
datafusion/common/src/float_semantics.rs:
##########
@@ -0,0 +1,342 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Float semantics for DataFusion.
+//!
+//! Arrow's comparison kernels work on the bit pattern of a float,
+//! i.e. IEEE 754 totalOrder. DataFusion deviates from that in one
+//! respect: `+0.0` and `-0.0` are equal, hash the same and fall into the same
+//! group. See [`normalize_float`], [`normalize_floats`] and
+//! [`normalize_float_scalar`]. Ordering still follows totalOrder, so
+//! [`compare_floats`] sorts `-0.0` before `+0.0`.
+//!
+//! Every comparison, hash or grouping boundary should be built from these
+//! helpers rather than inspecting float bits itself. Where an Arrow kernel
+//! compares, sorts, row-encodes or hashes the values, normalize them first.
+//! Where DataFusion compares values itself, use [`compare_floats`],

Review Comment:
   This paragraph mixes up equality and ordering. `compare_floats(-0.0, 0.0)` 
is `Less`, so an equality check written with `compare_floats` (the IN list, 
`nullif` and `array_has` steps of #26138) would still treat the two zeros as 
different. Also, "normalize before sorting" contradicts "Ordering still follows 
totalOrder" above. Maybe split it by purpose:
   
   ```diff
   -//! Every comparison, hash or grouping boundary should be built from these
   -//! helpers rather than inspecting float bits itself. Where an Arrow kernel
   -//! compares, sorts, row-encodes or hashes the values, normalize them first.
   -//! Where DataFusion compares values itself, use [`compare_floats`],
   -//! [`float_lt`] or [`float_gt`]. Where it hashes them, hash [`hash_input`].
   +//! Every comparison, hash or grouping boundary should be built from these
   +//! helpers rather than inspecting float bits itself:
   +//!
   +//! - Equality and grouping: normalize first ([`normalize_float`],
   +//!   [`normalize_floats`]), then compare bits or call Arrow's `eq`,
   +//!   `RowConverter` or `make_comparator`. Hash [`hash_input`].
   +//! - Ordering: use [`compare_floats`], [`float_lt`] or [`float_gt`]. 
Sorting
   +//!   does not normalize yet, so `-0.0` still sorts before `+0.0`.
   ```
   
   The `hash_input` doc has the same ambiguity ("Values that compare as 
equal"); "Values that are equal in SQL" would match.



-- 
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]

Reply via email to