This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 46d161270e feat: use `force_validate` feature flag when creating an 
arrays (#7241)
46d161270e is described below

commit 46d161270eacf4301b81abeee2333b3537f70e91
Author: Raz Luvaton <[email protected]>
AuthorDate: Sat Mar 8 11:35:43 2025 +0200

    feat: use `force_validate` feature flag when creating an arrays (#7241)
---
 arrow-array/src/array/byte_array.rs       | 3 +++
 arrow-array/src/array/byte_view_array.rs  | 4 ++++
 arrow-array/src/array/dictionary_array.rs | 4 ++++
 arrow-array/src/array/struct_array.rs     | 4 ++++
 arrow-array/src/ffi.rs                    | 8 ++++++--
 5 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/arrow-array/src/array/byte_array.rs 
b/arrow-array/src/array/byte_array.rs
index f2b2250708..b368f273cf 100644
--- a/arrow-array/src/array/byte_array.rs
+++ b/arrow-array/src/array/byte_array.rs
@@ -164,6 +164,9 @@ impl<T: ByteArrayType> GenericByteArray<T> {
         values: Buffer,
         nulls: Option<NullBuffer>,
     ) -> Self {
+        if cfg!(feature = "force_validate") {
+            return Self::new(offsets, values, nulls);
+        }
         Self {
             data_type: T::DATA_TYPE,
             value_offsets: offsets,
diff --git a/arrow-array/src/array/byte_view_array.rs 
b/arrow-array/src/array/byte_view_array.rs
index 8c78dec8e1..e837512ed0 100644
--- a/arrow-array/src/array/byte_view_array.rs
+++ b/arrow-array/src/array/byte_view_array.rs
@@ -232,6 +232,10 @@ impl<T: ByteViewType + ?Sized> GenericByteViewArray<T> {
         buffers: Vec<Buffer>,
         nulls: Option<NullBuffer>,
     ) -> Self {
+        if cfg!(feature = "force_validate") {
+            return Self::new(views, buffers, nulls);
+        }
+
         Self {
             data_type: T::DATA_TYPE,
             phantom: Default::default(),
diff --git a/arrow-array/src/array/dictionary_array.rs 
b/arrow-array/src/array/dictionary_array.rs
index f852b57fb6..38c4e01920 100644
--- a/arrow-array/src/array/dictionary_array.rs
+++ b/arrow-array/src/array/dictionary_array.rs
@@ -327,6 +327,10 @@ impl<K: ArrowDictionaryKeyType> DictionaryArray<K> {
     ///
     /// Safe provided [`Self::try_new`] would not return an error
     pub unsafe fn new_unchecked(keys: PrimitiveArray<K>, values: ArrayRef) -> 
Self {
+        if cfg!(feature = "force_validate") {
+            return Self::new(keys, values);
+        }
+
         let data_type = DataType::Dictionary(
             Box::new(keys.data_type().clone()),
             Box::new(values.data_type().clone()),
diff --git a/arrow-array/src/array/struct_array.rs 
b/arrow-array/src/array/struct_array.rs
index de6d9c699d..7ecee68335 100644
--- a/arrow-array/src/array/struct_array.rs
+++ b/arrow-array/src/array/struct_array.rs
@@ -189,6 +189,10 @@ impl StructArray {
         arrays: Vec<ArrayRef>,
         nulls: Option<NullBuffer>,
     ) -> Self {
+        if cfg!(feature = "force_validate") {
+            return Self::new(fields, arrays, nulls);
+        }
+
         let len = arrays.first().map(|x| x.len()).unwrap_or_default();
         Self {
             len,
diff --git a/arrow-array/src/ffi.rs b/arrow-array/src/ffi.rs
index 144f2a21af..ac28289e65 100644
--- a/arrow-array/src/ffi.rs
+++ b/arrow-array/src/ffi.rs
@@ -1298,12 +1298,12 @@ mod tests_to_then_from_ffi {
 mod tests_from_ffi {
     use std::sync::Arc;
 
-    use arrow_buffer::{bit_util, buffer::Buffer, MutableBuffer, OffsetBuffer};
+    use arrow_buffer::{bit_util, buffer::Buffer};
     use arrow_data::transform::MutableArrayData;
     use arrow_data::ArrayData;
     use arrow_schema::{DataType, Field};
 
-    use super::{ImportedArrowArray, Result};
+    use super::Result;
     use crate::builder::GenericByteViewBuilder;
     use crate::types::{BinaryViewType, ByteViewType, Int32Type, 
StringViewType};
     use crate::{
@@ -1507,7 +1507,11 @@ mod tests_from_ffi {
     }
 
     #[test]
+    #[cfg(not(feature = "force_validate"))]
     fn test_empty_string_with_non_zero_offset() -> Result<()> {
+        use super::ImportedArrowArray;
+        use arrow_buffer::{MutableBuffer, OffsetBuffer};
+
         // Simulate an empty string array with a non-zero offset from a 
producer
         let data: Buffer = MutableBuffer::new(0).into();
         let offsets = OffsetBuffer::new(vec![123].into());

Reply via email to