Skip to content

Commit

Permalink
Cleanup more uses of Array::data (apache#3880)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Apr 2, 2023
1 parent ecd44fd commit 2f38e6b
Show file tree
Hide file tree
Showing 30 changed files with 168 additions and 178 deletions.
4 changes: 2 additions & 2 deletions arrow-array/src/array/binary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ mod tests {
let data = vec![None];
let array = BinaryArray::from(data);
array
.data()
.into_data()
.validate_full()
.expect("All null array has valid array data");
}
Expand All @@ -693,7 +693,7 @@ mod tests {
let data = vec![None];
let array = LargeBinaryArray::from(data);
array
.data()
.into_data()
.validate_full()
.expect("All null array has valid array data");
}
Expand Down
8 changes: 4 additions & 4 deletions arrow-array/src/array/dictionary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@ impl<K: ArrowDictionaryKeyType> DictionaryArray<K> {

// Note: This use the ArrayDataBuilder::build_unchecked and afterwards
// call the new function which only validates that the keys are in bounds.
let data = keys.data().clone();
let data = keys.to_data();
let builder = data
.into_builder()
.data_type(dict_data_type)
.add_child_data(values.data().clone());
.add_child_data(values.to_data());

// Safety: `validate` ensures key type is correct, and
// `validate_values` ensures all offsets are within range
Expand Down Expand Up @@ -397,7 +397,7 @@ impl<K: ArrowDictionaryKeyType> DictionaryArray<K> {
Box::new(K::DATA_TYPE),
Box::new(values.data_type().clone()),
))
.child_data(vec![values.data().clone()]);
.child_data(vec![values.to_data()]);

// SAFETY:
// Offsets were valid before and verified length is greater than or equal
Expand Down Expand Up @@ -1076,7 +1076,7 @@ mod tests {
let boxed: ArrayRef = Arc::new(dict_array);

let col: DictionaryArray<Int8Type> =
DictionaryArray::<Int8Type>::from(boxed.data().clone());
DictionaryArray::<Int8Type>::from(boxed.to_data());
let err = col.into_primitive_dict_builder::<Int32Type>();

let returned = err.unwrap_err();
Expand Down
2 changes: 1 addition & 1 deletion arrow-array/src/array/map_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl MapArray {

let entry_struct = StructArray::from(vec![
(keys_field, Arc::new(keys_data) as ArrayRef),
(values_field, make_array(values.data().clone())),
(values_field, make_array(values.to_data())),
]);

let map_data_type = DataType::Map(
Expand Down
4 changes: 2 additions & 2 deletions arrow-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl Array for ArrayRef {
}

fn into_data(self) -> ArrayData {
self.data().clone()
self.to_data()
}

#[allow(deprecated)]
Expand Down Expand Up @@ -357,7 +357,7 @@ impl<'a, T: Array> Array for &'a T {
}

fn into_data(self) -> ArrayData {
self.data().clone()
self.to_data()
}

#[allow(deprecated)]
Expand Down
14 changes: 7 additions & 7 deletions arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ impl<T: DecimalType + ArrowPrimitiveType> PrimitiveArray<T> {
pub fn precision(&self) -> u8 {
match T::BYTE_LENGTH {
16 => {
if let DataType::Decimal128(p, _) = self.data().data_type() {
if let DataType::Decimal128(p, _) = self.data_type() {
*p
} else {
unreachable!(
Expand All @@ -1195,7 +1195,7 @@ impl<T: DecimalType + ArrowPrimitiveType> PrimitiveArray<T> {
}
}
32 => {
if let DataType::Decimal256(p, _) = self.data().data_type() {
if let DataType::Decimal256(p, _) = self.data_type() {
*p
} else {
unreachable!(
Expand All @@ -1212,7 +1212,7 @@ impl<T: DecimalType + ArrowPrimitiveType> PrimitiveArray<T> {
pub fn scale(&self) -> i8 {
match T::BYTE_LENGTH {
16 => {
if let DataType::Decimal128(_, s) = self.data().data_type() {
if let DataType::Decimal128(_, s) = self.data_type() {
*s
} else {
unreachable!(
Expand All @@ -1222,7 +1222,7 @@ impl<T: DecimalType + ArrowPrimitiveType> PrimitiveArray<T> {
}
}
32 => {
if let DataType::Decimal256(_, s) = self.data().data_type() {
if let DataType::Decimal256(_, s) = self.data_type() {
*s
} else {
unreachable!(
Expand Down Expand Up @@ -1874,7 +1874,7 @@ mod tests {
let array = PrimitiveArray::<Decimal128Type>::from(values.clone());
assert_eq!(array.values(), &values);

let array = PrimitiveArray::<Decimal128Type>::from(array.data().clone());
let array = PrimitiveArray::<Decimal128Type>::from(array.to_data());
assert_eq!(array.values(), &values);
}

Expand All @@ -1894,7 +1894,7 @@ mod tests {
let array = PrimitiveArray::<Decimal256Type>::from(values.clone());
assert_eq!(array.values(), &values);

let array = PrimitiveArray::<Decimal256Type>::from(array.data().clone());
let array = PrimitiveArray::<Decimal256Type>::from(array.to_data());
assert_eq!(array.values(), &values);
}

Expand Down Expand Up @@ -2190,7 +2190,7 @@ mod tests {

let boxed: ArrayRef = Arc::new(array);

let col: Int32Array = PrimitiveArray::<Int32Type>::from(boxed.data().clone());
let col: Int32Array = PrimitiveArray::<Int32Type>::from(boxed.to_data());
let err = col.into_builder();

match err {
Expand Down
4 changes: 2 additions & 2 deletions arrow-array/src/array/run_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ impl<R: RunEndIndexType> RunArray<R> {
let len = RunArray::logical_len(run_ends);
let builder = ArrayDataBuilder::new(ree_array_type)
.len(len)
.add_child_data(run_ends.data().clone())
.add_child_data(values.data().clone());
.add_child_data(run_ends.to_data())
.add_child_data(values.to_data());

// `build_unchecked` is used to avoid recursive validation of child arrays.
let array_data = unsafe { builder.build_unchecked() };
Expand Down
4 changes: 2 additions & 2 deletions arrow-array/src/array/string_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ mod tests {
let data: Vec<Option<&str>> = vec![None];
let array = StringArray::from(data);
array
.data()
.into_data()
.validate_full()
.expect("All null array has valid array data");
}
Expand All @@ -466,7 +466,7 @@ mod tests {
let data: Vec<Option<&str>> = vec![None];
let array = LargeStringArray::from(data);
array
.data()
.into_data()
.validate_full()
.expect("All null array has valid array data");
}
Expand Down
10 changes: 5 additions & 5 deletions arrow-array/src/builder/generic_list_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use crate::builder::null_buffer_builder::NullBufferBuilder;
use crate::builder::{ArrayBuilder, BufferBuilder};
use crate::{ArrayRef, GenericListArray, OffsetSizeTrait};
use crate::{Array, ArrayRef, GenericListArray, OffsetSizeTrait};
use arrow_buffer::Buffer;
use arrow_data::ArrayData;
use arrow_schema::Field;
Expand Down Expand Up @@ -228,7 +228,7 @@ where
pub fn finish(&mut self) -> GenericListArray<OffsetSize> {
let len = self.len();
let values_arr = self.values_builder.finish();
let values_data = values_arr.data();
let values_data = values_arr.to_data();

let offset_buffer = self.offsets_builder.finish();
let null_bit_buffer = self.null_buffer_builder.finish();
Expand All @@ -242,7 +242,7 @@ where
let array_data_builder = ArrayData::builder(data_type)
.len(len)
.add_buffer(offset_buffer)
.add_child_data(values_data.clone())
.add_child_data(values_data)
.null_bit_buffer(null_bit_buffer);

let array_data = unsafe { array_data_builder.build_unchecked() };
Expand All @@ -254,7 +254,7 @@ where
pub fn finish_cloned(&self) -> GenericListArray<OffsetSize> {
let len = self.len();
let values_arr = self.values_builder.finish_cloned();
let values_data = values_arr.data();
let values_data = values_arr.to_data();

let offset_buffer = Buffer::from_slice_ref(self.offsets_builder.as_slice());
let null_bit_buffer = self
Expand All @@ -270,7 +270,7 @@ where
let array_data_builder = ArrayData::builder(data_type)
.len(len)
.add_buffer(offset_buffer)
.add_child_data(values_data.clone())
.add_child_data(values_data)
.null_bit_buffer(null_bit_buffer);

let array_data = unsafe { array_data_builder.build_unchecked() };
Expand Down
4 changes: 2 additions & 2 deletions arrow-array/src/builder/struct_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl StructBuilder {
let mut child_data = Vec::with_capacity(self.field_builders.len());
for f in &mut self.field_builders {
let arr = f.finish();
child_data.push(arr.data().clone());
child_data.push(arr.to_data());
}
let length = self.len();
let null_bit_buffer = self.null_buffer_builder.finish();
Expand All @@ -254,7 +254,7 @@ impl StructBuilder {
let mut child_data = Vec::with_capacity(self.field_builders.len());
for f in &self.field_builders {
let arr = f.finish_cloned();
child_data.push(arr.data().clone());
child_data.push(arr.to_data());
}
let length = self.len();
let null_bit_buffer = self
Expand Down
8 changes: 4 additions & 4 deletions arrow-cast/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ pub fn cast_with_options(
let from_type = array.data_type();
// clone array if types are the same
if from_type == to_type {
return Ok(make_array(array.data().clone()));
return Ok(make_array(array.to_data()));
}
match (from_type, to_type) {
(
Expand Down Expand Up @@ -3108,7 +3108,7 @@ fn dictionary_cast<K: ArrowDictionaryKeyType>(
})?;

let keys_array: ArrayRef =
Arc::new(PrimitiveArray::<K>::from(dict_array.keys().data().clone()));
Arc::new(PrimitiveArray::<K>::from(dict_array.keys().to_data()));
let values_array = dict_array.values();
let cast_keys = cast_with_options(&keys_array, to_index_type, cast_options)?;
let cast_values =
Expand Down Expand Up @@ -3182,7 +3182,7 @@ where

// Note take requires first casting the indices to u32
let keys_array: ArrayRef =
Arc::new(PrimitiveArray::<K>::from(dict_array.keys().data().clone()));
Arc::new(PrimitiveArray::<K>::from(dict_array.keys().to_data()));
let indices = cast_with_options(&keys_array, &DataType::UInt32, cast_options)?;
let u32_indices =
indices
Expand Down Expand Up @@ -3379,7 +3379,7 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
to_type: &DataType,
cast_options: &CastOptions,
) -> Result<ArrayRef, ArrowError> {
let data = array.data().clone();
let data = array.to_data();
let underlying_array = make_array(data.child_data()[0].clone());
let cast_array =
cast_with_options(underlying_array.as_ref(), to.data_type(), cast_options)?;
Expand Down
2 changes: 1 addition & 1 deletion arrow-ord/src/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ where
{
// TODO: Use take_boolean (#2967)
let array = take(&dict_comparison, dict.keys(), None)?;
Ok(BooleanArray::from(array.data().clone()))
Ok(BooleanArray::from(array.to_data()))
}

/// Helper function to perform boolean lambda function on values from two arrays using
Expand Down
45 changes: 21 additions & 24 deletions arrow-ord/src/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

//! Contains functions and function factories to compare arrays.

use arrow_array::cast::AsArray;
use arrow_array::types::*;
use arrow_array::*;
use arrow_buffer::ArrowNativeType;
Expand All @@ -33,21 +34,21 @@ fn compare_primitives<T: ArrowPrimitiveType>(
where
T::Native: ArrowNativeTypeOp,
{
let left: PrimitiveArray<T> = PrimitiveArray::from(left.data().clone());
let right: PrimitiveArray<T> = PrimitiveArray::from(right.data().clone());
let left: PrimitiveArray<T> = PrimitiveArray::from(left.to_data());
let right: PrimitiveArray<T> = PrimitiveArray::from(right.to_data());
Box::new(move |i, j| left.value(i).compare(right.value(j)))
}

fn compare_boolean(left: &dyn Array, right: &dyn Array) -> DynComparator {
let left: BooleanArray = BooleanArray::from(left.data().clone());
let right: BooleanArray = BooleanArray::from(right.data().clone());
let left: BooleanArray = BooleanArray::from(left.to_data());
let right: BooleanArray = BooleanArray::from(right.to_data());

Box::new(move |i, j| left.value(i).cmp(&right.value(j)))
}

fn compare_string(left: &dyn Array, right: &dyn Array) -> DynComparator {
let left: StringArray = StringArray::from(left.data().clone());
let right: StringArray = StringArray::from(right.data().clone());
let left: StringArray = StringArray::from(left.to_data());
let right: StringArray = StringArray::from(right.to_data());

Box::new(move |i, j| left.value(i).cmp(right.value(j)))
}
Expand All @@ -58,15 +59,13 @@ where
V: ArrowPrimitiveType,
V::Native: ArrowNativeTypeOp,
{
let left = left.as_any().downcast_ref::<DictionaryArray<K>>().unwrap();
let right = right.as_any().downcast_ref::<DictionaryArray<K>>().unwrap();
let left = left.as_dictionary::<K>();
let right = right.as_dictionary::<K>();

let left_keys: PrimitiveArray<K> = PrimitiveArray::from(left.keys().data().clone());
let right_keys: PrimitiveArray<K> = PrimitiveArray::from(right.keys().data().clone());
let left_values: PrimitiveArray<V> =
PrimitiveArray::from(left.values().data().clone());
let right_values: PrimitiveArray<V> =
PrimitiveArray::from(right.values().data().clone());
let left_keys: PrimitiveArray<K> = PrimitiveArray::from(left.keys().to_data());
let right_keys: PrimitiveArray<K> = PrimitiveArray::from(right.keys().to_data());
let left_values: PrimitiveArray<V> = left.values().to_data().into();
let right_values: PrimitiveArray<V> = right.values().to_data().into();

Box::new(move |i: usize, j: usize| {
let key_left = left_keys.value(i).as_usize();
Expand All @@ -81,13 +80,13 @@ fn compare_dict_string<T>(left: &dyn Array, right: &dyn Array) -> DynComparator
where
T: ArrowDictionaryKeyType,
{
let left = left.as_any().downcast_ref::<DictionaryArray<T>>().unwrap();
let right = right.as_any().downcast_ref::<DictionaryArray<T>>().unwrap();
let left = left.as_dictionary::<T>();
let right = right.as_dictionary::<T>();

let left_keys: PrimitiveArray<T> = PrimitiveArray::from(left.keys().data().clone());
let right_keys: PrimitiveArray<T> = PrimitiveArray::from(right.keys().data().clone());
let left_values = StringArray::from(left.values().data().clone());
let right_values = StringArray::from(right.values().data().clone());
let left_keys: PrimitiveArray<T> = PrimitiveArray::from(left.keys().to_data());
let right_keys: PrimitiveArray<T> = PrimitiveArray::from(right.keys().to_data());
let left_values = StringArray::from(left.values().to_data());
let right_values = StringArray::from(right.values().to_data());

Box::new(move |i: usize, j: usize| {
let key_left = left_keys.value(i).as_usize();
Expand Down Expand Up @@ -264,10 +263,8 @@ pub fn build_compare(
}
}
(FixedSizeBinary(_), FixedSizeBinary(_)) => {
let left: FixedSizeBinaryArray =
FixedSizeBinaryArray::from(left.data().clone());
let right: FixedSizeBinaryArray =
FixedSizeBinaryArray::from(right.data().clone());
let left: FixedSizeBinaryArray = left.to_data().into();
let right: FixedSizeBinaryArray = right.to_data().into();

Box::new(move |i, j| left.value(i).cmp(right.value(j)))
}
Expand Down
2 changes: 1 addition & 1 deletion arrow-row/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,7 @@ mod tests {
.into_data()
.into_builder()
.data_type(data_type)
.add_child_data(values.data().clone())
.add_child_data(values.to_data())
.build()
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion arrow-row/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub unsafe fn decode<O: OffsetSizeTrait>(

let child = converter.convert_raw(&mut child_rows, validate_utf8)?;
assert_eq!(child.len(), 1);
let child_data = child[0].data().clone();
let child_data = child[0].to_data();

let builder = ArrayDataBuilder::new(field.data_type.clone())
.len(rows.len())
Expand Down
2 changes: 1 addition & 1 deletion arrow-select/src/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,7 @@ mod tests {
.downcast_ref::<DictionaryArray<Int16Type>>()
.unwrap();

let result_values: StringArray = result.values().data().clone().into();
let result_values: StringArray = result.values().to_data().into();

// dictionary values should stay the same
let expected_values = StringArray::from(vec!["foo", "bar", ""]);
Expand Down
Loading

0 comments on commit 2f38e6b

Please sign in to comment.