Skip to content

Commit

Permalink
feat: use force_validate feature flag when creating an arrays (#7241)
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton authored Mar 8, 2025
1 parent 32bd9a5 commit 46d1612
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions arrow-array/src/array/byte_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions arrow-array/src/array/byte_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions arrow-array/src/array/dictionary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
4 changes: 4 additions & 0 deletions arrow-array/src/array/struct_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions arrow-array/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 46d1612

Please sign in to comment.