Skip to content

Commit

Permalink
Code review actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Swoorup committed Oct 1, 2024
1 parent 7bf484c commit 3b329b7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
15 changes: 15 additions & 0 deletions arrow_convert/src/features/glam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ use arrow::array::{BooleanBuilder, Float32Builder, Float64Builder};
use arrow::array::{FixedSizeListArray, FixedSizeListBuilder};
use std::sync::Arc;

/// This macro implements the `ArrowSerialize` and `ArrowDeserialize` traits for a given `glam` vector or matrix type.
///
/// The macro takes the following parameters:
/// - `$type`: The type of the `glam` vector or matrix to implement the traits for.
/// - `$size`: The size of the vector or matrix (e.g. 2 for `glam::Vec2`, 4 for `glam::Mat4`).
/// - `$dt`: The data type of the elements in the vector or matrix (e.g. `bool`, `f32`).
/// - `$arrow_dt`: The corresponding Arrow data type for the element type.
/// - `$array_builder`: The Arrow array builder type to use for the element type.
/// - `$se`: A closure that serializes the `$type` to a slice of the element type.
/// - `$de`: A closure that deserializes a `Vec` of the element type to the `$type`.
macro_rules! impl_glam_ty {
($type:ty, $size:expr, $dt:ident, $arrow_dt:expr, $array_builder:ident, $se:expr, $de:expr) => {
impl ArrowField for $type {
Expand Down Expand Up @@ -53,6 +63,7 @@ macro_rules! impl_glam_ty {
};
}

/// Implements the `ArrowSerialize` and `ArrowDeserialize` traits for the given `glam::Vec<bool>` type.
macro_rules! impl_glam_vec_bool {
($type:ty, $size:expr) => {
impl_glam_ty!(
Expand All @@ -79,6 +90,7 @@ macro_rules! impl_glam_vec_bool {
};
}

/// Implements the `ArrowSerialize` and `ArrowDeserialize` traits for the given `glam::Vec2` type.
macro_rules! impl_glam_vec_f32 {
($type:ty, $size:expr) => {
impl_glam_ty!(
Expand All @@ -93,6 +105,7 @@ macro_rules! impl_glam_vec_f32 {
};
}

/// Implements the `ArrowSerialize` and `ArrowDeserialize` traits for the given `glam::Mat2`, `glam::Mat3`, and `glam::Mat4` types.
macro_rules! impl_glam_mat_f32 {
($type:ty, $size:expr) => {
impl_glam_ty!(
Expand All @@ -107,6 +120,7 @@ macro_rules! impl_glam_mat_f32 {
};
}

/// Implements the `ArrowSerialize` and `ArrowDeserialize` traits for the given `glam::DVec2`, `glam::DVec3`, and `glam::DVec4` types.
macro_rules! impl_glam_vec_f64 {
($type:ty, $size:expr) => {
impl_glam_ty!(
Expand All @@ -121,6 +135,7 @@ macro_rules! impl_glam_vec_f64 {
};
}

/// Implements the `ArrowSerialize` and `ArrowDeserialize` traits for the given `glam::DMat2`, `glam::DMat3`, and `glam::DMat4` types.
macro_rules! impl_glam_mat_f64 {
($type:ty, $size:expr) => {
impl_glam_ty!(
Expand Down
21 changes: 21 additions & 0 deletions arrow_convert/tests/test_tinystr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,24 @@ fn test_tinyasciistr_roundtrip() {
// Verify the roundtrip
assert_eq!(original, roundtrip);
}

#[cfg(feature = "tinystr")]
#[test]
fn test_tinyasciistr_max_length() {
use arrow::array::{Array, ArrayRef, FixedSizeBinaryArray};
use arrow_convert::deserialize::TryIntoCollection;
use arrow_convert::serialize::TryIntoArrow;
use tinystr::TinyAsciiStr;

let original: Vec<TinyAsciiStr<10>> = vec![TinyAsciiStr::from_str("ABCDEFGHIJ").unwrap()];

let arrow_array: ArrayRef = original.try_into_arrow().expect("Failed to convert to Arrow array");
assert!(arrow_array.as_any().is::<FixedSizeBinaryArray>());
let fixed_size_array = arrow_array.as_any().downcast_ref::<FixedSizeBinaryArray>().unwrap();
assert_eq!(fixed_size_array.value_length(), 10);

let roundtrip: Vec<TinyAsciiStr<10>> = arrow_array
.try_into_collection()
.expect("Failed to convert from Arrow array");
assert_eq!(original, roundtrip);
}

0 comments on commit 3b329b7

Please sign in to comment.