Skip to content

Commit 22552b3

Browse files
authored
Remove TypedArray, make InnerArrayData non-pub (#1378)
Also, converts `.clone().into_array()` -> `.to_array()` and removes From impl with hidden clone. FLUP: look at all the `SomeArray::try_from(xxx.clone())` !!! To remove in #1377
1 parent 383e97a commit 22552b3

File tree

58 files changed

+310
-431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+310
-431
lines changed

bench-vortex/benches/compress_noci.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn parquet_decompress_read(buf: bytes::Bytes) -> usize {
104104
}
105105

106106
fn parquet_compressed_written_size(array: &ArrayData, compression: Compression) -> usize {
107-
let chunked = ChunkedArray::try_from(array).unwrap();
107+
let chunked = ChunkedArray::try_from(array.clone()).unwrap();
108108
let (batches, schema) = chunked_to_vec_record_batch(chunked);
109109
parquet_compress_write(batches, schema, compression, &mut Vec::new())
110110
}
@@ -216,7 +216,7 @@ fn benchmark_compress<F, U>(
216216
measurement_time.map(|t| group.measurement_time(t));
217217

218218
group.bench_function(bench_name, |b| {
219-
let chunked = ChunkedArray::try_from(uncompressed.as_ref()).unwrap();
219+
let chunked = ChunkedArray::try_from(uncompressed.as_ref().clone()).unwrap();
220220
let (batches, schema) = chunked_to_vec_record_batch(chunked);
221221

222222
b.iter_with_large_drop(|| {
@@ -258,7 +258,7 @@ fn benchmark_compress<F, U>(
258258
measurement_time.map(|t| group.measurement_time(t));
259259

260260
let buffer = LazyCell::new(|| {
261-
let chunked = ChunkedArray::try_from(uncompressed.as_ref()).unwrap();
261+
let chunked = ChunkedArray::try_from(uncompressed.as_ref().clone()).unwrap();
262262
let (batches, schema) = chunked_to_vec_record_batch(chunked);
263263
let mut buf = Vec::new();
264264
parquet_compress_write(

bench-vortex/benches/compressor_throughput.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use vortex::sampling_compressor::compressors::CompressorRef;
2828
use vortex::sampling_compressor::SamplingCompressor;
2929
use vortex::scalar::Scalar;
3030
use vortex::validity::Validity;
31-
use vortex::{IntoArrayData as _, IntoCanonical};
31+
use vortex::{IntoArrayData as _, IntoCanonical, ToArrayData};
3232

3333
#[global_allocator]
3434
static GLOBAL: MiMalloc = MiMalloc;
@@ -118,19 +118,17 @@ fn strings(c: &mut Criterion) {
118118

119119
let varbinview_arr = VarBinViewArray::from_iter_str(gen_varbin_words(1_000_000, 0.00005));
120120
let (codes, values) = dict_encode_varbinview(&varbinview_arr);
121-
group.throughput(Throughput::Bytes(
122-
varbinview_arr.clone().into_array().nbytes() as u64,
123-
));
121+
group.throughput(Throughput::Bytes(varbinview_arr.to_array().nbytes() as u64));
124122
group.bench_function("dict_decode_varbinview", |b| {
125123
b.iter_batched(
126-
|| DictArray::try_new(codes.clone().into_array(), values.clone().into_array()).unwrap(),
124+
|| DictArray::try_new(codes.to_array(), values.to_array()).unwrap(),
127125
|dict_arr| black_box(dict_arr.into_canonical().unwrap()),
128126
BatchSize::SmallInput,
129127
);
130128
});
131129

132-
let fsst_compressor = fsst_train_compressor(&varbinview_arr.clone().into_array()).unwrap();
133-
let fsst_array = fsst_compress(&varbinview_arr.clone().into_array(), &fsst_compressor).unwrap();
130+
let fsst_compressor = fsst_train_compressor(&varbinview_arr.to_array()).unwrap();
131+
let fsst_array = fsst_compress(&varbinview_arr.to_array(), &fsst_compressor).unwrap();
134132
group.bench_function("fsst_decompress_varbinview", |b| {
135133
b.iter_batched(
136134
|| fsst_array.clone(),

encodings/alp/src/alp/compress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn patch_decoded(array: PrimitiveArray, patches: &ArrayData) -> VortexResult<Pri
8282
match patches.encoding().id() {
8383
Sparse::ID => {
8484
match_each_alp_float_ptype!(array.ptype(), |$T| {
85-
let typed_patches = SparseArray::try_from(patches).unwrap();
85+
let typed_patches = SparseArray::try_from(patches.clone()).unwrap();
8686
let primitive_values = typed_patches.values().into_primitive()?;
8787
array.patch(
8888
&typed_patches.resolved_indices(),

encodings/bytebool/src/array.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::fmt::{Debug, Display};
22
use std::mem::ManuallyDrop;
3+
use std::sync::Arc;
34

45
use arrow_buffer::BooleanBuffer;
56
use serde::{Deserialize, Serialize};
@@ -9,9 +10,7 @@ use vortex_array::encoding::ids;
910
use vortex_array::stats::StatsSet;
1011
use vortex_array::validity::{ArrayValidity, LogicalValidity, Validity, ValidityMetadata};
1112
use vortex_array::variants::{ArrayVariants, BoolArrayTrait};
12-
use vortex_array::{
13-
impl_encoding, ArrayData, ArrayTrait, Canonical, IntoArrayData, IntoCanonical, TypedArray,
14-
};
13+
use vortex_array::{impl_encoding, ArrayData, ArrayTrait, Canonical, IntoArrayData, IntoCanonical};
1514
use vortex_buffer::Buffer;
1615
use vortex_dtype::DType;
1716
use vortex_error::{VortexExpect as _, VortexResult};
@@ -41,18 +40,18 @@ impl ByteBoolArray {
4140
pub fn try_new(buffer: Buffer, validity: Validity) -> VortexResult<Self> {
4241
let length = buffer.len();
4342

44-
let typed = TypedArray::try_from_parts(
43+
ArrayData::try_new_owned(
44+
&ByteBoolEncoding,
4545
DType::Bool(validity.nullability()),
4646
length,
47-
ByteBoolMetadata {
47+
Arc::new(ByteBoolMetadata {
4848
validity: validity.to_metadata(length)?,
49-
},
49+
}),
5050
Some(buffer),
5151
validity.into_array().into_iter().collect::<Vec<_>>().into(),
5252
StatsSet::default(),
53-
)?;
54-
55-
Ok(typed.into())
53+
)?
54+
.try_into()
5655
}
5756

5857
pub fn try_from_vec<V: Into<Validity>>(data: Vec<bool>, validity: V) -> VortexResult<Self> {

encodings/bytebool/src/compute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use vortex_array::compute::unary::{FillForwardFn, ScalarAtFn};
33
use vortex_array::compute::{ArrayCompute, SliceFn, TakeFn, TakeOptions};
44
use vortex_array::validity::{ArrayValidity, Validity};
55
use vortex_array::variants::PrimitiveArrayTrait;
6-
use vortex_array::{ArrayDType, ArrayData, IntoArrayData, IntoArrayVariant};
6+
use vortex_array::{ArrayDType, ArrayData, IntoArrayData, IntoArrayVariant, ToArrayData};
77
use vortex_dtype::{match_each_integer_ptype, Nullability};
88
use vortex_error::{vortex_err, VortexResult};
99
use vortex_scalar::Scalar;
@@ -97,7 +97,7 @@ impl FillForwardFn for ByteBoolArray {
9797
fn fill_forward(&self) -> VortexResult<ArrayData> {
9898
let validity = self.logical_validity();
9999
if self.dtype().nullability() == Nullability::NonNullable {
100-
return Ok(self.clone().into());
100+
return Ok(self.to_array());
101101
}
102102
// all valid, but we need to convert to non-nullable
103103
if validity.all_valid() {

encodings/datetime-parts/src/compute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub fn decode_to_temporal(array: &DateTimePartsArray) -> VortexResult<TemporalAr
132132
mod test {
133133
use vortex_array::array::{PrimitiveArray, TemporalArray};
134134
use vortex_array::validity::Validity;
135-
use vortex_array::{IntoArrayData, IntoArrayVariant};
135+
use vortex_array::{IntoArrayVariant, ToArrayData};
136136
use vortex_datetime_dtype::TimeUnit;
137137
use vortex_dtype::DType;
138138

@@ -158,7 +158,7 @@ mod test {
158158
assert_eq!(raw_millis.validity(), validity);
159159

160160
let temporal_array = TemporalArray::new_timestamp(
161-
raw_millis.clone().into_array(),
161+
raw_millis.to_array(),
162162
TimeUnit::Ms,
163163
Some("UTC".to_string()),
164164
);

encodings/dict/benches/dict_compress.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rand::distributions::{Alphanumeric, Uniform};
55
use rand::prelude::SliceRandom;
66
use rand::{thread_rng, Rng};
77
use vortex_array::array::{PrimitiveArray, VarBinArray, VarBinViewArray};
8-
use vortex_array::{ArrayTrait, IntoArrayData as _, IntoCanonical as _};
8+
use vortex_array::{ArrayTrait, IntoCanonical as _, ToArrayData};
99
use vortex_dict::{dict_encode_primitive, dict_encode_varbin, dict_encode_varbinview, DictArray};
1010

1111
fn gen_primitive_dict(len: usize, uniqueness: f64) -> PrimitiveArray {
@@ -64,7 +64,7 @@ fn dict_decode(c: &mut Criterion) {
6464
group.throughput(Throughput::Bytes(primitive_arr.nbytes() as u64));
6565
group.bench_function("dict_decode_primitives", |b| {
6666
b.iter_batched(
67-
|| DictArray::try_new(codes.clone().into_array(), values.clone().into_array()).unwrap(),
67+
|| DictArray::try_new(codes.to_array(), values.to_array()).unwrap(),
6868
|dict_arr| black_box(dict_arr.into_canonical().unwrap()),
6969
BatchSize::SmallInput,
7070
);
@@ -75,7 +75,7 @@ fn dict_decode(c: &mut Criterion) {
7575
group.throughput(Throughput::Bytes(varbin_arr.nbytes() as u64));
7676
group.bench_function("dict_decode_varbin", |b| {
7777
b.iter_batched(
78-
|| DictArray::try_new(codes.clone().into_array(), values.clone().into_array()).unwrap(),
78+
|| DictArray::try_new(codes.to_array(), values.to_array()).unwrap(),
7979
|dict_arr| black_box(dict_arr.into_canonical().unwrap()),
8080
BatchSize::SmallInput,
8181
);
@@ -86,7 +86,7 @@ fn dict_decode(c: &mut Criterion) {
8686
group.throughput(Throughput::Bytes(varbin_arr.nbytes() as u64));
8787
group.bench_function("dict_decode_varbinview", |b| {
8888
b.iter_batched(
89-
|| DictArray::try_new(codes.clone().into_array(), values.clone().into_array()).unwrap(),
89+
|| DictArray::try_new(codes.to_array(), values.to_array()).unwrap(),
9090
|dict_arr| black_box(dict_arr.into_canonical().unwrap()),
9191
BatchSize::SmallInput,
9292
);

encodings/fastlanes/src/bitpacking/compress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn patch_unpacked(array: PrimitiveArray, patches: &ArrayData) -> VortexResult<Pr
193193
match patches.encoding().id() {
194194
Sparse::ID => {
195195
match_each_integer_ptype!(array.ptype(), |$T| {
196-
let typed_patches = SparseArray::try_from(patches).unwrap();
196+
let typed_patches = SparseArray::try_from(patches.clone()).unwrap();
197197
let primitive_values = typed_patches.values().into_primitive()?;
198198
array.patch(
199199
&typed_patches.resolved_indices(),

encodings/fastlanes/src/bitpacking/compute/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl SliceFn for BitPackedArray {
2929
.filter(|a| {
3030
// If the sliced patch_indices is empty, we should not propagate the patches.
3131
// There may be other logic that depends on Some(patches) indicating non-empty.
32-
!SparseArray::try_from(a)
32+
!SparseArray::try_from(a.clone())
3333
.vortex_expect("BitPackedArray must encode patches as SparseArray")
3434
.indices()
3535
.is_empty()

encodings/fastlanes/src/bitpacking/mod.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fmt::{Debug, Display};
2+
use std::sync::Arc;
23

34
use ::serde::{Deserialize, Serialize};
45
pub use compress::*;
@@ -9,9 +10,7 @@ use vortex_array::encoding::ids;
910
use vortex_array::stats::{ArrayStatisticsCompute, StatsSet};
1011
use vortex_array::validity::{ArrayValidity, LogicalValidity, Validity, ValidityMetadata};
1112
use vortex_array::variants::{ArrayVariants, PrimitiveArrayTrait};
12-
use vortex_array::{
13-
impl_encoding, ArrayDType, ArrayData, ArrayTrait, Canonical, IntoCanonical, TypedArray,
14-
};
13+
use vortex_array::{impl_encoding, ArrayDType, ArrayData, ArrayTrait, Canonical, IntoCanonical};
1514
use vortex_buffer::Buffer;
1615
use vortex_dtype::{DType, NativePType, Nullability, PType};
1716
use vortex_error::{vortex_bail, vortex_err, VortexExpect as _, VortexResult};
@@ -97,7 +96,7 @@ impl BitPackedArray {
9796
)
9897
}
9998

100-
if SparseArray::try_from(parray)?.indices().is_empty() {
99+
if SparseArray::try_from(parray.clone())?.indices().is_empty() {
101100
vortex_bail!("cannot construct BitPackedArray using patches without indices");
102101
}
103102
}
@@ -117,16 +116,16 @@ impl BitPackedArray {
117116
children.push(a)
118117
}
119118

120-
Ok(Self {
121-
typed: TypedArray::try_from_parts(
122-
dtype,
123-
length,
124-
metadata,
125-
Some(packed),
126-
children.into(),
127-
StatsSet::default(),
128-
)?,
129-
})
119+
ArrayData::try_new_owned(
120+
&BitPackedEncoding,
121+
dtype,
122+
length,
123+
Arc::new(metadata),
124+
Some(packed),
125+
children.into(),
126+
StatsSet::default(),
127+
)?
128+
.try_into()
130129
}
131130

132131
#[inline]
@@ -188,7 +187,7 @@ impl BitPackedArray {
188187
}
189188

190189
pub fn encode(array: &ArrayData, bit_width: u8) -> VortexResult<Self> {
191-
if let Ok(parray) = PrimitiveArray::try_from(array) {
190+
if let Ok(parray) = PrimitiveArray::try_from(array.clone()) {
192191
bitpack_encode(parray, bit_width)
193192
} else {
194193
vortex_bail!("Bitpacking can only encode primitive arrays");

0 commit comments

Comments
 (0)