Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Vec<u8> conversion #387

Merged
merged 5 commits into from
Dec 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion libraries/arrow-convert/src/from_impls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use arrow::{
array::{Array, AsArray, PrimitiveArray, StringArray},
array::{make_array, Array, AsArray, PrimitiveArray, StringArray},
datatypes::ArrowPrimitiveType,
};
use eyre::ContextCompat;
Expand All @@ -18,6 +18,18 @@ impl From<arrow::array::ArrayRef> for ArrowData {
}
}

impl From<ArrowData> for arrow::array::ArrayData {
fn from(value: ArrowData) -> Self {
value.0.to_data()
}
}
haixuanTao marked this conversation as resolved.
Show resolved Hide resolved

impl From<arrow::array::ArrayData> for ArrowData {
fn from(value: arrow::array::ArrayData) -> Self {
Self(make_array(value))
}
}
haixuanTao marked this conversation as resolved.
Show resolved Hide resolved

impl TryFrom<&ArrowData> for bool {
type Error = eyre::Report;
fn try_from(value: &ArrowData) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -136,6 +148,18 @@ impl<'a> TryFrom<&'a ArrowData> for &'a [u8] {
}
}

impl<'a> TryFrom<&'a ArrowData> for Vec<u8> {
type Error = eyre::Report;
fn try_from(value: &'a ArrowData) -> Result<Self, Self::Error> {
let array: &PrimitiveArray<arrow::datatypes::UInt8Type> =
value.as_primitive_opt().wrap_err("not a primitive array")?;
if array.null_count() != 0 {
eyre::bail!("array has nulls");
}
Ok(array.values().to_vec())
haixuanTao marked this conversation as resolved.
Show resolved Hide resolved
}
}

fn extract_single_primitive<T>(array: &PrimitiveArray<T>) -> Result<T::Native, eyre::Error>
where
T: ArrowPrimitiveType,
Expand Down
Loading