Skip to content

Commit

Permalink
Merge pull request #387 from dora-rs/simpler-conversion
Browse files Browse the repository at this point in the history
Adding conversion from `ArrayData` for simpler conversion and adding `Vec<u8>` conversion
  • Loading branch information
phil-opp authored Dec 8, 2023
2 parents 631dcff + d975fc1 commit a7244f0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 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},

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Bench (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Bench (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Bench (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Bench (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Bench (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Bench (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Bench (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Bench (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Bench (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Bench (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Bench (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Bench (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / CLI Test (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / CLI Test (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / CLI Test (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / ROS2 Bridge Examples

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / ROS2 Bridge Examples

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / ROS2 Bridge Examples

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / ROS2 Bridge Examples

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / ROS2 Bridge Examples

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / CLI Test (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / CLI Test (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / CLI Test (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / CLI Test (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / CLI Test (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / CLI Test (macos-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

unused import: `make_array`

Check warning on line 2 in libraries/arrow-convert/src/from_impls.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

unused import: `make_array`
datatypes::ArrowPrimitiveType,
};
use eyre::ContextCompat;
Expand Down Expand Up @@ -136,6 +136,13 @@ 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> {
value.try_into().map(|slice: &'a [u8]| slice.to_vec())
}
}

fn extract_single_primitive<T>(array: &PrimitiveArray<T>) -> Result<T::Native, eyre::Error>
where
T: ArrowPrimitiveType,
Expand All @@ -151,3 +158,19 @@ where
}
Ok(array.value(0))
}

#[cfg(test)]
mod tests {
use arrow::array::{make_array, PrimitiveArray};

use crate::ArrowData;

#[test]
fn test_u8() {
let array =
make_array(PrimitiveArray::<arrow::datatypes::UInt8Type>::from(vec![42]).into());
let data: ArrowData = array.into();
let value: u8 = (&data).try_into().unwrap();
assert_eq!(value, 42);
}
}
2 changes: 1 addition & 1 deletion libraries/message/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl ArrowTypeInfo {
let offset = usize::try_from(unsafe { ptr.offset_from(region_start) })
.context("offset_from is negative")?;

Ok(BufferOffset {
Result::<_, eyre::Report>::Ok(BufferOffset {
offset,
len: b.len(),
})
Expand Down

0 comments on commit a7244f0

Please sign in to comment.