tustvold commented on code in PR #4701:
URL: https://github.com/apache/arrow-rs/pull/4701#discussion_r1295759504


##########
arrow-ord/src/cmp.rs:
##########
@@ -0,0 +1,527 @@
+// 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.
+
+//! Comparison kernels for `Array`s.
+//!
+//! These kernels can leverage SIMD if available on your system.  Currently no 
runtime
+//! detection is provided, you should enable the specific SIMD intrinsics using
+//! `RUSTFLAGS="-C target-feature=+avx2"` for example.  See the documentation
+//! [here](https://doc.rust-lang.org/stable/core/arch/) for more information.
+//!
+
+use arrow_array::cast::AsArray;
+use arrow_array::types::{ArrowDictionaryKeyType, ByteArrayType};
+use arrow_array::{
+    downcast_dictionary_array, downcast_primitive_array, Array, ArrayRef,
+    ArrowNativeTypeOp, BooleanArray, Datum, DictionaryArray, 
FixedSizeBinaryArray,
+    GenericByteArray,
+};
+use arrow_buffer::bit_util::ceil;
+use arrow_buffer::{ArrowNativeType, BooleanBuffer, MutableBuffer, NullBuffer};
+use arrow_schema::ArrowError;
+use arrow_select::take::take;
+
+#[derive(Debug, Copy, Clone)]
+enum Op {
+    Equal,
+    NotEqual,
+    Less,
+    LessEqual,
+    Greater,
+    GreaterEqual,
+}
+
+impl std::fmt::Display for Op {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        match self {
+            Op::Equal => write!(f, "=="),
+            Op::NotEqual => write!(f, "!="),
+            Op::Less => write!(f, "<"),
+            Op::LessEqual => write!(f, "<="),
+            Op::Greater => write!(f, ">"),
+            Op::GreaterEqual => write!(f, ">="),
+        }
+    }
+}
+
+/// Perform `left == right` operation on two [`Datum`]
+///
+/// For floating values like f32 and f64, this comparison produces an ordering 
in accordance to
+/// the totalOrder predicate as defined in the IEEE 754 (2008 revision) 
floating point standard.
+/// Note that totalOrder treats positive and negative zeros as different. If 
it is necessary
+/// to treat them as equal, please normalize zeros before calling this kernel.
+///
+/// Please refer to [`f32::total_cmp`] and [`f64::total_cmp`]
+pub fn eq(lhs: &dyn Datum, rhs: &dyn Datum) -> Result<BooleanArray, 
ArrowError> {
+    compare_op(Op::Equal, lhs, rhs)
+}
+
+/// Perform `left != right` operation on two [`Datum`]
+///
+/// For floating values like f32 and f64, this comparison produces an ordering 
in accordance to
+/// the totalOrder predicate as defined in the IEEE 754 (2008 revision) 
floating point standard.
+/// Note that totalOrder treats positive and negative zeros as different. If 
it is necessary
+/// to treat them as equal, please normalize zeros before calling this kernel.
+///
+/// Please refer to [`f32::total_cmp`] and [`f64::total_cmp`]
+pub fn neq(lhs: &dyn Datum, rhs: &dyn Datum) -> Result<BooleanArray, 
ArrowError> {
+    compare_op(Op::NotEqual, lhs, rhs)
+}
+
+/// Perform `left < right` operation on two [`Datum`]
+///
+/// For floating values like f32 and f64, this comparison produces an ordering 
in accordance to
+/// the totalOrder predicate as defined in the IEEE 754 (2008 revision) 
floating point standard.
+/// Note that totalOrder treats positive and negative zeros as different. If 
it is necessary
+/// to treat them as equal, please normalize zeros before calling this kernel.
+///
+/// Please refer to [`f32::total_cmp`] and [`f64::total_cmp`]
+pub fn lt(lhs: &dyn Datum, rhs: &dyn Datum) -> Result<BooleanArray, 
ArrowError> {
+    compare_op(Op::Less, lhs, rhs)
+}
+
+/// Perform `left <= right` operation on two [`Datum`]
+///
+/// For floating values like f32 and f64, this comparison produces an ordering 
in accordance to
+/// the totalOrder predicate as defined in the IEEE 754 (2008 revision) 
floating point standard.
+/// Note that totalOrder treats positive and negative zeros as different. If 
it is necessary
+/// to treat them as equal, please normalize zeros before calling this kernel.
+///
+/// Please refer to [`f32::total_cmp`] and [`f64::total_cmp`]
+pub fn lt_eq(lhs: &dyn Datum, rhs: &dyn Datum) -> Result<BooleanArray, 
ArrowError> {
+    compare_op(Op::LessEqual, lhs, rhs)
+}
+
+/// Perform `left > right` operation on two [`Datum`]
+///
+/// For floating values like f32 and f64, this comparison produces an ordering 
in accordance to
+/// the totalOrder predicate as defined in the IEEE 754 (2008 revision) 
floating point standard.
+/// Note that totalOrder treats positive and negative zeros as different. If 
it is necessary
+/// to treat them as equal, please normalize zeros before calling this kernel.
+///
+/// Please refer to [`f32::total_cmp`] and [`f64::total_cmp`]
+pub fn gt(lhs: &dyn Datum, rhs: &dyn Datum) -> Result<BooleanArray, 
ArrowError> {
+    compare_op(Op::Greater, lhs, rhs)
+}
+
+/// Perform `left >= right` operation on two [`Datum`]
+///
+/// For floating values like f32 and f64, this comparison produces an ordering 
in accordance to
+/// the totalOrder predicate as defined in the IEEE 754 (2008 revision) 
floating point standard.
+/// Note that totalOrder treats positive and negative zeros as different. If 
it is necessary
+/// to treat them as equal, please normalize zeros before calling this kernel.
+///
+/// Please refer to [`f32::total_cmp`] and [`f64::total_cmp`]
+pub fn gt_eq(lhs: &dyn Datum, rhs: &dyn Datum) -> Result<BooleanArray, 
ArrowError> {
+    compare_op(Op::GreaterEqual, lhs, rhs)
+}
+
+/// Perform `op` on the provided `Datum`
+fn compare_op(
+    op: Op,
+    lhs: &dyn Datum,
+    rhs: &dyn Datum,
+) -> Result<BooleanArray, ArrowError> {
+    use arrow_schema::DataType::*;
+    let (l, l_s) = lhs.get();
+    let (r, r_s) = rhs.get();

Review Comment:
   Whilst I would agree in principle, the formatting becomes ludicrous with 
this change, making the code significantly harder to read, as the function 
becomes multiple pages long.



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

Reply via email to