Skip to content

Commit

Permalink
impl partialEq for Struct
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKaul committed Oct 20, 2024
1 parent 2f36fe0 commit ab21d34
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions iceberg-rust-spec/src/spec/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::{
any::Any,
collections::{BTreeMap, HashMap},
collections::{btree_map::Keys, BTreeMap, HashMap},
fmt,
io::Cursor,
slice::Iter,
Expand Down Expand Up @@ -128,7 +128,7 @@ impl fmt::Display for Value {
/// The partition struct stores the tuple of partition values for each file.
/// Its type is derived from the partition fields of the partition spec used to write the manifest file.
/// In v2, the partition struct’s field ids must match the ids from the partition spec.
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Debug, Clone, Eq, Hash, PartialOrd, Ord)]
pub struct Struct {
/// Vector to store the field values
pub fields: Vec<Option<Value>>,
Expand All @@ -150,6 +150,10 @@ impl Struct {
self.fields.iter()
}

pub fn keys(&self) -> Keys<'_, String, usize> {
self.lookup.keys()
}

pub(crate) fn cast(
self,
schema: &StructType,
Expand Down Expand Up @@ -263,6 +267,12 @@ impl<'de> Deserialize<'de> for Struct {
}
}

impl PartialEq for Struct {
fn eq(&self, other: &Self) -> bool {
self.keys().all(|key| self.get(key).eq(&other.get(key)))
}
}

impl Value {
/// Perform a partition transformation for the given value
pub fn tranform(&self, transform: &Transform) -> Result<Value, Error> {
Expand Down

0 comments on commit ab21d34

Please sign in to comment.