tustvold commented on code in PR #5672:
URL: https://github.com/apache/arrow-rs/pull/5672#discussion_r1573748425
##########
arrow-ord/src/ord.rs:
##########
@@ -24,33 +24,107 @@ use arrow_buffer::ArrowNativeType;
use arrow_schema::ArrowError;
use std::cmp::Ordering;
+#[derive(Debug, PartialEq, Eq)]
+pub enum Compare {
+ Less,
+ Greater,
+ Equal,
+ LeftNull,
+ RightNull,
+ BothNull,
+}
+
+impl Compare {
+ pub fn ordering(&self, null_first: bool) -> Ordering {
+ match self {
+ Self::Less => Ordering::Less,
+ Self::Greater => Ordering::Greater,
+ Self::Equal => Ordering::Equal,
+ Self::LeftNull => {
+ if null_first {
+ Ordering::Less
+ } else {
+ Ordering::Greater
+ }
+ }
+ Self::RightNull => {
+ if null_first {
+ Ordering::Greater
+ } else {
+ Ordering::Less
+ }
+ }
+ Self::BothNull => Ordering::Equal,
+ }
+ }
+
+ #[inline]
+ pub fn is_null(&self) -> bool {
+ matches!(self, Self::LeftNull | Self::RightNull | Self::BothNull)
+ }
+
+ #[inline]
+ pub const fn reverse(self) -> Self {
+ match self {
+ Self::Less => Self::Greater,
+ Self::Greater => Self::Less,
+ _ => self,
+ }
+ }
+}
+
+impl From<Ordering> for Compare {
+ fn from(ordering: Ordering) -> Self {
+ match ordering {
+ Ordering::Less => Self::Less,
+ Ordering::Greater => Self::Greater,
+ Ordering::Equal => Self::Equal,
+ }
+ }
+}
+
/// Compare the values at two arbitrary indices in two arrays.
-pub type DynComparator = Box<dyn Fn(usize, usize) -> Ordering + Send + Sync>;
+pub type DynComparator = Box<dyn Fn(usize, usize) -> Compare + Send + Sync>;
Review Comment:
Currently this will be a breaking change, we might want to make this change
additive and deprecate `DynComparator` instead
--
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]