Skip to content

Commit

Permalink
Remove unnecessary Option from Int96 (#2471)
Browse files Browse the repository at this point in the history
* Remove unnecessary Option from Int96

* Clippy
  • Loading branch information
tustvold authored Aug 17, 2022
1 parent 4e4902f commit 5e8586a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
22 changes: 5 additions & 17 deletions parquet/src/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,27 @@ use crate::util::{

/// Rust representation for logical type INT96, value is backed by an array of `u32`.
/// The type only takes 12 bytes, without extra padding.
#[derive(Clone, Debug, PartialOrd, Default)]
#[derive(Clone, Debug, PartialOrd, Default, PartialEq, Eq)]
pub struct Int96 {
value: Option<[u32; 3]>,
value: [u32; 3],
}

impl Int96 {
/// Creates new INT96 type struct with no data set.
pub fn new() -> Self {
Self { value: None }
Self { value: [0; 3] }
}

/// Returns underlying data as slice of [`u32`].
#[inline]
pub fn data(&self) -> &[u32] {
self.value
.as_ref()
.expect("set_data should have been called")
&self.value
}

/// Sets data for this INT96 type.
#[inline]
pub fn set_data(&mut self, elem0: u32, elem1: u32, elem2: u32) {
self.value = Some([elem0, elem1, elem2]);
self.value = [elem0, elem1, elem2];
}

/// Converts this INT96 into an i64 representing the number of MILLISECONDS since Epoch
Expand All @@ -75,16 +73,6 @@ impl Int96 {
}
}

impl PartialEq for Int96 {
fn eq(&self, other: &Int96) -> bool {
match (&self.value, &other.value) {
(Some(v1), Some(v2)) => v1 == v2,
(None, None) => true,
_ => false,
}
}
}

impl From<Vec<u32>> for Int96 {
fn from(buf: Vec<u32>) -> Self {
assert_eq!(buf.len(), 3);
Expand Down
2 changes: 1 addition & 1 deletion parquet/src/encodings/encoding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ mod tests {
run_test::<Int96Type>(
-1,
&[Int96::from(vec![1, 2, 3]), Int96::from(vec![2, 3, 4])],
32,
24,
);
run_test::<ByteArrayType>(
-1,
Expand Down

0 comments on commit 5e8586a

Please sign in to comment.