Skip to content

Commit

Permalink
Add writing statistics for FixedLenByteArray
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhtm1 committed Oct 2, 2021
1 parent e79e784 commit 554ec05
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/write/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ pub fn reduce(stats: &[&Option<Arc<dyn Statistics>>]) -> Result<Option<Arc<dyn S
let stats = stats.iter().map(|x| x.as_any().downcast_ref().unwrap());
Some(Arc::new(reduce_binary(stats)))
}
PhysicalType::FixedLenByteArray(_) => {
let stats = stats.iter().map(|x| x.as_any().downcast_ref().unwrap());
Some(Arc::new(reduce_fix_len_binary(stats)))
}
_ => todo!(),
})
}
Expand Down Expand Up @@ -83,6 +87,33 @@ fn reduce_binary<'a, I: Iterator<Item = &'a BinaryStatistics>>(mut stats: I) ->
})
}

fn reduce_fix_len_binary<'a, I: Iterator<Item = &'a FixedLenStatistics>>(mut stats: I) -> FixedLenStatistics {
let initial = stats.next().unwrap().clone();
stats.fold(initial, |mut acc, new| {
acc.min_value = match (acc.min_value, &new.min_value) {
(None, None) => None,
(Some(x), None) => Some(x),
(None, Some(x)) => Some(x.clone()),
(Some(x), Some(y)) => Some(ord_binary(x, y.clone(), false)),
};
acc.max_value = match (acc.max_value, &new.max_value) {
(None, None) => None,
(Some(x), None) => Some(x),
(None, Some(x)) => Some(x.clone()),
(Some(x), Some(y)) => Some(ord_binary(x, y.clone(), true)),
};
acc.null_count = match (acc.null_count, &new.null_count) {
(None, None) => None,
(Some(x), None) => Some(x),
(None, Some(x)) => Some(*x),
(Some(x), Some(y)) => Some(x + *y),
};
acc.distinct_count = None;
acc
})
}


fn ord_binary(a: Vec<u8>, b: Vec<u8>, max: bool) -> Vec<u8> {
for (v1, v2) in a.iter().zip(b.iter()) {
match v1.cmp(v2) {
Expand Down

0 comments on commit 554ec05

Please sign in to comment.