-
|
Hi, Is there a good way to convert an So far the rough solution I've come up with looks as follows: fn arrow_array_to_polars_series(
name: &str,
array: &Arc<dyn arrow::array::Array>,
) -> Result<polars::series::Series, String> {
match array.data_type() {
arrow::datatypes::DataType::Binary => {
match array.as_any().downcast_ref::<arrow::array::BinaryArray>() {
Some(downcast) => Ok(polars::series::Series::new(
name,
downcast.iter().collect::<Vec<Option<&[u8]>>>(),
)),
_ => Err("Couldn't downcast!".into()),
}
}
arrow::datatypes::DataType::Int8 => {
match array.as_any().downcast_ref::<arrow::array::Int32Array>() {
Some(downcast) => Ok(polars::series::Series::new(
name,
downcast.iter().collect::<Vec<Option<i32>>>(),
)),
_ => Err("Couldn't downcast!".into()),
}
}
// Numerous other arrow::datatypes::DataTypes to be filled in below here...
_ => Err("Unhandled data type!".into()),
}
}However, there are at least 3 problems with fully implementing this approach:
I feel like there may well be a better approach than the one sketched above, so if anyone has any pointers or suggestions I'd be very grateful. (For context, the arrow arrays are coming from a SQL query executed by connectorx, and I'm trying to find a way to convert this column data into a Thanks! Dan |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
I'm running into the same issue. Have you found a solution? |
Beta Was this translation helpful? Give feedback.
-
The underlying representation is Vec with a separate structure for nulls, so you can't directly go to Vec<Option> The way to convert an Array to a Vec is:
|
Beta Was this translation helpful? Give feedback.
The underlying representation is Vec with a separate structure for nulls, so you can't directly go to Vec<Option>
The way to convert an Array to a Vec is:
PrimitiveArrayPrimitiveArray::into_partsto get the scalar buffer (that holds the value)ScalarBuffer::to_vec