Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion parquet-variant/src/variant/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl VariantListHeader {
///
/// [valid]: VariantMetadata#Validation
/// [Variant spec]: https://github.com/apache/parquet-format/blob/master/VariantEncoding.md#value-data-for-array-basic_type3
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone)]
pub struct VariantList<'m, 'v> {
pub metadata: VariantMetadata<'m>,
pub value: &'v [u8],
Expand Down Expand Up @@ -302,6 +302,16 @@ impl<'m, 'v> VariantList<'m, 'v> {
}
}

impl<'m, 'v> PartialEq for VariantList<'m, 'v> {
fn eq(&self, other: &Self) -> bool {
self.metadata == other.metadata
&& self.value == other.value
&& self.header == other.header
&& self.num_elements == other.num_elements
&& self.first_value_byte == other.first_value_byte
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -627,4 +637,24 @@ mod tests {
assert_eq!(expected_list.get(i).unwrap(), item_str);
}
}

#[test]
fn items_are_equal_even_if_not_validated() {
use crate::Variant;
use crate::VariantBuilder;

let mut builder = VariantBuilder::new();

let mut list = builder.new_list();
list.append_value("hello2");
list.finish();

let (metadata, value) = builder.finish();

let variant1 = Variant::new(&metadata, &value);
let variant2 = Variant::new(&metadata, &value)
.with_full_validation()
.unwrap();
assert_eq!(variant1, variant2)
}
}
17 changes: 13 additions & 4 deletions parquet-variant/src/variant/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,8 @@ impl<'m> VariantMetadata<'m> {
// checks whether the dictionary entries are equal -- regardless of their sorting order
impl<'m> PartialEq for VariantMetadata<'m> {
fn eq(&self, other: &Self) -> bool {
let is_equal = self.is_empty() == other.is_empty()
&& self.is_fully_validated() == other.is_fully_validated()
&& self.first_value_byte == other.first_value_byte
&& self.validated == other.validated;
let is_equal =
self.is_empty() == other.is_empty() && self.first_value_byte == other.first_value_byte;

let other_field_names: HashSet<&'m str> = HashSet::from_iter(other.iter());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any chance that other_field_names contains items not in self.iter()

Expand Down Expand Up @@ -531,4 +529,15 @@ mod tests {
"unexpected error: {err:?}"
);
}

#[test]
fn metadata_is_equal() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to add some negative tests

let metadata_bytes = vec![0x11, 0, 0];
let metadata1 = VariantMetadata::try_new(&metadata_bytes).unwrap();
let metadata2 = VariantMetadata::try_new(&metadata_bytes)
.unwrap()
.with_full_validation()
.unwrap();
assert_eq!(metadata1, metadata2)
}
}
24 changes: 22 additions & 2 deletions parquet-variant/src/variant/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ impl<'m, 'v> PartialEq for VariantObject<'m, 'v> {
&& self.header == other.header
&& self.num_elements == other.num_elements
&& self.first_field_offset_byte == other.first_field_offset_byte
&& self.first_value_byte == other.first_value_byte
&& self.validated == other.validated;
&& self.first_value_byte == other.first_value_byte;

// value validation
let other_fields: HashMap<&str, Variant> = HashMap::from_iter(other.iter());
Expand Down Expand Up @@ -949,4 +948,25 @@ mod tests {
// objects are still logically equal
assert_eq!(v1, v2);
}

#[test]
fn items_are_equal_even_if_not_validated() {
use crate::Variant;
use crate::VariantBuilder;

let mut builder = VariantBuilder::new();
let mut obj = builder.new_object();
obj.insert("field1", "hello");
obj.insert("field2", 34);
obj.insert("field3", true);
obj.finish().unwrap();

let (metadata, value) = builder.finish();

let variant1 = Variant::new(&metadata, &value);
let variant2 = Variant::new(&metadata, &value)
.with_full_validation()
.unwrap();
assert_eq!(variant1, variant2)
}
}
Loading