Xuanwo commented on code in PR #24375: URL: https://github.com/apache/datafusion/pull/24375#discussion_r3864267097
########## datafusion/physical-expr/src/expressions/normalize_float_zero.rs: ########## @@ -0,0 +1,255 @@ +// 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. + +//! Floating-point signed-zero normalization expression. + +use std::hash::Hash; +use std::sync::Arc; + +use arrow::datatypes::{DataType, FieldRef, Schema}; +use arrow::record_batch::RecordBatch; +use datafusion_common::Result; +use datafusion_common::utils::{normalize_float_zero, normalize_float_zero_scalar}; +use datafusion_expr::ColumnarValue; +use datafusion_expr::interval_arithmetic::Interval; +use datafusion_expr::sort_properties::ExprProperties; + +use crate::PhysicalExpr; + +/// Replaces floating-point `-0.0` values with `+0.0`. +/// +/// Other values and data types are returned unchanged. This expression is +/// order-preserving but not strictly order-preserving because it collapses the +/// two signed-zero representations. +#[derive(Debug, Eq)] +pub struct NormalizeFloatZeroExpr { Review Comment: Good question. `normalize_float_zero` works on an already evaluated array, but here normalization must be part of the required ordering. For example, raw `[key, ts]` may be `(-0, 10), (+0, 1)`. Normalizing only during comparison makes them one equality group but leaves `ts` as `[10, 1]`, breaking the forward scan. We need the input sorted by `[normalize_float_zero(key), ts]`. The new `PhysicalExpr` is the plan-level wrapper around the existing helper, allowing `SortExec`, ordering enforcement, and protobuf to represent this without changing float sorting globally. --- Let me know if this addressed your concerns. I'm open to better ideas! -- 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]
