Skip to content

Commit 46d1612

Browse files
authored
feat: use force_validate feature flag when creating an arrays (#7241)
1 parent 32bd9a5 commit 46d1612

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

arrow-array/src/array/byte_array.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ impl<T: ByteArrayType> GenericByteArray<T> {
164164
values: Buffer,
165165
nulls: Option<NullBuffer>,
166166
) -> Self {
167+
if cfg!(feature = "force_validate") {
168+
return Self::new(offsets, values, nulls);
169+
}
167170
Self {
168171
data_type: T::DATA_TYPE,
169172
value_offsets: offsets,

arrow-array/src/array/byte_view_array.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ impl<T: ByteViewType + ?Sized> GenericByteViewArray<T> {
232232
buffers: Vec<Buffer>,
233233
nulls: Option<NullBuffer>,
234234
) -> Self {
235+
if cfg!(feature = "force_validate") {
236+
return Self::new(views, buffers, nulls);
237+
}
238+
235239
Self {
236240
data_type: T::DATA_TYPE,
237241
phantom: Default::default(),

arrow-array/src/array/dictionary_array.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ impl<K: ArrowDictionaryKeyType> DictionaryArray<K> {
327327
///
328328
/// Safe provided [`Self::try_new`] would not return an error
329329
pub unsafe fn new_unchecked(keys: PrimitiveArray<K>, values: ArrayRef) -> Self {
330+
if cfg!(feature = "force_validate") {
331+
return Self::new(keys, values);
332+
}
333+
330334
let data_type = DataType::Dictionary(
331335
Box::new(keys.data_type().clone()),
332336
Box::new(values.data_type().clone()),

arrow-array/src/array/struct_array.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ impl StructArray {
189189
arrays: Vec<ArrayRef>,
190190
nulls: Option<NullBuffer>,
191191
) -> Self {
192+
if cfg!(feature = "force_validate") {
193+
return Self::new(fields, arrays, nulls);
194+
}
195+
192196
let len = arrays.first().map(|x| x.len()).unwrap_or_default();
193197
Self {
194198
len,

arrow-array/src/ffi.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,12 +1298,12 @@ mod tests_to_then_from_ffi {
12981298
mod tests_from_ffi {
12991299
use std::sync::Arc;
13001300

1301-
use arrow_buffer::{bit_util, buffer::Buffer, MutableBuffer, OffsetBuffer};
1301+
use arrow_buffer::{bit_util, buffer::Buffer};
13021302
use arrow_data::transform::MutableArrayData;
13031303
use arrow_data::ArrayData;
13041304
use arrow_schema::{DataType, Field};
13051305

1306-
use super::{ImportedArrowArray, Result};
1306+
use super::Result;
13071307
use crate::builder::GenericByteViewBuilder;
13081308
use crate::types::{BinaryViewType, ByteViewType, Int32Type, StringViewType};
13091309
use crate::{
@@ -1507,7 +1507,11 @@ mod tests_from_ffi {
15071507
}
15081508

15091509
#[test]
1510+
#[cfg(not(feature = "force_validate"))]
15101511
fn test_empty_string_with_non_zero_offset() -> Result<()> {
1512+
use super::ImportedArrowArray;
1513+
use arrow_buffer::{MutableBuffer, OffsetBuffer};
1514+
15111515
// Simulate an empty string array with a non-zero offset from a producer
15121516
let data: Buffer = MutableBuffer::new(0).into();
15131517
let offsets = OffsetBuffer::new(vec![123].into());

0 commit comments

Comments
 (0)