From e0a527b25464d2c0fd7ada439632898fa305ae48 Mon Sep 17 00:00:00 2001 From: Yijie Shen Date: Sat, 7 May 2022 02:48:35 +0800 Subject: [PATCH] Add `DecimalType` support in `new_null_array ` (#1659) * minor: creation of all null decimal array * fmt --- arrow/src/array/array.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/arrow/src/array/array.rs b/arrow/src/array/array.rs index 1ad01f4f0d4b..421e60f04ac5 100644 --- a/arrow/src/array/array.rs +++ b/arrow/src/array/array.rs @@ -554,9 +554,7 @@ pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef { ) }) } - DataType::Decimal(_, _) => { - unimplemented!("Creating null Decimal array not yet supported") - } + DataType::Decimal(_, _) => new_null_sized_decimal(data_type, length), } } @@ -620,6 +618,24 @@ fn new_null_sized_array( }) } +#[inline] +fn new_null_sized_decimal(data_type: &DataType, length: usize) -> ArrayRef { + make_array(unsafe { + ArrayData::new_unchecked( + data_type.clone(), + length, + Some(length), + Some(MutableBuffer::new_null(length).into()), + 0, + vec![Buffer::from(vec![ + 0u8; + length * std::mem::size_of::() + ])], + vec![], + ) + }) +} + /// Creates a new array from two FFI pointers. Used to import arrays from the C Data Interface /// # Safety /// Assumes that these pointers represent valid C Data Interfaces, both in memory