Skip to content

Commit

Permalink
Fix scalar eq for booleans (#2168)
Browse files Browse the repository at this point in the history
And derive partial eq where we can
  • Loading branch information
gatesn authored Jan 31, 2025
1 parent d0294e4 commit 46c770b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 36 deletions.
13 changes: 4 additions & 9 deletions vortex-scalar/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@ use vortex_error::{vortex_bail, vortex_err, VortexError, VortexExpect as _, Vort

use crate::{InnerScalarValue, Scalar, ScalarValue};

#[derive(Debug, Hash)]
#[derive(Debug, Hash, PartialEq, Eq)]
pub struct BinaryScalar<'a> {
dtype: &'a DType,
value: Option<ByteBuffer>,
}

impl PartialEq for BinaryScalar<'_> {
fn eq(&self, other: &Self) -> bool {
self.dtype == other.dtype && self.value == other.value
}
}

impl Eq for BinaryScalar<'_> {}

/// Ord is not implemented since it's undefined for different nullability
impl PartialOrd for BinaryScalar<'_> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
if self.dtype != other.dtype {
return None;
}
self.value.partial_cmp(&other.value)
}
}
Expand Down
10 changes: 1 addition & 9 deletions vortex-scalar/src/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@ use vortex_error::{vortex_bail, vortex_err, VortexError, VortexExpect as _, Vort

use crate::{InnerScalarValue, Scalar, ScalarValue};

#[derive(Debug, Hash)]
#[derive(Debug, Hash, PartialEq, Eq)]
pub struct BoolScalar<'a> {
dtype: &'a DType,
value: Option<bool>,
}

impl PartialEq for BoolScalar<'_> {
fn eq(&self, other: &Self) -> bool {
self.value == other.value
}
}

impl Eq for BoolScalar<'_> {}

impl PartialOrd for BoolScalar<'_> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if self.dtype != other.dtype {
Expand Down
10 changes: 1 addition & 9 deletions vortex-scalar/src/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@ use vortex_error::{
use crate::pvalue::PValue;
use crate::{InnerScalarValue, Scalar, ScalarValue};

#[derive(Debug, Clone, Copy, Hash)]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub struct PrimitiveScalar<'a> {
dtype: &'a DType,
ptype: PType,
pvalue: Option<PValue>,
}

impl PartialEq for PrimitiveScalar<'_> {
fn eq(&self, other: &Self) -> bool {
self.dtype() == other.dtype() && self.pvalue == other.pvalue
}
}

impl Eq for PrimitiveScalar<'_> {}

/// Ord is not implemented since it's undefined for different nullability
impl PartialOrd for PrimitiveScalar<'_> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Expand Down
13 changes: 4 additions & 9 deletions vortex-scalar/src/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@ use vortex_error::{vortex_bail, vortex_err, VortexError, VortexExpect as _, Vort

use crate::{InnerScalarValue, Scalar, ScalarValue};

#[derive(Debug, Hash)]
#[derive(Debug, Hash, PartialEq, Eq)]
pub struct Utf8Scalar<'a> {
dtype: &'a DType,
value: Option<BufferString>,
}

impl PartialEq for Utf8Scalar<'_> {
fn eq(&self, other: &Self) -> bool {
self.dtype == other.dtype && self.value == other.value
}
}

impl Eq for Utf8Scalar<'_> {}

/// Ord is not implemented since it's undefined for different nullability
impl PartialOrd for Utf8Scalar<'_> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
if self.dtype != other.dtype {
return None;
}
self.value.partial_cmp(&other.value)
}
}
Expand Down

0 comments on commit 46c770b

Please sign in to comment.