This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 79d4ab0 Remove `GenericStringArray::from_vec` and
`GenericStringArray::from_opt_vec` (#1147)
79d4ab0 is described below
commit 79d4ab0e2c6579a8cd4514dfb1406ac8e920aaa7
Author: Andrew Lamb <[email protected]>
AuthorDate: Tue Jan 11 12:58:02 2022 -0500
Remove `GenericStringArray::from_vec` and
`GenericStringArray::from_opt_vec` (#1147)
---
arrow/src/array/array_string.rs | 34 +++-------------------------------
arrow/src/array/equal/mod.rs | 6 ++----
2 files changed, 5 insertions(+), 35 deletions(-)
diff --git a/arrow/src/array/array_string.rs b/arrow/src/array/array_string.rs
index d1826ef..6af8bae 100644
--- a/arrow/src/array/array_string.rs
+++ b/arrow/src/array/array_string.rs
@@ -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
@@ -326,7 +298,7 @@ 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()
}
}
@@ -334,7 +306,7 @@ 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)
}
}
@@ -342,7 +314,7 @@ 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)
}
}
diff --git a/arrow/src/array/equal/mod.rs b/arrow/src/array/equal/mod.rs
index 742eeec..09ba0cd 100644
--- a/arrow/src/array/equal/mod.rs
+++ b/arrow/src/array/equal/mod.rs
@@ -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);
}