Skip to content

Commit

Permalink
patch: add ::is_compact method for GenericByteViewArray
Browse files Browse the repository at this point in the history
Signed-off-by: 蔡略 <cailue@bupt.edu.cn>
  • Loading branch information
ClSlaid committed May 5, 2024
1 parent 87a9d56 commit 3042ce0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions arrow-array/src/array/byte_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ use arrow_data::{ArrayData, ArrayDataBuilder, ByteView};
use arrow_schema::{ArrowError, DataType};
use std::any::Any;

#[cfg(test)]
use std::collections::BTreeMap;

use std::fmt::Debug;
use std::marker::PhantomData;
use std::sync::Arc;
Expand Down Expand Up @@ -270,8 +268,11 @@ impl<T: ByteViewType + ?Sized> GenericByteViewArray<T> {
}
}

// TODO: remove this after GC is implemented
#[cfg(test)]
/// check if the array is a compact view
pub fn is_compact(&self) -> bool {
self.compact_check().iter().all(|&x| x)
}

/// Returns whether the buffers are compact
pub(self) fn compact_check(&self) -> Vec<bool> {
let mut checkers: Vec<_> = self
Expand Down Expand Up @@ -515,14 +516,11 @@ impl From<Vec<Option<String>>> for StringViewArray {
/// so it is likely to scan the entire array.
///
/// Then it is better to do the check at once, rather than doing it for each accumulate operation.
#[cfg(test)]
struct CompactChecker {
length: usize,
intervals: BTreeMap<usize, usize>,
}

// TODO: remove this after GC is implemented
#[cfg(test)]
impl CompactChecker {
/// Create a new checker with the expected length of the buffer
pub fn new(length: usize) -> Self {
Expand Down Expand Up @@ -831,6 +829,7 @@ mod tests {
// array should have only one buffer
let array = builder.finish();
let compact_check = array.compact_check();
assert!(array.is_compact());
assert_eq!(compact_check.len(), 1);
assert!(compact_check.iter().all(|&x| x));

Expand All @@ -839,5 +838,6 @@ mod tests {
let compact_check = sliced.compact_check();
assert_eq!(compact_check.len(), 1);
assert!(!compact_check.iter().all(|&x| x));
assert!(!sliced.is_compact());
}
}

0 comments on commit 3042ce0

Please sign in to comment.