Skip to content

Commit

Permalink
Split up arrow::array::builder module (apache#1843)
Browse files Browse the repository at this point in the history
- Removed old builder.rs
- Added missing licensing header to builder submodules
- Updated builder submodule imports and exports
- Updated array mod file builder imports and exports
  • Loading branch information
DaltonModlin committed Jun 16, 2022
1 parent 5686dad commit c7c6cb7
Show file tree
Hide file tree
Showing 15 changed files with 372 additions and 4,056 deletions.
3,914 changes: 0 additions & 3,914 deletions arrow/src/array/builder.rs

This file was deleted.

27 changes: 19 additions & 8 deletions arrow/src/array/builder/boolean_buffer_builder.rs
@@ -1,8 +1,25 @@
use crate::util::bit_util;
// 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::buffer::{Buffer, MutableBuffer};

use crate::array::builder::Range;
use super::Range;

use crate::util::bit_util;

#[derive(Debug)]
pub struct BooleanBufferBuilder {
Expand Down Expand Up @@ -155,12 +172,6 @@ impl From<BooleanBufferBuilder> for Buffer {
mod tests {
use super::*;

// use crate::array::array::Array;
// use crate::array::builder::ArrayBuilder;
use crate::array::Int32BufferBuilder;
use crate::array::Int8Builder;
use crate::array::UInt8BufferBuilder;

#[test]
fn test_boolean_buffer_builder_write_bytes() {
let mut b = BooleanBufferBuilder::new(4);
Expand Down
36 changes: 23 additions & 13 deletions arrow/src/array/builder/boolean_builder.rs
@@ -1,16 +1,31 @@
// 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 std::any::Any;
use std::sync::Arc;

use crate::datatypes::*;

use crate::array::ArrayBuilder;
use crate::array::ArrayData;
use crate::array::ArrayRef;
use crate::array::BooleanArray;
use crate::datatypes::DataType;
use crate::error::{ArrowError, Result};

pub use crate::array::ArrayBuilder;
pub use crate::array::ArrayData;
pub use crate::array::ArrayRef;
pub use crate::array::BooleanArray;

pub use crate::array::builder::boolean_buffer_builder::BooleanBufferBuilder;
use super::BooleanBufferBuilder;

/// Array builder for fixed-width primitive types
///
Expand Down Expand Up @@ -160,11 +175,6 @@ impl ArrayBuilder for BooleanBuilder {
mod tests {
use super::*;

use crate::array::Array;
use crate::bitmap::Bitmap;
use crate::buffer::Buffer;
use crate::error::Result;

#[test]
fn test_boolean_array_builder_append_slice() {
let arr1 =
Expand Down
23 changes: 19 additions & 4 deletions arrow/src/array/builder/buffer_builder.rs
@@ -1,9 +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 std::mem;

use crate::array::builder::PhantomData;
use crate::buffer::{Buffer, MutableBuffer};
use crate::datatypes::ArrowNativeType;

use crate::buffer::{Buffer, MutableBuffer};
use super::PhantomData;

/// Converts a `MutableBuffer` to a `BufferBuilder<T>`.
///
Expand Down Expand Up @@ -274,8 +291,6 @@ impl<T: ArrowNativeType> BufferBuilder<T> {

#[cfg(test)]
mod tests {
use super::*;

use crate::array::array::Array;
use crate::array::builder::ArrayBuilder;
use crate::array::Int32BufferBuilder;
Expand Down
67 changes: 56 additions & 11 deletions arrow/src/array/builder/decimal_builder.rs
@@ -1,11 +1,37 @@
// 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 std::any::Any;
use std::sync::Arc;

use crate::array::*;
use crate::datatypes::*;
use crate::array::ArrayBuilder;
use crate::array::ArrayRef;
use crate::array::DecimalArray;
use crate::array::FixedSizeBinaryArray;
use crate::array::OffsetSizeTrait;
use crate::array::UInt8Builder;
use crate::array::{GenericBinaryArray, GenericStringArray};

use crate::error::{ArrowError, Result};

pub use crate::array::builder::GenericBinaryBuilder;
use super::{FixedSizeBinaryBuilder, FixedSizeListBuilder};
use super::{GenericBinaryBuilder, GenericListBuilder, GenericStringBuilder};

use crate::datatypes::validate_decimal_precision;

/// Array Builder for [`DecimalArray`]
///
Expand Down Expand Up @@ -329,11 +355,11 @@ impl DecimalBuilder {
/// Automatically calls the `append` method to delimit the slice appended in as a
/// distinct array element.
#[inline]
pub fn append_value(&mut self, value: i128) -> Result<()> {
pub fn append_value(&mut self, value: impl Into<i128>) -> Result<()> {
let value = if self.value_validation {
validate_decimal_precision(value, self.precision)?
validate_decimal_precision(value.into(), self.precision)?
} else {
value
value.into()
};

let value_as_bytes = Self::from_i128_to_fixed_size_bytes(
Expand Down Expand Up @@ -385,17 +411,36 @@ mod tests {
use super::*;

use crate::array::Array;
use crate::bitmap::Bitmap;
use crate::buffer::Buffer;
use crate::error::Result;
use crate::datatypes::DataType;
use crate::util::decimal::Decimal128;

#[test]
fn test_decimal_builder() {
let mut builder = DecimalBuilder::new(30, 38, 6);

builder.append_value(8_887_000_000).unwrap();
builder.append_value(8_887_000_000_i128).unwrap();
builder.append_null().unwrap();
builder.append_value(-8_887_000_000_i128).unwrap();
let decimal_array: DecimalArray = builder.finish();

assert_eq!(&DataType::Decimal(38, 6), decimal_array.data_type());
assert_eq!(3, decimal_array.len());
assert_eq!(1, decimal_array.null_count());
assert_eq!(32, decimal_array.value_offset(2));
assert_eq!(16, decimal_array.value_length());
}

#[test]
fn test_decimal_builder_with_decimal128() {
let mut builder = DecimalBuilder::new(30, 38, 6);

builder
.append_value(Decimal128::new_from_i128(30, 38, 8_887_000_000_i128))
.unwrap();
builder.append_null().unwrap();
builder.append_value(-8_887_000_000).unwrap();
builder
.append_value(Decimal128::new_from_i128(30, 38, -8_887_000_000_i128))
.unwrap();
let decimal_array: DecimalArray = builder.finish();

assert_eq!(&DataType::Decimal(38, 6), decimal_array.data_type());
Expand Down
43 changes: 27 additions & 16 deletions arrow/src/array/builder/fixed_size_list_builder.rs
@@ -1,18 +1,33 @@
// 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 std::any::Any;
use std::sync::Arc;

use crate::datatypes::*;
use crate::array::ArrayData;
use crate::array::ArrayRef;
use crate::array::FixedSizeListArray;
use crate::array::Int32BufferBuilder;
use crate::datatypes::DataType;
use crate::datatypes::Field;
use crate::error::Result;

pub use crate::array::builder::BooleanBufferBuilder;
pub use crate::array::builder::BufferBuilder;
pub use crate::array::ArrayBuilder;
pub use crate::array::ArrayData;
pub use crate::array::ArrayRef;
pub use crate::array::FixedSizeListArray;
pub use crate::array::OffsetSizeTrait;

pub use crate::array::Int32BufferBuilder;
use super::ArrayBuilder;
use super::BooleanBufferBuilder;

/// Array builder for `ListArray`
#[derive(Debug)]
Expand Down Expand Up @@ -147,12 +162,8 @@ mod tests {
use super::*;

use crate::array::Array;
use crate::bitmap::Bitmap;
use crate::buffer::Buffer;
use crate::error::Result;

use crate::array::builder::FixedSizeBinaryArray;
use crate::array::builder::FixedSizeBinaryBuilder;
use crate::array::FixedSizeBinaryArray;
use crate::array::FixedSizeBinaryBuilder;
use crate::array::Int32Array;
use crate::array::Int32Builder;

Expand Down
43 changes: 28 additions & 15 deletions arrow/src/array/builder/generic_list_builder.rs
@@ -1,17 +1,32 @@
// 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 std::any::Any;
use std::sync::Arc;

use crate::datatypes::*;
use crate::array::ArrayData;
use crate::array::ArrayRef;
use crate::array::GenericListArray;
use crate::array::OffsetSizeTrait;
use crate::datatypes::DataType;
use crate::datatypes::Field;
use crate::error::Result;

pub use crate::array::builder::BooleanBufferBuilder;
pub use crate::array::builder::BufferBuilder;
pub use crate::array::ArrayBuilder;
pub use crate::array::ArrayData;
pub use crate::array::ArrayRef;
pub use crate::array::GenericListArray;
pub use crate::array::OffsetSizeTrait;
pub use crate::array::UInt8Builder;
use super::{ArrayBuilder, BooleanBufferBuilder, BufferBuilder};

/// Array builder for `ListArray`
#[derive(Debug)]
Expand Down Expand Up @@ -144,14 +159,12 @@ mod tests {
use super::*;

use crate::array::Array;
use crate::array::{Int32Array, Int32Builder};
use crate::bitmap::Bitmap;
use crate::array::Int32Array;
use crate::array::Int32Builder;
use crate::buffer::Buffer;
use crate::error::Result;

pub use crate::array::builder::{
BinaryBuilder, GenericStringBuilder, LargeBinaryBuilder, LargeListBuilder,
LargeStringBuilder, ListBuilder, StringBuilder,
use crate::array::builder::{
BinaryBuilder, LargeBinaryBuilder, LargeListBuilder, ListBuilder, StringBuilder,
};

#[test]
Expand Down
32 changes: 28 additions & 4 deletions arrow/src/array/builder/map_builder.rs
@@ -1,10 +1,34 @@
// 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 std::any::Any;
use std::sync::Arc;

use crate::array::*;
use crate::datatypes::*;
use crate::array::array::Array;
use crate::array::ArrayData;
use crate::array::ArrayRef;
use crate::array::MapArray;
use crate::array::StructArray;
use crate::datatypes::DataType;
use crate::datatypes::Field;
use crate::error::{ArrowError, Result};

use super::{ArrayBuilder, BooleanBufferBuilder, BufferBuilder};

#[derive(Debug)]
pub struct MapBuilder<K: ArrayBuilder, V: ArrayBuilder> {
offsets_builder: BufferBuilder<i32>,
Expand Down Expand Up @@ -168,10 +192,10 @@ impl<K: ArrayBuilder, V: ArrayBuilder> ArrayBuilder for MapBuilder<K, V> {
mod tests {
use super::*;

use crate::array::Array;
use crate::array::builder::StringBuilder;
use crate::array::Int32Builder;
use crate::bitmap::Bitmap;
use crate::buffer::Buffer;
use crate::error::Result;

// TODO: add a test that finishes building, after designing a spec-compliant
// way of inserting values to the map.
Expand Down

0 comments on commit c7c6cb7

Please sign in to comment.