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

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new cc0ee5e  ARROW-10825: [Rust] Added support for NullArray to 
MutableArrayData
cc0ee5e is described below

commit cc0ee5efcf9f6a67bcc407a11e8553a0409275c1
Author: Jorge C. Leitao <[email protected]>
AuthorDate: Fri Jan 1 06:13:58 2021 -0500

    ARROW-10825: [Rust] Added support for NullArray to MutableArrayData
    
    Closes #8851 from jorgecarleitao/mutable_null
    
    Authored-by: Jorge C. Leitao <[email protected]>
    Signed-off-by: Andrew Lamb <[email protected]>
---
 rust/arrow/src/array/transform/mod.rs  | 28 ++++++++++++++++++++++++----
 rust/arrow/src/array/transform/null.rs | 26 ++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/rust/arrow/src/array/transform/mod.rs 
b/rust/arrow/src/array/transform/mod.rs
index c32c787..dee0248 100644
--- a/rust/arrow/src/array/transform/mod.rs
+++ b/rust/arrow/src/array/transform/mod.rs
@@ -24,6 +24,7 @@ use super::{ArrayData, ArrayDataRef};
 mod boolean;
 mod fixed_binary;
 mod list;
+mod null;
 mod primitive;
 mod structure;
 mod utils;
@@ -56,7 +57,7 @@ struct _MutableArrayData<'a> {
 impl<'a> _MutableArrayData<'a> {
     fn freeze(self, dictionary: Option<ArrayDataRef>) -> ArrayData {
         let buffers = match self.data_type {
-            DataType::Struct(_) => vec![],
+            DataType::Null | DataType::Struct(_) => vec![],
             DataType::Utf8
             | DataType::Binary
             | DataType::LargeUtf8
@@ -174,6 +175,7 @@ impl<'a> std::fmt::Debug for MutableArrayData<'a> {
 fn build_extend(array: &ArrayData) -> Extend {
     use crate::datatypes::*;
     match array.data_type() {
+        DataType::Null => null::build_extend(array),
         DataType::Boolean => boolean::build_extend(array),
         DataType::UInt8 => primitive::build_extend::<u8>(array),
         DataType::UInt16 => primitive::build_extend::<u16>(array),
@@ -218,7 +220,6 @@ fn build_extend(array: &ArrayData) -> Extend {
         DataType::FixedSizeBinary(_) => fixed_binary::build_extend(array),
         DataType::Float16 => unreachable!(),
         /*
-        DataType::Null => {}
         DataType::FixedSizeList(_, _) => {}
         DataType::Union(_) => {}
         */
@@ -229,6 +230,7 @@ fn build_extend(array: &ArrayData) -> Extend {
 fn build_extend_nulls(data_type: &DataType) -> ExtendNulls {
     use crate::datatypes::*;
     Box::new(match data_type {
+        DataType::Null => null::extend_nulls,
         DataType::Boolean => boolean::extend_nulls,
         DataType::UInt8 => primitive::extend_nulls::<u8>,
         DataType::UInt16 => primitive::extend_nulls::<u16>,
@@ -267,7 +269,6 @@ fn build_extend_nulls(data_type: &DataType) -> ExtendNulls {
         DataType::FixedSizeBinary(_) => fixed_binary::extend_nulls,
         DataType::Float16 => unreachable!(),
         /*
-        DataType::Null => {}
         DataType::FixedSizeList(_, _) => {}
         DataType::Union(_) => {}
         */
@@ -294,6 +295,7 @@ impl<'a> MutableArrayData<'a> {
 
         let empty_buffer = MutableBuffer::new(0);
         let [buffer1, buffer2] = match &data_type {
+            DataType::Null => [empty_buffer, MutableBuffer::new(0)],
             DataType::Boolean => {
                 let bytes = bit_util::ceil(capacity, 8);
                 let buffer = MutableBuffer::new(bytes).with_bitset(bytes, 
false);
@@ -542,7 +544,7 @@ mod tests {
         array::{
             Array, ArrayDataRef, ArrayRef, BooleanArray, DictionaryArray,
             FixedSizeBinaryArray, Int16Array, Int16Type, Int32Array, 
Int64Array,
-            Int64Builder, ListBuilder, PrimitiveBuilder, StringArray,
+            Int64Builder, ListBuilder, NullArray, PrimitiveBuilder, 
StringArray,
             StringDictionaryBuilder, StructArray, UInt8Array,
         },
         buffer::Buffer,
@@ -756,6 +758,24 @@ mod tests {
         assert_eq!(result, expected);
     }
 
+    #[test]
+    fn test_null() {
+        let array1 = NullArray::new(10).data();
+        let array2 = NullArray::new(5).data();
+        let arrays = vec![array1.as_ref(), array2.as_ref()];
+
+        let mut mutable = MutableArrayData::new(arrays, false, 0);
+
+        mutable.extend(0, 1, 3);
+        mutable.extend(1, 0, 1);
+
+        let result = mutable.freeze();
+        let result = NullArray::from(Arc::new(result));
+
+        let expected = NullArray::new(3);
+        assert_eq!(result, expected);
+    }
+
     fn create_dictionary_array(values: &[&str], keys: &[Option<&str>]) -> 
ArrayDataRef {
         let values = StringArray::from(values.to_vec());
         let mut builder = StringDictionaryBuilder::new_with_dictionary(
diff --git a/rust/arrow/src/array/transform/null.rs 
b/rust/arrow/src/array/transform/null.rs
new file mode 100644
index 0000000..e1335e1
--- /dev/null
+++ b/rust/arrow/src/array/transform/null.rs
@@ -0,0 +1,26 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::array::ArrayData;
+
+use super::{Extend, _MutableArrayData};
+
+pub(super) fn build_extend(_: &ArrayData) -> Extend {
+    Box::new(move |_, _, _, _| {})
+}
+
+pub(super) fn extend_nulls(_: &mut _MutableArrayData, _: usize) {}

Reply via email to