Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions rust/arrow/src/array/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use super::{ArrayData, ArrayDataRef};
mod boolean;
mod fixed_binary;
mod list;
mod null;
mod primitive;
mod structure;
mod utils;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(_) => {}
*/
Expand All @@ -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>,
Expand Down Expand Up @@ -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(_) => {}
*/
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
26 changes: 26 additions & 0 deletions rust/arrow/src/array/transform/null.rs
Original file line number Diff line number Diff line change
@@ -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) {}