Skip to content

Commit eebf64b

Browse files
ARROW-11511: [Rust] Replace Arc<ArrayData> by ArrayData in all arrays
# Rational Currently, all our arrays use an `Arc<ArrayData>`, which they expose via `Array::data` and `Array::data_ref`. This adds a level of indirection. Now, it happens that, afaik, in the current code base `Arc<>` is not needed. On #9271 we are observing some performace issues with small arrays, and one of the ideas that came up was to get rid of `Arc` and see what happens. # This PR Well, this PR replaces all `Arc<ArrayData>` by `ArrayData`. On the one hand, this means that cloning an array is a tad more expensive (`Arc` vs `ArrayData`). On the other hand, it means that often the compiler can optimize out. The gist of the benchmarks below is: * ~10%-20% improvement over basically everything * ~20%-100% improvement in `take` There is some noise, as there are benches that are not expected to be affected and are being affected. Personally, I like this PR because it makes working with `ArrayData` and arrays simpler: no need for `Arc::new` or `as_ref` and company (besides the speed). # questions * does anyone knows why we are using `Arc<ArrayData>` in all arrays? * Do you envision an issue with removing the `Arc`? * Would someone be so kind and run the benches independently, just to be sure. # Benchmarks ```bash # modify cargo.toml by adding `bench = false` to the section [lib] git checkout master cargo bench --benches -- --save-baseline `git branch --show-current`-`git rev-parse --short HEAD` git checkout arcless cargo bench --benches -- --save-baseline `git branch --show-current`-`git rev-parse --short HEAD` ``` ``` Jorges-MacBook-Pro-2:arrow jorgecarleitao$ critcmp master-437c8c944 arcless-3dbcaca49 -t 10 group arcless-3dbcaca49 master-437c8c944 ----- ----------------- ---------------- add 512 1.00 435.3±8.19ns ? B/sec 1.30 565.7±81.95ns ? B/sec add_nulls_512 1.00 451.9±15.41ns ? B/sec 1.29 581.9±98.83ns ? B/sec and 1.00 1516.9±39.34ns ? B/sec 1.21 1842.4±190.71ns ? B/sec array_from_vec 128 1.00 932.0±35.13ns ? B/sec 1.51 1411.2±475.00ns ? B/sec array_from_vec 256 1.00 1125.6±24.63ns ? B/sec 1.23 1382.1±201.90ns ? B/sec array_from_vec 512 1.00 1519.9±52.92ns ? B/sec 1.24 1877.9±368.40ns ? B/sec array_slice 128 1.00 293.3±4.85ns ? B/sec 1.61 471.3±94.42ns ? B/sec array_slice 2048 1.00 319.7±8.25ns ? B/sec 1.50 478.2±293.70ns ? B/sec array_slice 512 1.00 293.8±5.91ns ? B/sec 1.69 496.1±145.06ns ? B/sec array_string_from_vec 128 1.00 3.2±0.10µs ? B/sec 1.35 4.3±1.68µs ? B/sec array_string_from_vec 256 1.00 4.1±0.13µs ? B/sec 1.18 4.9±0.94µs ? B/sec array_string_from_vec 512 1.00 5.9±0.11µs ? B/sec 1.26 7.4±5.14µs ? B/sec bench_bool/bench_bool 1.00 2.0±0.03ms 245.8 MB/sec 1.12 2.3±0.30ms 219.7 MB/sec buffer_bit_ops and 1.00 577.0±11.19ns ? B/sec 1.14 658.5±185.85ns ? B/sec cast date32 to date64 512 1.00 6.8±0.21µs ? B/sec 1.18 8.0±1.25µs ? B/sec cast date64 to date32 512 1.00 6.8±0.42µs ? B/sec 1.27 8.6±2.22µs ? B/sec cast f32 to string 512 1.00 52.2±1.37µs ? B/sec 1.17 61.0±9.24µs ? B/sec cast float32 to int32 512 1.00 2.9±0.07µs ? B/sec 1.20 3.4±0.52µs ? B/sec cast float64 to float32 512 1.00 3.0±0.07µs ? B/sec 1.18 3.6±0.47µs ? B/sec cast float64 to uint64 512 1.00 3.4±0.19µs ? B/sec 1.45 5.0±0.72µs ? B/sec cast int32 to float32 512 1.00 2.9±0.09µs ? B/sec 1.11 3.3±0.52µs ? B/sec cast int32 to float64 512 1.00 2.7±0.12µs ? B/sec 1.27 3.4±0.77µs ? B/sec cast int32 to int64 512 1.00 2.9±0.06µs ? B/sec 1.26 3.6±0.67µs ? B/sec cast int32 to uint32 512 1.00 2.7±0.08µs ? B/sec 1.23 3.3±0.32µs ? B/sec cast int64 to int32 512 1.00 2.7±0.05µs ? B/sec 1.23 3.3±0.89µs ? B/sec cast time32s to time32ms 512 1.00 1487.8±52.94ns ? B/sec 1.11 1648.3±145.69ns ? B/sec cast time32s to time64us 512 1.00 4.8±0.12µs ? B/sec 1.26 6.0±0.82µs ? B/sec cast time64ns to time32s 512 1.00 9.9±0.24µs ? B/sec 1.24 12.3±1.87µs ? B/sec cast timestamp_ms to i64 512 1.00 286.7±13.15ns ? B/sec 1.66 474.9±72.34ns ? B/sec cast timestamp_ms to timestamp_ns 512 1.00 1961.6±38.52ns ? B/sec 1.41 2.8±4.01µs ? B/sec cast timestamp_ns to timestamp_s 512 1.00 26.2±0.31ns ? B/sec 1.12 29.4±3.74ns ? B/sec cast utf8 to date32 512 1.00 43.9±1.05µs ? B/sec 1.15 50.7±10.33µs ? B/sec cast utf8 to f32 1.00 30.9±0.81µs ? B/sec 1.21 37.5±5.32µs ? B/sec concat str 1024 1.00 9.9±0.54µs ? B/sec 1.34 13.2±5.26µs ? B/sec divide 512 1.00 1411.3±40.15ns ? B/sec 1.13 1599.1±200.00ns ? B/sec divide_nulls_512 1.00 1419.2±28.43ns ? B/sec 1.12 1587.9±142.46ns ? B/sec eq Float32 1.00 103.3±3.33µs ? B/sec 1.25 129.4±19.72µs ? B/sec equal_512 1.00 19.2±1.00ns ? B/sec 2.58 49.5±12.56ns ? B/sec equal_bool_512 1.00 19.1±1.39ns ? B/sec 2.17 41.5±2.29ns ? B/sec equal_bool_513 1.00 21.1±0.70ns ? B/sec 2.15 45.4±3.84ns ? B/sec equal_nulls_512 1.00 2.4±0.11µs ? B/sec 1.11 2.7±0.37µs ? B/sec equal_string_512 1.00 84.5±5.08ns ? B/sec 1.32 111.9±5.30ns ? B/sec equal_string_nulls_512 1.00 3.6±0.48µs ? B/sec 1.11 4.0±1.29µs ? B/sec filter context f32 high selectivity 1.00 308.9±10.81µs ? B/sec 1.11 343.2±57.50µs ? B/sec filter context f32 low selectivity 1.00 2.7±0.08µs ? B/sec 1.10 3.0±0.43µs ? B/sec filter context string high selectivity 1.00 1091.3±26.04µs ? B/sec 1.13 1238.6±174.82µs ? B/sec filter context u8 1.00 231.6±4.05µs ? B/sec 1.21 281.0±112.36µs ? B/sec filter context u8 w NULLs 1.00 500.1±20.38µs ? B/sec 1.17 586.5±155.02µs ? B/sec filter context u8 w NULLs high selectivity 1.00 295.2±5.91µs ? B/sec 1.17 344.2±63.42µs ? B/sec filter context u8 w NULLs low selectivity 1.00 2.9±0.51µs ? B/sec 1.21 3.5±5.02µs ? B/sec filter f32 1.00 797.4±33.25µs ? B/sec 1.22 971.4±135.07µs ? B/sec filter u8 low selectivity 1.00 7.9±0.73µs ? B/sec 1.12 8.9±1.47µs ? B/sec from_slice prepared 1.15 961.1±24.81µs ? B/sec 1.00 834.2±59.41µs ? B/sec gt Float32 1.00 66.2±14.03µs ? B/sec 1.28 84.6±9.31µs ? B/sec gt scalar Float32 1.49 60.9±8.59µs ? B/sec 1.00 40.8±4.06µs ? B/sec gt_eq Float32 1.00 117.3±31.66µs ? B/sec 1.10 129.6±25.35µs ? B/sec json_list_primitive_to_record_batch 1.00 63.3±2.09µs ? B/sec 1.16 73.4±11.01µs ? B/sec json_primitive_to_record_batch 1.00 25.1±0.82µs ? B/sec 1.11 27.7±4.88µs ? B/sec length 1.00 2.9±0.10µs ? B/sec 1.30 3.7±0.77µs ? B/sec like_utf8 scalar ends with 1.00 246.5±13.62µs ? B/sec 1.19 294.5±45.77µs ? B/sec like_utf8 scalar equals 1.17 98.3±7.08µs ? B/sec 1.00 83.7±10.13µs ? B/sec limit 512, 512 1.00 291.9±5.45ns ? B/sec 1.55 451.1±130.11ns ? B/sec lt Float32 1.00 70.0±19.63µs ? B/sec 1.26 88.3±12.27µs ? B/sec lt scalar Float32 1.00 62.6±3.01µs ? B/sec 1.39 87.3±25.97µs ? B/sec lt_eq Float32 1.00 104.8±8.32µs ? B/sec 1.43 149.9±56.97µs ? B/sec lt_eq scalar Float32 1.00 82.1±3.59µs ? B/sec 1.11 91.3±12.27µs ? B/sec max nulls 512 1.00 1378.4±51.28ns ? B/sec 1.32 1820.6±260.46ns ? B/sec min 512 1.00 1510.6±13.17ns ? B/sec 1.28 1938.2±515.72ns ? B/sec min nulls 512 1.00 1380.2±51.78ns ? B/sec 1.44 1980.7±259.55ns ? B/sec min nulls string 512 1.00 7.1±0.12µs ? B/sec 1.25 8.9±1.66µs ? B/sec multiply 512 1.00 461.5±42.95ns ? B/sec 1.30 601.0±102.46ns ? B/sec mutable 1.00 475.9±15.21µs ? B/sec 1.19 566.7±77.31µs ? B/sec mutable prepared 1.00 530.8±21.36µs ? B/sec 1.17 621.0±60.61µs ? B/sec mutable str 1024 1.00 1493.7±56.88µs ? B/sec 1.19 1776.6±329.88µs ? B/sec mutable str nulls 1024 1.00 4.6±0.30ms ? B/sec 1.13 5.2±0.51ms ? B/sec neq Float32 1.00 65.8±1.70µs ? B/sec 1.39 91.5±20.30µs ? B/sec neq scalar Float32 1.47 97.6±50.68µs ? B/sec 1.00 66.4±6.21µs ? B/sec nlike_utf8 scalar contains 1.00 2.4±0.03ms ? B/sec 1.16 2.8±0.41ms ? B/sec nlike_utf8 scalar equals 1.00 218.8±19.42µs ? B/sec 1.14 249.2±24.71µs ? B/sec not 1.00 955.5±27.28ns ? B/sec 1.15 1102.4±153.08ns ? B/sec or 1.00 1497.9±37.68ns ? B/sec 1.15 1726.6±88.42ns ? B/sec sort 2^10 1.00 153.9±11.62µs ? B/sec 1.14 175.6±25.84µs ? B/sec sort 2^12 1.00 748.9±51.51µs ? B/sec 1.13 849.8±109.51µs ? B/sec struct_array_from_vec 256 1.00 7.6±0.23µs ? B/sec 1.12 8.5±2.51µs ? B/sec struct_array_from_vec 512 1.00 10.0±0.73µs ? B/sec 1.24 12.4±3.51µs ? B/sec subtract 512 1.00 434.8±9.25ns ? B/sec 1.32 574.3±37.34ns ? B/sec sum 512 1.00 524.8±12.74ns ? B/sec 1.19 626.2±156.66ns ? B/sec take bool 1024 1.00 3.6±0.27µs ? B/sec 1.45 5.2±3.11µs ? B/sec take bool 512 1.00 2.1±0.10µs ? B/sec 1.23 2.6±0.32µs ? B/sec take bool nulls 1024 1.00 5.1±2.09µs ? B/sec 1.60 8.1±2.08µs ? B/sec take bool nulls 512 1.00 2.1±0.14µs ? B/sec 1.82 3.9±0.77µs ? B/sec take i32 1024 1.00 1583.0±111.03ns ? B/sec 1.49 2.4±0.58µs ? B/sec take i32 512 1.00 1058.3±88.60ns ? B/sec 1.29 1364.4±97.02ns ? B/sec take i32 nulls 1024 1.00 1527.5±54.16ns ? B/sec 1.82 2.8±1.00µs ? B/sec take i32 nulls 512 1.00 1086.4±124.91ns ? B/sec 2.34 2.5±1.64µs ? B/sec take str 1024 1.00 5.9±0.51µs ? B/sec 1.20 7.1±1.30µs ? B/sec take str 512 1.00 3.8±0.36µs ? B/sec 1.21 4.6±0.96µs ? B/sec take str null indices 1024 1.00 5.6±0.16µs ? B/sec 1.27 7.2±1.63µs ? B/sec take str null indices 512 1.00 3.7±0.31µs ? B/sec 1.23 4.6±1.32µs ? B/sec take str null values 1024 1.00 5.7±0.14µs ? B/sec 1.25 7.1±1.02µs ? B/sec take str null values null indices 1024 1.00 12.8±0.39µs ? B/sec 1.14 14.6±1.85µs ? B/sec ``` Closes #9329 from jorgecarleitao/arcless Lead-authored-by: Jorge C. Leitao <[email protected]> Co-authored-by: Neville Dipale <[email protected]> Signed-off-by: Neville Dipale <[email protected]>
1 parent ae87509 commit eebf64b

Some content is hidden

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

47 files changed

+614
-616
lines changed

rust/arrow/examples/dynamic_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn process(batch: &RecordBatch) {
9595
Arc::new(projected_schema),
9696
vec![
9797
id.clone(), // NOTE: this is cloning the Arc not the array data
98-
Arc::new(Float64Array::from(nested_c.data())),
98+
Arc::new(Float64Array::from(nested_c.data().clone())),
9999
],
100100
);
101101
}

rust/arrow/src/array/array.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use std::fmt;
1919
use std::sync::Arc;
2020
use std::{any::Any, convert::TryFrom};
2121

22-
use super::ArrayDataRef;
2322
use super::*;
2423
use crate::array::equal_json::JsonEqual;
2524
use crate::buffer::{Buffer, MutableBuffer};
@@ -57,11 +56,13 @@ pub trait Array: fmt::Debug + Send + Sync + JsonEqual {
5756
/// ```
5857
fn as_any(&self) -> &Any;
5958

60-
/// Returns a reference-counted pointer to the underlying data of this array.
61-
fn data(&self) -> ArrayDataRef;
59+
/// Returns a reference to the underlying data of this array.
60+
fn data(&self) -> &ArrayData;
6261

63-
/// Returns a borrowed & reference-counted pointer to the underlying data of this array.
64-
fn data_ref(&self) -> &ArrayDataRef;
62+
/// Returns a reference-counted pointer to the underlying data of this array.
63+
fn data_ref(&self) -> &ArrayData {
64+
self.data()
65+
}
6566

6667
/// Returns a reference to the [`DataType`](crate::datatypes::DataType) of this array.
6768
///
@@ -93,7 +94,7 @@ pub trait Array: fmt::Debug + Send + Sync + JsonEqual {
9394
/// assert_eq!(array_slice.as_ref(), &Int32Array::from(vec![2, 3, 4]));
9495
/// ```
9596
fn slice(&self, offset: usize, length: usize) -> ArrayRef {
96-
make_array(Arc::new(self.data_ref().as_ref().slice(offset, length)))
97+
make_array(self.data_ref().slice(offset, length))
9798
}
9899

99100
/// Returns the length (i.e., number of elements) of this array.
@@ -206,7 +207,7 @@ pub trait Array: fmt::Debug + Send + Sync + JsonEqual {
206207
fn to_raw(
207208
&self,
208209
) -> Result<(*const ffi::FFI_ArrowArray, *const ffi::FFI_ArrowSchema)> {
209-
let data = self.data().as_ref().clone();
210+
let data = self.data().clone();
210211
let array = ffi::ArrowArray::try_from(data)?;
211212
Ok(ffi::ArrowArray::into_raw(array))
212213
}
@@ -217,7 +218,7 @@ pub type ArrayRef = Arc<Array>;
217218

218219
/// Constructs an array using the input `data`.
219220
/// Returns a reference-counted `Array` instance.
220-
pub fn make_array(data: ArrayDataRef) -> ArrayRef {
221+
pub fn make_array(data: ArrayData) -> ArrayRef {
221222
match data.data_type() {
222223
DataType::Boolean => Arc::new(BooleanArray::from(data)) as ArrayRef,
223224
DataType::Int8 => Arc::new(Int8Array::from(data)) as ArrayRef,
@@ -325,7 +326,7 @@ pub fn make_array(data: ArrayDataRef) -> ArrayRef {
325326
/// Creates a new empty array
326327
pub fn new_empty_array(data_type: &DataType) -> ArrayRef {
327328
let data = ArrayData::new_empty(data_type);
328-
make_array(Arc::new(data))
329+
make_array(data)
329330
}
330331
/// Creates a new array of `data_type` of length `length` filled entirely of `NULL` values
331332
pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
@@ -334,15 +335,15 @@ pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
334335
DataType::Null => Arc::new(NullArray::new(length)),
335336
DataType::Boolean => {
336337
let null_buf: Buffer = MutableBuffer::new_null(length).into();
337-
make_array(Arc::new(ArrayData::new(
338+
make_array(ArrayData::new(
338339
data_type.clone(),
339340
length,
340341
Some(length),
341342
Some(null_buf.clone()),
342343
0,
343344
vec![null_buf],
344345
vec![],
345-
)))
346+
))
346347
}
347348
DataType::Int8 => new_null_sized_array::<Int8Type>(data_type, length),
348349
DataType::UInt8 => new_null_sized_array::<UInt8Type>(data_type, length),
@@ -371,15 +372,15 @@ pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
371372
new_null_sized_array::<IntervalDayTimeType>(data_type, length)
372373
}
373374
},
374-
DataType::FixedSizeBinary(value_len) => make_array(Arc::new(ArrayData::new(
375+
DataType::FixedSizeBinary(value_len) => make_array(ArrayData::new(
375376
data_type.clone(),
376377
length,
377378
Some(length),
378379
Some(MutableBuffer::new_null(length).into()),
379380
0,
380381
vec![Buffer::from(vec![0u8; *value_len as usize * length])],
381382
vec![],
382-
))),
383+
)),
383384
DataType::Binary | DataType::Utf8 => {
384385
new_null_binary_array::<i32>(data_type, length)
385386
}
@@ -392,21 +393,20 @@ pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
392393
DataType::LargeList(field) => {
393394
new_null_list_array::<i64>(data_type, field.data_type(), length)
394395
}
395-
DataType::FixedSizeList(field, value_len) => {
396-
make_array(Arc::new(ArrayData::new(
397-
data_type.clone(),
398-
length,
399-
Some(length),
400-
Some(MutableBuffer::new_null(length).into()),
401-
0,
402-
vec![],
403-
vec![
404-
new_null_array(field.data_type(), *value_len as usize * length)
405-
.data(),
406-
],
407-
)))
408-
}
409-
DataType::Struct(fields) => make_array(Arc::new(ArrayData::new(
396+
DataType::FixedSizeList(field, value_len) => make_array(ArrayData::new(
397+
data_type.clone(),
398+
length,
399+
Some(length),
400+
Some(MutableBuffer::new_null(length).into()),
401+
0,
402+
vec![],
403+
vec![
404+
new_null_array(field.data_type(), *value_len as usize * length)
405+
.data()
406+
.clone(),
407+
],
408+
)),
409+
DataType::Struct(fields) => make_array(ArrayData::new(
410410
data_type.clone(),
411411
length,
412412
Some(length),
@@ -415,22 +415,22 @@ pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
415415
vec![],
416416
fields
417417
.iter()
418-
.map(|field| Arc::new(ArrayData::new_empty(field.data_type())))
418+
.map(|field| ArrayData::new_empty(field.data_type()))
419419
.collect(),
420-
))),
420+
)),
421421
DataType::Union(_) => {
422422
unimplemented!("Creating null Union array not yet supported")
423423
}
424424
DataType::Dictionary(_, value) => {
425-
make_array(Arc::new(ArrayData::new(
425+
make_array(ArrayData::new(
426426
data_type.clone(),
427427
length,
428428
Some(length),
429429
Some(MutableBuffer::new_null(length).into()),
430430
0,
431431
vec![MutableBuffer::new(0).into()], // values are empty
432-
vec![new_empty_array(value.as_ref()).data()],
433-
)))
432+
vec![new_empty_array(value.as_ref()).data().clone()],
433+
))
434434
}
435435
DataType::Decimal(_, _) => {
436436
unimplemented!("Creating null Decimal array not yet supported")
@@ -444,7 +444,7 @@ fn new_null_list_array<OffsetSize: OffsetSizeTrait>(
444444
child_data_type: &DataType,
445445
length: usize,
446446
) -> ArrayRef {
447-
make_array(Arc::new(ArrayData::new(
447+
make_array(ArrayData::new(
448448
data_type.clone(),
449449
length,
450450
Some(length),
@@ -453,16 +453,16 @@ fn new_null_list_array<OffsetSize: OffsetSizeTrait>(
453453
vec![Buffer::from(
454454
vec![OffsetSize::zero(); length + 1].to_byte_slice(),
455455
)],
456-
vec![Arc::new(ArrayData::new_empty(child_data_type))],
457-
)))
456+
vec![ArrayData::new_empty(child_data_type)],
457+
))
458458
}
459459

460460
#[inline]
461461
fn new_null_binary_array<OffsetSize: OffsetSizeTrait>(
462462
data_type: &DataType,
463463
length: usize,
464464
) -> ArrayRef {
465-
make_array(Arc::new(ArrayData::new(
465+
make_array(ArrayData::new(
466466
data_type.clone(),
467467
length,
468468
Some(length),
@@ -473,23 +473,23 @@ fn new_null_binary_array<OffsetSize: OffsetSizeTrait>(
473473
MutableBuffer::new(0).into(),
474474
],
475475
vec![],
476-
)))
476+
))
477477
}
478478

479479
#[inline]
480480
fn new_null_sized_array<T: ArrowPrimitiveType>(
481481
data_type: &DataType,
482482
length: usize,
483483
) -> ArrayRef {
484-
make_array(Arc::new(ArrayData::new(
484+
make_array(ArrayData::new(
485485
data_type.clone(),
486486
length,
487487
Some(length),
488488
Some(MutableBuffer::new_null(length).into()),
489489
0,
490490
vec![Buffer::from(vec![0u8; length * T::get_byte_width()])],
491491
vec![],
492-
)))
492+
))
493493
}
494494

495495
/// Creates a new array from two FFI pointers. Used to import arrays from the C Data Interface
@@ -501,7 +501,7 @@ pub unsafe fn make_array_from_raw(
501501
schema: *const ffi::FFI_ArrowSchema,
502502
) -> Result<ArrayRef> {
503503
let array = ffi::ArrowArray::try_from_raw(array, schema)?;
504-
let data = Arc::new(ArrayData::try_from(array)?);
504+
let data = ArrayData::try_from(array)?;
505505
Ok(make_array(data))
506506
}
507507
// Helper function for printing potentially long arrays.

rust/arrow/src/array/array_binary.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
use std::convert::{From, TryInto};
1819
use std::fmt;
1920
use std::mem;
2021
use std::{any::Any, iter::FromIterator};
21-
use std::{
22-
convert::{From, TryInto},
23-
sync::Arc,
24-
};
2522

2623
use super::{
27-
array::print_long_array, raw_pointer::RawPtrBox, Array, ArrayData, ArrayDataRef,
24+
array::print_long_array, raw_pointer::RawPtrBox, Array, ArrayData,
2825
FixedSizeListArray, GenericBinaryIter, GenericListArray, OffsetSizeTrait,
2926
};
3027
use crate::buffer::Buffer;
@@ -47,7 +44,7 @@ impl BinaryOffsetSizeTrait for i64 {
4744
}
4845

4946
pub struct GenericBinaryArray<OffsetSize: BinaryOffsetSizeTrait> {
50-
data: ArrayDataRef,
47+
data: ArrayData,
5148
value_offsets: RawPtrBox<OffsetSize>,
5249
value_data: RawPtrBox<u8>,
5350
}
@@ -199,11 +196,7 @@ impl<OffsetSize: BinaryOffsetSizeTrait> Array for GenericBinaryArray<OffsetSize>
199196
self
200197
}
201198

202-
fn data(&self) -> ArrayDataRef {
203-
self.data.clone()
204-
}
205-
206-
fn data_ref(&self) -> &ArrayDataRef {
199+
fn data(&self) -> &ArrayData {
207200
&self.data
208201
}
209202

@@ -218,10 +211,10 @@ impl<OffsetSize: BinaryOffsetSizeTrait> Array for GenericBinaryArray<OffsetSize>
218211
}
219212
}
220213

221-
impl<OffsetSize: BinaryOffsetSizeTrait> From<ArrayDataRef>
214+
impl<OffsetSize: BinaryOffsetSizeTrait> From<ArrayData>
222215
for GenericBinaryArray<OffsetSize>
223216
{
224-
fn from(data: ArrayDataRef) -> Self {
217+
fn from(data: ArrayData) -> Self {
225218
assert_eq!(
226219
data.data_type(),
227220
&<OffsetSize as BinaryOffsetSizeTrait>::DATA_TYPE,
@@ -324,7 +317,7 @@ impl<T: BinaryOffsetSizeTrait> From<GenericListArray<T>> for GenericBinaryArray<
324317

325318
/// A type of `FixedSizeListArray` whose elements are binaries.
326319
pub struct FixedSizeBinaryArray {
327-
data: ArrayDataRef,
320+
data: ArrayData,
328321
value_data: RawPtrBox<u8>,
329322
length: i32,
330323
}
@@ -451,7 +444,7 @@ impl FixedSizeBinaryArray {
451444
vec![buffer.into()],
452445
vec![],
453446
);
454-
Ok(FixedSizeBinaryArray::from(Arc::new(array_data)))
447+
Ok(FixedSizeBinaryArray::from(array_data))
455448
}
456449

457450
/// Create an array from an iterable argument of byte slices.
@@ -519,8 +512,8 @@ impl FixedSizeBinaryArray {
519512
}
520513
}
521514

522-
impl From<ArrayDataRef> for FixedSizeBinaryArray {
523-
fn from(data: ArrayDataRef) -> Self {
515+
impl From<ArrayData> for FixedSizeBinaryArray {
516+
fn from(data: ArrayData) -> Self {
524517
assert_eq!(
525518
data.buffers().len(),
526519
1,
@@ -581,11 +574,7 @@ impl Array for FixedSizeBinaryArray {
581574
self
582575
}
583576

584-
fn data(&self) -> ArrayDataRef {
585-
self.data.clone()
586-
}
587-
588-
fn data_ref(&self) -> &ArrayDataRef {
577+
fn data(&self) -> &ArrayData {
589578
&self.data
590579
}
591580

@@ -602,7 +591,7 @@ impl Array for FixedSizeBinaryArray {
602591

603592
/// A type of `DecimalArray` whose elements are binaries.
604593
pub struct DecimalArray {
605-
data: ArrayDataRef,
594+
data: ArrayData,
606595
value_data: RawPtrBox<u8>,
607596
precision: usize,
608597
scale: usize,
@@ -690,8 +679,8 @@ impl DecimalArray {
690679
}
691680
}
692681

693-
impl From<ArrayDataRef> for DecimalArray {
694-
fn from(data: ArrayDataRef) -> Self {
682+
impl From<ArrayData> for DecimalArray {
683+
fn from(data: ArrayData) -> Self {
695684
assert_eq!(
696685
data.buffers().len(),
697686
1,
@@ -728,11 +717,7 @@ impl Array for DecimalArray {
728717
self
729718
}
730719

731-
fn data(&self) -> ArrayDataRef {
732-
self.data.clone()
733-
}
734-
735-
fn data_ref(&self) -> &ArrayDataRef {
720+
fn data(&self) -> &ArrayData {
736721
&self.data
737722
}
738723

0 commit comments

Comments
 (0)