Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Move Container to json
Browse files Browse the repository at this point in the history
  • Loading branch information
AnIrishDuck committed Oct 27, 2022
1 parent 5ceee98 commit 757385a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 47 deletions.
10 changes: 1 addition & 9 deletions src/array/binary/mutable.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::{iter::FromIterator, sync::Arc};

use crate::{
array::{
specification::check_offsets, Array, Container, MutableArray, Offset, TryExtend, TryPush,
},
array::{specification::check_offsets, Array, MutableArray, Offset, TryExtend, TryPush},
bitmap::MutableBitmap,
datatypes::DataType,
error::{Error, Result},
Expand Down Expand Up @@ -188,12 +186,6 @@ impl<O: Offset> MutableBinaryArray<O> {
}
}

impl<O: Offset> Container for MutableBinaryArray<O> {
fn with_capacity(capacity: usize) -> Self {
MutableBinaryArray::with_capacity(capacity)
}
}

impl<O: Offset> MutableArray for MutableBinaryArray<O> {
fn len(&self) -> usize {
self.offsets.len() - 1
Expand Down
8 changes: 1 addition & 7 deletions src/array/boolean/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::iter::FromIterator;
use std::sync::Arc;

use crate::{
array::{Array, Container, MutableArray, TryExtend, TryPush},
array::{Array, MutableArray, TryExtend, TryPush},
bitmap::MutableBitmap,
datatypes::{DataType, PhysicalType},
error::Result,
Expand Down Expand Up @@ -453,12 +453,6 @@ impl<Ptr: std::borrow::Borrow<Option<bool>>> FromIterator<Ptr> for MutableBoolea
}
}

impl Container for MutableBooleanArray {
fn with_capacity(capacity: usize) -> Self {
MutableBooleanArray::with_capacity(capacity)
}
}

impl MutableArray for MutableBooleanArray {
fn len(&self) -> usize {
self.values.len()
Expand Down
8 changes: 1 addition & 7 deletions src/array/fixed_size_binary/mutable.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use crate::{
array::{Array, Container, MutableArray},
array::{Array, MutableArray},
bitmap::MutableBitmap,
datatypes::DataType,
error::{Error, Result},
Expand Down Expand Up @@ -211,12 +211,6 @@ impl MutableFixedSizeBinaryArray {
}
}

impl Container for MutableFixedSizeBinaryArray {
fn with_capacity(capacity: usize) -> Self {
MutableFixedSizeBinaryArray::with_capacity(capacity, 0)
}
}

impl MutableArray for MutableFixedSizeBinaryArray {
fn len(&self) -> usize {
self.values.len() / self.size
Expand Down
11 changes: 1 addition & 10 deletions src/array/list/mutable.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::sync::Arc;

use crate::{
array::{
specification::try_check_offsets, Array, Container, MutableArray, Offset, TryExtend,
TryPush,
},
array::{specification::try_check_offsets, Array, MutableArray, Offset, TryExtend, TryPush},
bitmap::MutableBitmap,
datatypes::{DataType, Field},
error::{Error, Result},
Expand Down Expand Up @@ -288,12 +285,6 @@ impl<O: Offset, M: MutableArray> MutableListArray<O, M> {
}
}

impl<O: Offset, M: MutableArray + Default + 'static> Container for MutableListArray<O, M> {
fn with_capacity(capacity: usize) -> Self {
MutableListArray::with_capacity(capacity)
}
}

impl<O: Offset, M: MutableArray + 'static> MutableArray for MutableListArray<O, M> {
fn len(&self) -> usize {
MutableListArray::len(self)
Expand Down
8 changes: 1 addition & 7 deletions src/array/primitive/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{iter::FromIterator, sync::Arc};

use crate::bitmap::Bitmap;
use crate::{
array::{Array, Container, MutableArray, TryExtend, TryPush},
array::{Array, MutableArray, TryExtend, TryPush},
bitmap::MutableBitmap,
datatypes::DataType,
error::{Error, Result},
Expand Down Expand Up @@ -378,12 +378,6 @@ impl<T: NativeType> TryPush<Option<T>> for MutablePrimitiveArray<T> {
}
}

impl<T: NativeType> Container for MutablePrimitiveArray<T> {
fn with_capacity(capacity: usize) -> Self {
MutablePrimitiveArray::with_capacity(capacity)
}
}

impl<T: NativeType> MutableArray for MutablePrimitiveArray<T> {
fn len(&self) -> usize {
self.values.len()
Expand Down
8 changes: 1 addition & 7 deletions src/array/utf8/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{iter::FromIterator, sync::Arc};

use crate::array::physical_binary::*;
use crate::{
array::{Array, Container, MutableArray, Offset, TryExtend, TryPush},
array::{Array, MutableArray, Offset, TryExtend, TryPush},
bitmap::{
utils::{BitmapIter, ZipValidity},
Bitmap, MutableBitmap,
Expand Down Expand Up @@ -247,12 +247,6 @@ impl<O: Offset> MutableUtf8Array<O> {
}
}

impl<O: Offset> Container for MutableUtf8Array<O> {
fn with_capacity(capacity: usize) -> Self {
MutableUtf8Array::with_capacity(capacity)
}
}

impl<O: Offset> MutableArray for MutableUtf8Array<O> {
fn len(&self) -> usize {
self.len()
Expand Down
45 changes: 45 additions & 0 deletions src/io/json/read/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,51 @@ where
Box::new(A::from(array))
}

/// A trait describing an array with a backing store that can be preallocated to
/// a given size.
pub(crate) trait Container {
/// Create this array with a given capacity.
fn with_capacity(capacity: usize) -> Self
where
Self: Sized;
}

impl<O: Offset> Container for MutableBinaryArray<O> {
fn with_capacity(capacity: usize) -> Self {
MutableBinaryArray::with_capacity(capacity)
}
}

impl Container for MutableBooleanArray {
fn with_capacity(capacity: usize) -> Self {
MutableBooleanArray::with_capacity(capacity)
}
}

impl Container for MutableFixedSizeBinaryArray {
fn with_capacity(capacity: usize) -> Self {
MutableFixedSizeBinaryArray::with_capacity(capacity, 0)
}
}

impl<O: Offset, M: MutableArray + Default + 'static> Container for MutableListArray<O, M> {
fn with_capacity(capacity: usize) -> Self {
MutableListArray::with_capacity(capacity)
}
}

impl<T: NativeType> Container for MutablePrimitiveArray<T> {
fn with_capacity(capacity: usize) -> Self {
MutablePrimitiveArray::with_capacity(capacity)
}
}

impl<O: Offset> Container for MutableUtf8Array<O> {
fn with_capacity(capacity: usize) -> Self {
MutableUtf8Array::with_capacity(capacity)
}
}

fn fill_generic_array_from<B, M, A>(f: fn(&mut M, &[B]), rows: &[B]) -> Box<dyn Array>
where
M: Container,
Expand Down

0 comments on commit 757385a

Please sign in to comment.