From e0845991f240b981c841a8e23c741e2815fbd34d Mon Sep 17 00:00:00 2001 From: Thomas Tanon Date: Tue, 21 Jul 2026 09:56:11 +0200 Subject: [PATCH 1/4] create_array! Drop (Large)Binary special case and support BinaryView The three types support `From>` and `From>>`, making the default macro code paths working --- arrow-array/src/record_batch.rs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/arrow-array/src/record_batch.rs b/arrow-array/src/record_batch.rs index e05450a97f7f..6c6817e51eb1 100644 --- a/arrow-array/src/record_batch.rs +++ b/arrow-array/src/record_batch.rs @@ -115,7 +115,9 @@ macro_rules! create_array { (@from TimestampMillisecond) => { $crate::TimestampMillisecondArray }; (@from TimestampMicrosecond) => { $crate::TimestampMicrosecondArray }; (@from TimestampNanosecond) => { $crate::TimestampNanosecondArray }; - + (@from Binary) => { $crate::BinaryArray }; + (@from BinaryView) => { $crate::BinaryViewArray }; + (@from LargeBinary) => { $crate::LargeBinaryArray }; (@from $ty: ident) => { compile_error!(concat!("Unsupported data type: ", stringify!($ty))) }; @@ -124,26 +126,10 @@ macro_rules! create_array { std::sync::Arc::new($crate::NullArray::new($size)) }; - (Binary, [$($values: expr),*]) => { - std::sync::Arc::new($crate::BinaryArray::from_vec(vec![$($values),*])) - }; - - (LargeBinary, [$($values: expr),*]) => { - std::sync::Arc::new($crate::LargeBinaryArray::from_vec(vec![$($values),*])) - }; - ($ty: tt, [$($values: expr),*]) => { std::sync::Arc::new(<$crate::create_array!(@from $ty)>::from(vec![$($values),*])) }; - (Binary, $values: expr) => { - std::sync::Arc::new($crate::BinaryArray::from_vec($values)) - }; - - (LargeBinary, $values: expr) => { - std::sync::Arc::new($crate::LargeBinaryArray::from_vec($values)) - }; - ($ty: tt, $values: expr) => { std::sync::Arc::new(<$crate::create_array!(@from $ty)>::from($values)) }; From 21196ef3c4df00cbce67bf478454a8526c417919 Mon Sep 17 00:00:00 2001 From: Thomas Tanon Date: Tue, 21 Jul 2026 15:44:08 +0200 Subject: [PATCH 2/4] Add extra From implementations to BinaryArray and BinaryViewArray on [u8; _] --- arrow-arith/src/aggregate.rs | 2 +- arrow-array/src/array/binary_array.rs | 30 +++++++++++++++++++++--- arrow-array/src/array/byte_view_array.rs | 24 +++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/arrow-arith/src/aggregate.rs b/arrow-arith/src/aggregate.rs index 2e5713dd7d06..787327f3ae11 100644 --- a/arrow-arith/src/aggregate.rs +++ b/arrow-arith/src/aggregate.rs @@ -1580,7 +1580,7 @@ mod tests { Some("c".as_bytes()) ); - test_binary!(test_binary_min_max_all_nulls, vec![None, None], None, None); + test_binary!(test_binary_min_max_all_nulls, vec![None::<&[u8]>, None], None, None); test_binary!( test_binary_min_max_1, diff --git a/arrow-array/src/array/binary_array.rs b/arrow-array/src/array/binary_array.rs index b1fbd5729ad7..7f45bedd9342 100644 --- a/arrow-array/src/array/binary_array.rs +++ b/arrow-array/src/array/binary_array.rs @@ -96,7 +96,19 @@ impl GenericBinaryArray { impl From>> for GenericBinaryArray { fn from(v: Vec>) -> Self { - Self::from_opt_vec(v) + v.into_iter().collect() + } +} + +impl From>> for GenericBinaryArray { + fn from(v: Vec>) -> Self { + v.into_iter().collect() + } +} + +impl From>> for GenericBinaryArray { + fn from(v: Vec>) -> Self { + v.into_iter().collect() } } @@ -106,6 +118,18 @@ impl From> for GenericBinaryArray From> for GenericBinaryArray { + fn from(v: Vec<[u8; C]>) -> Self { + Self::from_iter_values(v) + } +} + +impl From> for GenericBinaryArray { + fn from(v: Vec<&[u8; C]>) -> Self { + Self::from_iter_values(v) + } +} + impl From> for GenericBinaryArray { fn from(v: GenericListArray) -> Self { Self::from_list(v) @@ -575,7 +599,7 @@ mod tests { #[test] fn test_binary_array_all_null() { - let data = vec![None]; + let data = vec![None::<&[u8]>]; let array = BinaryArray::from(data); array .into_data() @@ -585,7 +609,7 @@ mod tests { #[test] fn test_large_binary_array_all_null() { - let data = vec![None]; + let data = vec![None::<&[u8]>]; let array = LargeBinaryArray::from(data); array .into_data() diff --git a/arrow-array/src/array/byte_view_array.rs b/arrow-array/src/array/byte_view_array.rs index 58b5ce7a0569..dd95dc5a993f 100644 --- a/arrow-array/src/array/byte_view_array.rs +++ b/arrow-array/src/array/byte_view_array.rs @@ -1140,12 +1140,36 @@ impl From> for BinaryViewArray { } } +impl From> for BinaryViewArray { + fn from(v: Vec<[u8; C]>) -> Self { + Self::from_iter_values(v) + } +} + +impl From> for BinaryViewArray { + fn from(v: Vec<&[u8; C]>) -> Self { + Self::from_iter_values(v) + } +} + impl From>> for BinaryViewArray { fn from(v: Vec>) -> Self { v.into_iter().collect() } } +impl From>> for BinaryViewArray { + fn from(v: Vec>) -> Self { + v.into_iter().collect() + } +} + +impl From>> for BinaryViewArray { + fn from(v: Vec>) -> Self { + v.into_iter().collect() + } +} + /// A [`GenericByteViewArray`] that stores utf8 data /// /// See [`GenericByteViewArray`] for format and layout details. From 9bda563f87cc5ebfa8e183cab25e3ee96acf0e18 Mon Sep 17 00:00:00 2001 From: Thomas Tanon Date: Tue, 21 Jul 2026 15:52:03 +0200 Subject: [PATCH 3/4] Fix formatting --- arrow-arith/src/aggregate.rs | 7 ++++++- arrow-array/src/array/binary_array.rs | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/arrow-arith/src/aggregate.rs b/arrow-arith/src/aggregate.rs index 787327f3ae11..b09dd96a00fd 100644 --- a/arrow-arith/src/aggregate.rs +++ b/arrow-arith/src/aggregate.rs @@ -1580,7 +1580,12 @@ mod tests { Some("c".as_bytes()) ); - test_binary!(test_binary_min_max_all_nulls, vec![None::<&[u8]>, None], None, None); + test_binary!( + test_binary_min_max_all_nulls, + vec![None::<&[u8]>, None], + None, + None + ); test_binary!( test_binary_min_max_1, diff --git a/arrow-array/src/array/binary_array.rs b/arrow-array/src/array/binary_array.rs index 7f45bedd9342..72b2ed027520 100644 --- a/arrow-array/src/array/binary_array.rs +++ b/arrow-array/src/array/binary_array.rs @@ -100,13 +100,17 @@ impl From>> for GenericBinaryArra } } -impl From>> for GenericBinaryArray { +impl From>> + for GenericBinaryArray +{ fn from(v: Vec>) -> Self { v.into_iter().collect() } } -impl From>> for GenericBinaryArray { +impl From>> + for GenericBinaryArray +{ fn from(v: Vec>) -> Self { v.into_iter().collect() } @@ -118,13 +122,17 @@ impl From> for GenericBinaryArray From> for GenericBinaryArray { +impl From> + for GenericBinaryArray +{ fn from(v: Vec<[u8; C]>) -> Self { Self::from_iter_values(v) } } -impl From> for GenericBinaryArray { +impl From> + for GenericBinaryArray +{ fn from(v: Vec<&[u8; C]>) -> Self { Self::from_iter_values(v) } From 3543db306471e626bdf3e50ef04c446cf324d87d Mon Sep 17 00:00:00 2001 From: Thomas Tanon Date: Fri, 24 Jul 2026 10:24:23 +0200 Subject: [PATCH 4/4] Add From> and From>>> --- arrow-array/src/array/binary_array.rs | 12 ++++++++++++ arrow-array/src/array/byte_view_array.rs | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/arrow-array/src/array/binary_array.rs b/arrow-array/src/array/binary_array.rs index 72b2ed027520..349ae652bfb9 100644 --- a/arrow-array/src/array/binary_array.rs +++ b/arrow-array/src/array/binary_array.rs @@ -116,6 +116,12 @@ impl From>> } } +impl From>>> for GenericBinaryArray { + fn from(v: Vec>>) -> Self { + v.into_iter().collect() + } +} + impl From> for GenericBinaryArray { fn from(v: Vec<&[u8]>) -> Self { Self::from_iter_values(v) @@ -138,6 +144,12 @@ impl From> } } +impl From>> for GenericBinaryArray { + fn from(v: Vec>) -> Self { + Self::from_iter_values(v) + } +} + impl From> for GenericBinaryArray { fn from(v: GenericListArray) -> Self { Self::from_list(v) diff --git a/arrow-array/src/array/byte_view_array.rs b/arrow-array/src/array/byte_view_array.rs index dd95dc5a993f..3369d2833277 100644 --- a/arrow-array/src/array/byte_view_array.rs +++ b/arrow-array/src/array/byte_view_array.rs @@ -1152,6 +1152,12 @@ impl From> for BinaryViewArray { } } +impl From>> for BinaryViewArray { + fn from(v: Vec>) -> Self { + Self::from_iter_values(v) + } +} + impl From>> for BinaryViewArray { fn from(v: Vec>) -> Self { v.into_iter().collect() @@ -1170,6 +1176,12 @@ impl From>> for BinaryViewArray { } } +impl From>>> for BinaryViewArray { + fn from(v: Vec>>) -> Self { + v.into_iter().collect() + } +} + /// A [`GenericByteViewArray`] that stores utf8 data /// /// See [`GenericByteViewArray`] for format and layout details.