Skip to content

Commit

Permalink
Remove GenericStringArray::from_vec and `GenericStringArray::from_o…
Browse files Browse the repository at this point in the history
…pt_vec` (#1147)
  • Loading branch information
alamb authored Jan 11, 2022
1 parent e2130d9 commit 79d4ab0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 35 deletions.
34 changes: 3 additions & 31 deletions arrow/src/array/array_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,34 +137,6 @@ impl<OffsetSize: StringOffsetSizeTrait> GenericStringArray<OffsetSize> {
Self::from(array_data)
}

pub(crate) fn from_vec<Ptr>(v: Vec<Ptr>) -> Self
where
Ptr: AsRef<str>,
{
let mut offsets =
MutableBuffer::new((v.len() + 1) * std::mem::size_of::<OffsetSize>());
let mut values = MutableBuffer::new(0);

let mut length_so_far = OffsetSize::zero();
offsets.push(length_so_far);

for s in &v {
length_so_far += OffsetSize::from_usize(s.as_ref().len()).unwrap();
offsets.push(length_so_far);
values.extend_from_slice(s.as_ref().as_bytes());
}
let array_data = ArrayData::builder(OffsetSize::DATA_TYPE)
.len(v.len())
.add_buffer(offsets.into())
.add_buffer(values.into());
let array_data = unsafe { array_data.build_unchecked() };
Self::from(array_data)
}

pub(crate) fn from_opt_vec(v: Vec<Option<&str>>) -> Self {
v.into_iter().collect()
}

/// Creates a `GenericStringArray` based on an iterator of values without nulls
pub fn from_iter_values<Ptr, I: IntoIterator<Item = Ptr>>(iter: I) -> Self
where
Expand Down Expand Up @@ -326,23 +298,23 @@ impl<OffsetSize: StringOffsetSizeTrait> From<Vec<Option<&str>>>
for GenericStringArray<OffsetSize>
{
fn from(v: Vec<Option<&str>>) -> Self {
GenericStringArray::<OffsetSize>::from_opt_vec(v)
v.into_iter().collect()
}
}

impl<OffsetSize: StringOffsetSizeTrait> From<Vec<&str>>
for GenericStringArray<OffsetSize>
{
fn from(v: Vec<&str>) -> Self {
GenericStringArray::<OffsetSize>::from_vec(v)
GenericStringArray::<OffsetSize>::from_iter_values(v)
}
}

impl<OffsetSize: StringOffsetSizeTrait> From<Vec<String>>
for GenericStringArray<OffsetSize>
{
fn from(v: Vec<String>) -> Self {
GenericStringArray::<OffsetSize>::from_vec(v)
GenericStringArray::<OffsetSize>::from_iter_values(v)
}
}

Expand Down
6 changes: 2 additions & 4 deletions arrow/src/array/equal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,9 @@ mod tests {
let cases = binary_cases();

for (lhs, rhs, expected) in cases {
let lhs = lhs.iter().map(|x| x.as_deref()).collect();
let rhs = rhs.iter().map(|x| x.as_deref()).collect();
let lhs = GenericStringArray::<OffsetSize>::from_opt_vec(lhs);
let lhs: GenericStringArray<OffsetSize> = lhs.into_iter().collect();
let lhs = lhs.data();
let rhs = GenericStringArray::<OffsetSize>::from_opt_vec(rhs);
let rhs: GenericStringArray<OffsetSize> = rhs.into_iter().collect();
let rhs = rhs.data();
test_equal(lhs, rhs, expected);
}
Expand Down

0 comments on commit 79d4ab0

Please sign in to comment.