diff --git a/Cargo.toml b/Cargo.toml index 90436b4f1a9..30bec197b3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -350,6 +350,7 @@ needless_range_loop = "allow" or_fun_call = "deny" panic = "deny" # panic_in_result_fn = "deny" -- we cannot disable this for tests to use assertions +clone_on_ref_ptr = "warn" redundant_clone = "deny" same_name_method = "deny" tests_outside_test_module = "deny" diff --git a/benchmarks/compress-bench/src/lib.rs b/benchmarks/compress-bench/src/lib.rs index 9fa6928cf0d..477a4942f3e 100644 --- a/benchmarks/compress-bench/src/lib.rs +++ b/benchmarks/compress-bench/src/lib.rs @@ -22,7 +22,7 @@ pub fn chunked_to_vec_record_batch( .map(|array| { // TODO(connor)[ListView]: The rust Parquet implementation does not support writing // `ListView` to Parquet files yet. - let converted_array = recursive_list_from_list_view(array.clone())?; + let converted_array = recursive_list_from_list_view(Arc::clone(&array))?; Ok(RecordBatch::try_from(converted_array.as_ref())?) }) .collect::>>()?; diff --git a/benchmarks/compress-bench/src/parquet.rs b/benchmarks/compress-bench/src/parquet.rs index 0a4e9105600..e172be9b5a3 100644 --- a/benchmarks/compress-bench/src/parquet.rs +++ b/benchmarks/compress-bench/src/parquet.rs @@ -53,7 +53,7 @@ impl Compressor for ParquetCompressor { // Read the input parquet file let file = File::open(parquet_path)?; let builder = ParquetRecordBatchReaderBuilder::try_new(file)?; - let schema = builder.schema().clone(); + let schema = Arc::clone(&builder.schema()); let reader = builder.build()?; let batches: Vec = reader.collect::, _>>()?; @@ -69,7 +69,7 @@ impl Compressor for ParquetCompressor { // First compress to get the bytes we'll decompress let file = File::open(parquet_path)?; let builder = ParquetRecordBatchReaderBuilder::try_new(file)?; - let schema = builder.schema().clone(); + let schema = Arc::clone(&builder.schema()); let reader = builder.build()?; let batches: Vec = reader.collect::, _>>()?; diff --git a/benchmarks/datafusion-bench/src/lib.rs b/benchmarks/datafusion-bench/src/lib.rs index 43b86331e9f..4aeeb80e9bb 100644 --- a/benchmarks/datafusion-bench/src/lib.rs +++ b/benchmarks/datafusion-bench/src/lib.rs @@ -82,7 +82,7 @@ pub fn make_object_store( .build()?, ); session - .register_object_store(&Url::parse(&format!("s3://{bucket_name}/"))?, s3.clone()); + .register_object_store(&Url::parse(&format!("s3://{bucket_name}/"))?, Arc::clone(&s3)); Ok(s3) } "gs" => { @@ -93,12 +93,12 @@ pub fn make_object_store( .build()?, ); session - .register_object_store(&Url::parse(&format!("gs://{bucket_name}/"))?, gcs.clone()); + .register_object_store(&Url::parse(&format!("gs://{bucket_name}/"))?, Arc::clone(&gcs)); Ok(gcs) } _ => { let fs = Arc::new(LocalFileSystem::default()); - session.register_object_store(&Url::parse("file:/")?, fs.clone()); + session.register_object_store(&Url::parse("file:/")?, Arc::clone(&fs)); Ok(fs) } } diff --git a/benchmarks/datafusion-bench/src/main.rs b/benchmarks/datafusion-bench/src/main.rs index 942f52f842e..4feda1d916f 100644 --- a/benchmarks/datafusion-bench/src/main.rs +++ b/benchmarks/datafusion-bench/src/main.rs @@ -203,7 +203,7 @@ async fn main() -> anyhow::Result<()> { .iter() .any(|(idx, f, _)| *idx == query_idx && *f == *format) { - plans_mut.push((query_idx, *format, plan.clone())); + plans_mut.push((query_idx, *format, Arc::clone(&plan))); } } @@ -252,7 +252,7 @@ async fn register_benchmark_tables( let pattern = benchmark.pattern(table.name, format); let table_url = ListingTableUrl::try_new(benchmark_base.clone(), pattern)?; - let mut listing_options = ListingOptions::new(file_format.clone()) + let mut listing_options = ListingOptions::new(Arc::clone(&file_format)) .with_session_config_options(session.state().config()); if benchmark.dataset_name() == "polarsignals" && format == Format::Parquet { // Work around a DataFusion bug (fixed in 53.0.0) where the @@ -305,7 +305,7 @@ async fn register_v2_tables( .object_store(table_url.object_store())?; let fs: vortex::io::filesystem::FileSystemRef = - Arc::new(ObjectStoreFileSystem::new(store.clone(), SESSION.handle())); + Arc::new(ObjectStoreFileSystem::new(Arc::clone(&store), SESSION.handle())); let base_prefix = benchmark_base.path().trim_start_matches('/').to_string(); let fs = fs.with_prefix(base_prefix); @@ -416,7 +416,7 @@ pub async fn execute_query( .create_physical_plan() .with_labelset(get_labelset_from_global()) .await?; - let result = collect(plan.clone(), task_ctx) + let result = collect(Arc::clone(&plan), task_ctx) .with_labelset(get_labelset_from_global()) .await?; diff --git a/benchmarks/lance-bench/src/compress.rs b/benchmarks/lance-bench/src/compress.rs index 93891ec5555..ee83d83d102 100644 --- a/benchmarks/lance-bench/src/compress.rs +++ b/benchmarks/lance-bench/src/compress.rs @@ -22,6 +22,7 @@ use vortex_bench::compress::Compressor; use crate::convert::convert_utf8view_batch; use crate::convert::convert_utf8view_schema; +use std::sync::Arc; /// Read a Lance dataset and decompress it back into RecordBatches. pub async fn lance_decompress_read(path: &str) -> anyhow::Result { @@ -92,7 +93,7 @@ impl Compressor for LanceCompressor { // Read the input parquet file let file = File::open(parquet_path)?; let builder = ParquetRecordBatchReaderBuilder::try_new(file)?; - let schema = builder.schema().clone(); + let schema = Arc::clone(&builder.schema()); let reader = builder.build()?; let batches: Vec = reader.collect::, _>>()?; @@ -131,7 +132,7 @@ impl Compressor for LanceCompressor { // First compress to get the Lance dataset let file = File::open(parquet_path)?; let builder = ParquetRecordBatchReaderBuilder::try_new(file)?; - let schema = builder.schema().clone(); + let schema = Arc::clone(&builder.schema()); let reader = builder.build()?; let batches: Vec = reader.collect::, _>>()?; diff --git a/benchmarks/lance-bench/src/convert.rs b/benchmarks/lance-bench/src/convert.rs index 0da159b25e4..53e8b08d766 100644 --- a/benchmarks/lance-bench/src/convert.rs +++ b/benchmarks/lance-bench/src/convert.rs @@ -84,7 +84,7 @@ impl Iterator for ParquetFilesIterator { impl RecordBatchReader for ParquetFilesIterator { fn schema(&self) -> SchemaRef { - self.schema.clone() + Arc::clone(&self.schema) } } @@ -161,7 +161,7 @@ pub async fn convert_parquet_to_lance<'p>( // Get schema from the first Parquet file let first_file = File::open(&parquet_files[0])?; let first_builder = ParquetRecordBatchReaderBuilder::try_new(first_file)?; - let schema = first_builder.schema().clone(); + let schema = Arc::clone(&first_builder.schema()); // Create a streaming iterator that reads from all Parquet files let batch_iter = ParquetFilesIterator::new(parquet_files, schema)?; @@ -237,7 +237,7 @@ pub fn convert_utf8view_batch(batch: RecordBatch) -> anyhow::Result // Cast Utf8View to Utf8. cast(column, &DataType::Utf8)? } else { - column.clone() + Arc::clone(&column) }; new_columns.push(new_column); } @@ -277,6 +277,6 @@ impl Iterator for ConvertingParquetFilesIterator { impl RecordBatchReader for ConvertingParquetFilesIterator { fn schema(&self) -> SchemaRef { - self.converted_schema.clone() + Arc::clone(&self.converted_schema) } } diff --git a/encodings/alp/src/alp/array.rs b/encodings/alp/src/alp/array.rs index eb71ebbd6a1..ab6f75900c3 100644 --- a/encodings/alp/src/alp/array.rs +++ b/encodings/alp/src/alp/array.rs @@ -459,14 +459,14 @@ impl ALPArray { fn make_slots(encoded: &ArrayRef, patches: &Option) -> Vec> { let (patch_indices, patch_values, patch_chunk_offsets) = match patches { Some(p) => ( - Some(p.indices().clone()), - Some(p.values().clone()), + Some(Arc::clone(&p.indices())), + Some(Arc::clone(&p.values())), p.chunk_offsets().clone(), ), None => (None, None, None), }; vec![ - Some(encoded.clone()), + Some(Arc::clone(&encoded)), patch_indices, patch_values, patch_chunk_offsets, @@ -501,8 +501,8 @@ impl ALPArray { Patches::new_unchecked( self.encoded().len(), patch_offset, - indices.clone(), - values.clone(), + Arc::clone(&indices), + Arc::clone(&values), self.slots[PATCH_CHUNK_OFFSETS_SLOT].clone(), self.patch_offset_within_chunk, ) @@ -836,15 +836,15 @@ mod tests { let patches_without_chunk_offsets = Patches::new( original_patches.array_len(), original_patches.offset(), - original_patches.indices().clone(), - original_patches.values().clone(), + Arc::clone(&original_patches.indices()), + Arc::clone(&original_patches.values()), None, // NO chunk_offsets - this triggers the bug! ) .unwrap(); // Build a new ALPArray with the same encoded data but patches without chunk_offsets. let alp_without_chunk_offsets = ALPArray::new( - normally_encoded.encoded().clone(), + Arc::clone(&normally_encoded.encoded()), normally_encoded.exponents(), Some(patches_without_chunk_offsets), ); diff --git a/encodings/alp/src/alp/compute/between.rs b/encodings/alp/src/alp/compute/between.rs index 2963007ac76..6e04f3a0c6d 100644 --- a/encodings/alp/src/alp/compute/between.rs +++ b/encodings/alp/src/alp/compute/between.rs @@ -20,6 +20,7 @@ use crate::ALP; use crate::ALPArray; use crate::ALPFloat; use crate::match_each_alp_float_ptype; +use std::sync::Arc; impl BetweenReduce for ALP { fn between( @@ -84,7 +85,7 @@ where upper_strict, }; - array.encoded().clone().between( + Arc::clone(&array.encoded()).between( ConstantArray::new(Scalar::primitive(lower_enc, nullability), array.len()).into_array(), ConstantArray::new(Scalar::primitive(upper_enc, nullability), array.len()).into_array(), options, diff --git a/encodings/alp/src/alp/compute/cast.rs b/encodings/alp/src/alp/compute/cast.rs index 3185c69d66c..f1144f2d792 100644 --- a/encodings/alp/src/alp/compute/cast.rs +++ b/encodings/alp/src/alp/compute/cast.rs @@ -11,6 +11,7 @@ use vortex_error::VortexResult; use crate::alp::ALP; use crate::alp::ALPArray; +use std::sync::Arc; impl CastReduce for ALP { fn cast(array: &ALPArray, dtype: &DType) -> VortexResult> { @@ -34,7 +35,7 @@ impl CastReduce for ALP { Patches::new( p.array_len(), p.offset(), - p.indices().clone(), + Arc::clone(&p.indices()), p.values().cast(dtype.clone())?, p.chunk_offsets().clone(), ) diff --git a/encodings/alp/src/alp/compute/mask.rs b/encodings/alp/src/alp/compute/mask.rs index d4f63475c9e..09c13578bfb 100644 --- a/encodings/alp/src/alp/compute/mask.rs +++ b/encodings/alp/src/alp/compute/mask.rs @@ -12,6 +12,7 @@ use vortex_error::VortexResult; use crate::ALP; use crate::ALPArray; +use std::sync::Arc; impl MaskReduce for ALP { fn mask(array: &ALPArray, mask: &ArrayRef) -> VortexResult> { @@ -19,7 +20,7 @@ impl MaskReduce for ALP { if array.patches().is_some() { return Ok(None); } - let masked_encoded = array.encoded().clone().mask(mask.clone())?; + let masked_encoded = Arc::clone(&array.encoded()).mask(Arc::clone(&mask))?; Ok(Some( ALPArray::new(masked_encoded, array.exponents(), None).into_array(), )) @@ -33,7 +34,7 @@ impl MaskKernel for ALP { ctx: &mut ExecutionCtx, ) -> VortexResult> { let vortex_mask = Validity::Array(mask.not()?).execute_mask(array.len(), ctx)?; - let masked_encoded = array.encoded().clone().mask(mask.clone())?; + let masked_encoded = Arc::clone(&array.encoded()).mask(Arc::clone(&mask))?; let masked_patches = array .patches() .map(|p| p.mask(&vortex_mask, ctx)) diff --git a/encodings/alp/src/alp/decompress.rs b/encodings/alp/src/alp/decompress.rs index 7320cddf1db..528ec07c2b3 100644 --- a/encodings/alp/src/alp/decompress.rs +++ b/encodings/alp/src/alp/decompress.rs @@ -17,6 +17,7 @@ use crate::ALPArray; use crate::ALPFloat; use crate::Exponents; use crate::match_each_alp_float_ptype; +use std::sync::Arc; /// Decompresses an ALP-encoded array using `to_primitive` (legacy path). /// @@ -32,9 +33,9 @@ pub fn decompress_into_array( && let Some(chunk_offsets) = patches.chunk_offsets() { let prim_encoded = encoded.execute::(ctx)?; - let patches_chunk_offsets = chunk_offsets.clone().execute::(ctx)?; - let patches_indices = patches.indices().clone().execute::(ctx)?; - let patches_values = patches.values().clone().execute::(ctx)?; + let patches_chunk_offsets = Arc::clone(&chunk_offsets).execute::(ctx)?; + let patches_indices = Arc::clone(&patches.indices()).execute::(ctx)?; + let patches_values = Arc::clone(&patches.values()).execute::(ctx)?; Ok(decompress_chunked_core( prim_encoded, exponents, @@ -65,9 +66,9 @@ pub fn execute_decompress(array: ALPArray, ctx: &mut ExecutionCtx) -> VortexResu { // TODO(joe): have into parts. let encoded = encoded.execute::(ctx)?; - let patches_chunk_offsets = chunk_offsets.clone().execute::(ctx)?; - let patches_indices = patches.indices().clone().execute::(ctx)?; - let patches_values = patches.values().clone().execute::(ctx)?; + let patches_chunk_offsets = Arc::clone(&chunk_offsets).execute::(ctx)?; + let patches_indices = Arc::clone(&patches.indices()).execute::(ctx)?; + let patches_values = Arc::clone(&patches.values()).execute::(ctx)?; Ok(decompress_chunked_core( encoded, exponents, diff --git a/encodings/alp/src/alp_rd/array.rs b/encodings/alp/src/alp_rd/array.rs index 4986bb3abb1..926a03bf6b5 100644 --- a/encodings/alp/src/alp_rd/array.rs +++ b/encodings/alp/src/alp_rd/array.rs @@ -258,8 +258,8 @@ impl VTable for ALPRD { Some(Patches::new( old.array_len(), old.offset(), - indices.clone(), - values.clone(), + Arc::clone(&indices), + Arc::clone(&values), slots[LP_PATCH_CHUNK_OFFSETS_SLOT].clone(), )?) } @@ -492,15 +492,15 @@ impl ALPRDArray { ) -> Vec> { let (pi, pv, pco) = match patches { Some(p) => ( - Some(p.indices().clone()), - Some(p.values().clone()), + Some(Arc::clone(&p.indices())), + Some(Arc::clone(&p.values())), p.chunk_offsets().clone(), ), None => (None, None, None), }; vec![ - Some(left_parts.clone()), - Some(right_parts.clone()), + Some(Arc::clone(&left_parts)), + Some(Arc::clone(&right_parts)), pi, pv, pco, @@ -569,8 +569,8 @@ impl ALPRDArray { // Update both the patches and the corresponding slots to keep them in sync. let (pi, pv, pco) = match &patches { Some(p) => ( - Some(p.indices().clone()), - Some(p.values().clone()), + Some(Arc::clone(&p.indices())), + Some(Arc::clone(&p.values())), p.chunk_offsets().clone(), ), None => (None, None, None), diff --git a/encodings/alp/src/alp_rd/compute/cast.rs b/encodings/alp/src/alp_rd/compute/cast.rs index a1441d6e416..08fc1dd8da5 100644 --- a/encodings/alp/src/alp_rd/compute/cast.rs +++ b/encodings/alp/src/alp_rd/compute/cast.rs @@ -10,6 +10,7 @@ use vortex_error::VortexResult; use crate::alp_rd::ALPRD; use crate::alp_rd::ALPRDArray; +use std::sync::Arc; impl CastReduce for ALPRD { fn cast(array: &ALPRDArray, dtype: &DType) -> VortexResult> { @@ -32,7 +33,7 @@ impl CastReduce for ALPRD { dtype.clone(), new_left_parts, array.left_parts_dictionary().clone(), - array.right_parts().clone(), + Arc::clone(&array.right_parts()), array.right_bit_width(), array.left_parts_patches(), )? diff --git a/encodings/alp/src/alp_rd/compute/mask.rs b/encodings/alp/src/alp_rd/compute/mask.rs index 6126eeef301..2e6be3cbd3c 100644 --- a/encodings/alp/src/alp_rd/compute/mask.rs +++ b/encodings/alp/src/alp_rd/compute/mask.rs @@ -11,20 +11,21 @@ use vortex_error::VortexResult; use crate::ALPRD; use crate::ALPRDArray; +use std::sync::Arc; impl MaskReduce for ALPRD { fn mask(array: &ALPRDArray, mask: &ArrayRef) -> VortexResult> { let masked_left_parts = MaskExpr.try_new_array( array.left_parts().len(), EmptyOptions, - [array.left_parts().clone(), mask.clone()], + [Arc::clone(&array.left_parts()), Arc::clone(&mask)], )?; Ok(Some( ALPRDArray::try_new( array.dtype().as_nullable(), masked_left_parts, array.left_parts_dictionary().clone(), - array.right_parts().clone(), + Arc::clone(&array.right_parts()), array.right_bit_width(), array.left_parts_patches(), )? diff --git a/encodings/alp/src/alp_rd/mod.rs b/encodings/alp/src/alp_rd/mod.rs index 2ba30885342..f200661b23f 100644 --- a/encodings/alp/src/alp_rd/mod.rs +++ b/encodings/alp/src/alp_rd/mod.rs @@ -9,6 +9,7 @@ use vortex_array::IntoArray; use vortex_array::patches::Patches; use vortex_array::validity::Validity; use vortex_fastlanes::bitpack_compress::bitpack_encode_unchecked; +use std::sync::Arc; mod array; mod compute; @@ -314,8 +315,8 @@ pub fn alp_rd_decode( } // Overwrite exception positions with their true left bit-patterns. - let indices = patches.indices().clone().execute::(ctx)?; - let patch_values = patches.values().clone().execute::(ctx)?; + let indices = Arc::clone(&patches.indices()).execute::(ctx)?; + let patch_values = Arc::clone(&patches.values()).execute::(ctx)?; alp_rd_apply_patches(&mut left_parts, &indices, &patch_values, patches.offset()); // Reconstruct floats by shifting each decoded left value into the MSBs diff --git a/encodings/bytebool/src/array.rs b/encodings/bytebool/src/array.rs index dd59ac06e93..80e3aa7e910 100644 --- a/encodings/bytebool/src/array.rs +++ b/encodings/bytebool/src/array.rs @@ -160,7 +160,7 @@ impl VTable for ByteBool { slots.len() ); array.validity = match &slots[VALIDITY_SLOT] { - Some(arr) => Validity::Array(arr.clone()), + Some(arr) => Validity::Array(Arc::clone(&arr)), None => Validity::from(array.dtype.nullability()), }; array.slots = slots; diff --git a/encodings/bytebool/src/compute.rs b/encodings/bytebool/src/compute.rs index ac7e6a23b61..d8519b9dad6 100644 --- a/encodings/bytebool/src/compute.rs +++ b/encodings/bytebool/src/compute.rs @@ -17,6 +17,7 @@ use vortex_error::VortexResult; use super::ByteBool; use super::ByteBoolArray; +use std::sync::Arc; impl CastReduce for ByteBool { fn cast(array: &ByteBoolArray, dtype: &DType) -> VortexResult> { @@ -45,7 +46,7 @@ impl MaskReduce for ByteBool { Ok(Some( ByteBoolArray::new( array.buffer().clone(), - array.validity().and(Validity::Array(mask.clone()))?, + array.validity().and(Validity::Array(Arc::clone(&mask)))?, ) .into_array(), )) @@ -58,7 +59,7 @@ impl TakeExecute for ByteBool { indices: &ArrayRef, ctx: &mut ExecutionCtx, ) -> VortexResult> { - let indices = indices.clone().execute::(ctx)?; + let indices = Arc::clone(&indices).execute::(ctx)?; let bools = array.as_slice(); // This handles combining validity from both source array and nullable indices diff --git a/encodings/datetime-parts/src/canonical.rs b/encodings/datetime-parts/src/canonical.rs index 96d81c9b477..dec5ef0b4ca 100644 --- a/encodings/datetime-parts/src/canonical.rs +++ b/encodings/datetime-parts/src/canonical.rs @@ -19,6 +19,7 @@ use vortex_error::VortexResult; use vortex_error::vortex_panic; use crate::DateTimePartsArray; +use std::sync::Arc; /// Decode an [Array] into a [TemporalArray]. /// @@ -67,7 +68,7 @@ pub fn decode_to_temporal( *v += seconds; } } else { - let seconds_buf = array.seconds().clone().execute::(ctx)?; + let seconds_buf = Arc::clone(&array.seconds()).execute::(ctx)?; match_each_integer_ptype!(seconds_buf.ptype(), |S| { for (v, second) in values.iter_mut().zip(seconds_buf.as_slice::()) { let second: i64 = second.as_(); @@ -85,7 +86,7 @@ pub fn decode_to_temporal( *v += subseconds; } } else { - let subseconds_buf = array.subseconds().clone().execute::(ctx)?; + let subseconds_buf = Arc::clone(&array.subseconds()).execute::(ctx)?; match_each_integer_ptype!(subseconds_buf.ptype(), |S| { for (v, subseconds) in values.iter_mut().zip(subseconds_buf.as_slice::()) { let subseconds: i64 = subseconds.as_(); diff --git a/encodings/datetime-parts/src/compute/cast.rs b/encodings/datetime-parts/src/compute/cast.rs index 916da53d619..b9cffb01481 100644 --- a/encodings/datetime-parts/src/compute/cast.rs +++ b/encodings/datetime-parts/src/compute/cast.rs @@ -11,6 +11,7 @@ use vortex_error::VortexResult; use crate::DateTimeParts; use crate::DateTimePartsArray; +use std::sync::Arc; impl CastReduce for DateTimeParts { fn cast(array: &DateTimePartsArray, dtype: &DType) -> VortexResult> { @@ -24,8 +25,8 @@ impl CastReduce for DateTimeParts { array .days() .cast(array.days().dtype().with_nullability(dtype.nullability()))?, - array.seconds().clone(), - array.subseconds().clone(), + Arc::clone(&array.seconds()), + Arc::clone(&array.subseconds()), )? .into_array(), )) diff --git a/encodings/datetime-parts/src/compute/mask.rs b/encodings/datetime-parts/src/compute/mask.rs index 686d63ef1bd..bd3ea479552 100644 --- a/encodings/datetime-parts/src/compute/mask.rs +++ b/encodings/datetime-parts/src/compute/mask.rs @@ -10,6 +10,7 @@ use vortex_error::VortexResult; use crate::DateTimeParts; use crate::DateTimePartsArray; use crate::DateTimePartsArrayParts; +use std::sync::Arc; impl MaskReduce for DateTimeParts { fn mask(array: &DateTimePartsArray, mask: &ArrayRef) -> VortexResult> { @@ -19,7 +20,7 @@ impl MaskReduce for DateTimeParts { seconds, subseconds, } = array.clone().into_parts(); - let masked_days = days.mask(mask.clone())?; + let masked_days = days.mask(Arc::clone(&mask))?; Ok(Some( DateTimePartsArray::try_new(dtype.as_nullable(), masked_days, seconds, subseconds)? .into_array(), diff --git a/encodings/datetime-parts/src/compute/rules.rs b/encodings/datetime-parts/src/compute/rules.rs index 730324bff5b..1adc24e0a3b 100644 --- a/encodings/datetime-parts/src/compute/rules.rs +++ b/encodings/datetime-parts/src/compute/rules.rs @@ -28,6 +28,7 @@ use vortex_error::VortexResult; use crate::DateTimeParts; use crate::DateTimePartsArray; use crate::timestamp; +use std::sync::Arc; pub(crate) const PARENT_RULES: ParentRuleSet = ParentRuleSet::new(&[ ParentRuleSet::lift(&DTPFilterPushDownRule), @@ -60,7 +61,7 @@ impl ArrayParentReduceRule for DTPFilterPushDownRule { DateTimePartsArray::try_new( child.dtype().clone(), - child.days().clone().filter(parent.filter_mask().clone())?, + Arc::clone(&child.days()).filter(parent.filter_mask().clone())?, ConstantArray::new( child.seconds().as_constant().vortex_expect("constant"), parent.filter_mask().true_count(), @@ -120,7 +121,7 @@ impl ArrayParentReduceRule for DTPComparisonPushDownRule { for (idx, c) in parent.iter_children().enumerate() { if idx == child_idx { // This is the DTP child - replace with days - new_children.push(days.clone()); + new_children.push(Arc::clone(&days)); } else { // Must be a constant timestamp at midnight let Some(days_value) = try_extract_days_constant(c) else { diff --git a/encodings/decimal-byte-parts/src/decimal_byte_parts/compute/mask.rs b/encodings/decimal-byte-parts/src/decimal_byte_parts/compute/mask.rs index 152c8b7e11c..96aebb2e7df 100644 --- a/encodings/decimal-byte-parts/src/decimal_byte_parts/compute/mask.rs +++ b/encodings/decimal-byte-parts/src/decimal_byte_parts/compute/mask.rs @@ -11,13 +11,14 @@ use vortex_error::VortexResult; use crate::DecimalByteParts; use crate::DecimalBytePartsArray; +use std::sync::Arc; impl MaskReduce for DecimalByteParts { fn mask(array: &DecimalBytePartsArray, mask: &ArrayRef) -> VortexResult> { let masked_msp = MaskExpr.try_new_array( array.msp().len(), EmptyOptions, - [array.msp().clone(), mask.clone()], + [Arc::clone(&array.msp()), Arc::clone(&mask)], )?; Ok(Some( DecimalBytePartsArray::try_new(masked_msp, *array.decimal_dtype())?.into_array(), diff --git a/encodings/decimal-byte-parts/src/decimal_byte_parts/mod.rs b/encodings/decimal-byte-parts/src/decimal_byte_parts/mod.rs index 7df75061673..4cd1aada42f 100644 --- a/encodings/decimal-byte-parts/src/decimal_byte_parts/mod.rs +++ b/encodings/decimal-byte-parts/src/decimal_byte_parts/mod.rs @@ -291,7 +291,7 @@ fn to_canonical_decimal( ctx: &mut ExecutionCtx, ) -> VortexResult { // TODO(joe): support parts len != 1 - let prim = array.msp().clone().execute::(ctx)?; + let prim = Arc::clone(&array.msp()).execute::(ctx)?; // Depending on the decimal type and the min/max of the primitive array we can choose // the correct buffer size diff --git a/encodings/fastlanes/benches/compute_between.rs b/encodings/fastlanes/benches/compute_between.rs index 48cbae73216..4eea9cef461 100644 --- a/encodings/fastlanes/benches/compute_between.rs +++ b/encodings/fastlanes/benches/compute_between.rs @@ -14,6 +14,7 @@ use vortex_array::arrays::PrimitiveArray; use vortex_array::dtype::NativePType; use vortex_error::VortexExpect; use vortex_fastlanes::bitpack_compress::bitpack_to_best_bit_width; +use std::sync::Arc; fn main() { divan::main(); @@ -227,7 +228,7 @@ mod bitpack { bencher .with_inputs(|| (&arr, LEGACY_SESSION.create_execution_ctx())) .bench_refs(|(arr, ctx)| { - arr.clone() + Arc::clone(&arr) .between( ConstantArray::new(min, arr.len()).into_array(), ConstantArray::new(max, arr.len()).into_array(), @@ -318,7 +319,7 @@ mod alp { bencher .with_inputs(|| (&arr, LEGACY_SESSION.create_execution_ctx())) .bench_refs(|(arr, ctx)| { - arr.clone() + Arc::clone(&arr) .between( ConstantArray::new(min, arr.len()).into_array(), ConstantArray::new(max, arr.len()).into_array(), diff --git a/encodings/fastlanes/src/bitpacking/array/bitpack_compress.rs b/encodings/fastlanes/src/bitpacking/array/bitpack_compress.rs index e56f39633f5..6084dcb9f78 100644 --- a/encodings/fastlanes/src/bitpacking/array/bitpack_compress.rs +++ b/encodings/fastlanes/src/bitpacking/array/bitpack_compress.rs @@ -25,6 +25,7 @@ use vortex_mask::Mask; use crate::BitPackedArray; use crate::bitpack_decompress; +use std::sync::Arc; pub fn bitpack_to_best_bit_width(array: &PrimitiveArray) -> VortexResult { let bit_width_freq = bit_width_histogram(array)?; @@ -488,7 +489,7 @@ mod test { .collect::>(); let chunked = ChunkedArray::from_iter(chunks).into_array(); - let into_ca = chunked.clone().to_primitive(); + let into_ca = Arc::clone(&chunked).to_primitive(); let mut primitive_builder = PrimitiveBuilder::::with_capacity(chunked.dtype().nullability(), 10 * 100); chunked diff --git a/encodings/fastlanes/src/bitpacking/array/bitpack_decompress.rs b/encodings/fastlanes/src/bitpacking/array/bitpack_decompress.rs index 372ac81af52..fd5102ee5e8 100644 --- a/encodings/fastlanes/src/bitpacking/array/bitpack_decompress.rs +++ b/encodings/fastlanes/src/bitpacking/array/bitpack_decompress.rs @@ -19,6 +19,7 @@ use vortex_error::VortexResult; use crate::BitPackedArray; use crate::unpack_iter::BitPacked; +use std::sync::Arc; /// Unpacks a bit-packed array into a primitive array. pub fn unpack_array( @@ -93,8 +94,8 @@ pub fn apply_patches_to_uninit_range_fn T>( ) -> VortexResult<()> { assert_eq!(patches.array_len(), dst.len()); - let indices = patches.indices().clone().execute::(ctx)?; - let values = patches.values().clone().execute::(ctx)?; + let indices = Arc::clone(&patches.indices()).execute::(ctx)?; + let values = Arc::clone(&patches.values()).execute::(ctx)?; assert!(values.all_valid()?, "Patch values must be all valid"); let values = values.as_slice::(); @@ -554,7 +555,7 @@ mod tests { let unpacked_array = sliced; let executed = { let mut ctx = SESSION.create_execution_ctx(); - slice_ref.clone().execute::(&mut ctx).unwrap() + Arc::clone(&slice_ref).execute::(&mut ctx).unwrap() }; assert_eq!( diff --git a/encodings/fastlanes/src/bitpacking/array/mod.rs b/encodings/fastlanes/src/bitpacking/array/mod.rs index a0e5067ea3e..780e5814043 100644 --- a/encodings/fastlanes/src/bitpacking/array/mod.rs +++ b/encodings/fastlanes/src/bitpacking/array/mod.rs @@ -17,6 +17,7 @@ use vortex_error::VortexExpect; use vortex_error::VortexResult; use vortex_error::vortex_bail; use vortex_error::vortex_ensure; +use std::sync::Arc; pub mod bitpack_compress; pub mod bitpack_decompress; @@ -124,8 +125,8 @@ impl BitPackedArray { ) -> Vec> { let (pi, pv, pco) = match patches { Some(p) => ( - Some(p.indices().clone()), - Some(p.values().clone()), + Some(Arc::clone(&p.indices())), + Some(Arc::clone(&p.values())), p.chunk_offsets().clone(), ), None => (None, None, None), @@ -303,8 +304,8 @@ impl BitPackedArray { Patches::new_unchecked( self.len, patch_offset, - indices.clone(), - values.clone(), + Arc::clone(&indices), + Arc::clone(&values), self.slots[PATCH_CHUNK_OFFSETS_SLOT].clone(), self.patch_offset_within_chunk, ) @@ -322,8 +323,8 @@ impl BitPackedArray { pub fn replace_patches(&mut self, patches: Option) { let (pi, pv, pco) = match &patches { Some(p) => ( - Some(p.indices().clone()), - Some(p.values().clone()), + Some(Arc::clone(&p.indices())), + Some(Arc::clone(&p.values())), p.chunk_offsets().clone(), ), None => (None, None, None), diff --git a/encodings/fastlanes/src/bitpacking/compute/cast.rs b/encodings/fastlanes/src/bitpacking/compute/cast.rs index 1480f24a18f..a041efd3cf7 100644 --- a/encodings/fastlanes/src/bitpacking/compute/cast.rs +++ b/encodings/fastlanes/src/bitpacking/compute/cast.rs @@ -11,6 +11,7 @@ use vortex_error::VortexResult; use crate::bitpacking::BitPacked; use crate::bitpacking::BitPackedArray; +use std::sync::Arc; impl CastReduce for BitPacked { fn cast(array: &BitPackedArray, dtype: &DType) -> VortexResult> { @@ -30,7 +31,7 @@ impl CastReduce for BitPacked { Patches::new( patches.array_len(), patches.offset(), - patches.indices().clone(), + Arc::clone(&patches.indices()), new_values, patches.chunk_offsets().clone(), ) diff --git a/encodings/fastlanes/src/bitpacking/compute/filter.rs b/encodings/fastlanes/src/bitpacking/compute/filter.rs index 69452e02568..d679f7c6163 100644 --- a/encodings/fastlanes/src/bitpacking/compute/filter.rs +++ b/encodings/fastlanes/src/bitpacking/compute/filter.rs @@ -70,7 +70,7 @@ impl FilterKernel for BitPacked { let patches = array .patches() - .map(|patches| patches.filter(&Mask::Values(values.clone()), ctx)) + .map(|patches| patches.filter(&Mask::Values(Arc::clone(&values)), ctx)) .transpose()? .flatten(); @@ -98,7 +98,7 @@ fn filter_primitive_without_patches( selection: &Arc, ) -> VortexResult<(Buffer, Validity)> { let values = filter_with_indices(array, selection.indices()); - let validity = array.validity().filter(&Mask::Values(selection.clone()))?; + let validity = array.validity().filter(&Mask::Values(Arc::clone(&selection)))?; Ok((values.freeze(), validity)) } diff --git a/encodings/fastlanes/src/bitpacking/compute/take.rs b/encodings/fastlanes/src/bitpacking/compute/take.rs index 9e9289ce133..688e77b4f07 100644 --- a/encodings/fastlanes/src/bitpacking/compute/take.rs +++ b/encodings/fastlanes/src/bitpacking/compute/take.rs @@ -26,6 +26,7 @@ use super::chunked_indices; use crate::BitPacked; use crate::BitPackedArray; use crate::bitpack_decompress; +use std::sync::Arc; // TODO(connor): This is duplicated in `encodings/fastlanes/src/bitpacking/kernels/mod.rs`. /// assuming the buffer is already allocated (which will happen at most once) then unpacking @@ -51,7 +52,7 @@ impl TakeExecute for BitPacked { let validity = array.validity(); let taken_validity = validity.take(indices)?; - let indices = indices.clone().execute::(ctx)?; + let indices = Arc::clone(&indices).execute::(ctx)?; let taken = match_each_unsigned_integer_ptype!(ptype.to_unsigned(), |T| { match_each_integer_ptype!(indices.ptype(), |I| { take_primitive::(array, &indices, taken_validity, ctx)? diff --git a/encodings/fastlanes/src/bitpacking/vtable/operations.rs b/encodings/fastlanes/src/bitpacking/vtable/operations.rs index fd91f98260c..cd3f66b5bbc 100644 --- a/encodings/fastlanes/src/bitpacking/vtable/operations.rs +++ b/encodings/fastlanes/src/bitpacking/vtable/operations.rs @@ -9,6 +9,7 @@ use vortex_error::VortexResult; use crate::BitPacked; use crate::BitPackedArray; use crate::bitpack_decompress; +use std::sync::Arc; impl OperationsVTable for BitPacked { fn scalar_at( @@ -55,7 +56,7 @@ mod test { fn slice_via_reduce(array: &BitPackedArray, range: Range) -> BitPackedArray { let array_ref = array.clone().into_array(); - let slice_array = SliceArray::new(array_ref.clone(), range); + let slice_array = SliceArray::new(Arc::clone(&array_ref), range); let sliced = array_ref .vtable() .reduce_parent(&array_ref, &slice_array.into_array(), 0) @@ -144,7 +145,7 @@ mod test { assert!(array.patches().is_some()); - let patch_indices = array.patches().unwrap().indices().clone(); + let patch_indices = Arc::clone(&array.patches().unwrap().indices()); assert_eq!(patch_indices.len(), 1); // Slicing drops the empty patches array. @@ -216,7 +217,7 @@ mod test { let packed = BitPackedArray::encode(&uncompressed, 8).unwrap(); assert!(packed.patches().is_some()); - let patches = packed.patches().unwrap().indices().clone(); + let patches = Arc::clone(&packed.patches().unwrap().indices()); assert_eq!( usize::try_from(&patches.scalar_at(0).unwrap()).unwrap(), 256 diff --git a/encodings/fastlanes/src/delta/array/delta_decompress.rs b/encodings/fastlanes/src/delta/array/delta_decompress.rs index 9ac446a92fc..393549d0ef1 100644 --- a/encodings/fastlanes/src/delta/array/delta_decompress.rs +++ b/encodings/fastlanes/src/delta/array/delta_decompress.rs @@ -18,13 +18,14 @@ use vortex_error::VortexResult; use crate::DeltaArray; use crate::bit_transpose::untranspose_validity; +use std::sync::Arc; pub fn delta_decompress( array: &DeltaArray, ctx: &mut ExecutionCtx, ) -> VortexResult { - let bases = array.bases().clone().execute::(ctx)?; - let deltas = array.deltas().clone().execute::(ctx)?; + let bases = Arc::clone(&array.bases()).execute::(ctx)?; + let deltas = Arc::clone(&array.deltas()).execute::(ctx)?; let start = array.offset(); let end = start + array.len(); diff --git a/encodings/fastlanes/src/for/array/for_decompress.rs b/encodings/fastlanes/src/for/array/for_decompress.rs index d7633481b74..c7dad541d9f 100644 --- a/encodings/fastlanes/src/for/array/for_decompress.rs +++ b/encodings/fastlanes/src/for/array/for_decompress.rs @@ -22,6 +22,7 @@ use crate::FoRArray; use crate::bitpack_decompress; use crate::unpack_iter::UnpackStrategy; use crate::unpack_iter::UnpackedChunks; +use std::sync::Arc; /// FoR unpacking strategy that applies a reference value during unpacking. struct FoRStrategy { @@ -56,7 +57,7 @@ pub fn decompress(array: &FoRArray, ctx: &mut ExecutionCtx) -> VortexResult(ctx)?; + let encoded = Arc::clone(&array.encoded()).execute::(ctx)?; let validity = encoded.validity(); Ok(match_each_integer_ptype!(ptype, |T| { diff --git a/encodings/fastlanes/src/rle/array/mod.rs b/encodings/fastlanes/src/rle/array/mod.rs index 02282602dd6..ff75c951e7a 100644 --- a/encodings/fastlanes/src/rle/array/mod.rs +++ b/encodings/fastlanes/src/rle/array/mod.rs @@ -11,6 +11,7 @@ use vortex_error::VortexResult; use vortex_error::vortex_ensure; use crate::FL_CHUNK_SIZE; +use std::sync::Arc; pub mod rle_compress; pub mod rle_decompress; @@ -280,7 +281,7 @@ mod tests { .into_array(); let rle_array = RLEArray::try_new( - values.clone(), + Arc::clone(&values), indices_with_validity, values_idx_offsets, 0, @@ -316,7 +317,7 @@ mod tests { .into_array(); let rle_array = RLEArray::try_new( - values.clone(), + Arc::clone(&values), indices_with_validity, values_idx_offsets, 0, @@ -353,7 +354,7 @@ mod tests { .into_array(); let rle_array = RLEArray::try_new( - values.clone(), + Arc::clone(&values), indices_with_validity, values_idx_offsets, 0, @@ -395,7 +396,7 @@ mod tests { .into_array(); let rle_array = RLEArray::try_new( - values.clone(), + Arc::clone(&values), indices_with_validity, values_idx_offsets, 0, @@ -423,7 +424,7 @@ mod tests { let values_idx_offsets = PrimitiveArray::from_iter(Vec::::new()).into_array(); let rle_array = RLEArray::try_new( values, - indices.clone(), + Arc::clone(&indices), values_idx_offsets, 0, indices.len(), @@ -489,9 +490,9 @@ mod tests { let rle_array = RLEArray::encode(&primitive).unwrap(); let sliced = RLEArray::try_new( - rle_array.values().clone(), - rle_array.indices().clone(), - rle_array.values_idx_offsets().clone(), + Arc::clone(&rle_array.values()), + Arc::clone(&rle_array.indices()), + Arc::clone(&rle_array.values_idx_offsets()), 100, 100, ) @@ -556,9 +557,9 @@ mod tests { // SAFETY: we only replace the indices child; all other invariants hold. let reconstructed = unsafe { RLEArray::new_unchecked( - rle.values().clone(), + Arc::clone(&rle.values()), re_encoded.into_array(), - rle.values_idx_offsets().clone(), + Arc::clone(&rle.values_idx_offsets()), rle.dtype().clone(), rle.offset(), rle.len(), diff --git a/encodings/fastlanes/src/rle/array/rle_compress.rs b/encodings/fastlanes/src/rle/array/rle_compress.rs index 9c0feb8291d..300f870e2fe 100644 --- a/encodings/fastlanes/src/rle/array/rle_compress.rs +++ b/encodings/fastlanes/src/rle/array/rle_compress.rs @@ -17,6 +17,7 @@ use vortex_error::VortexResult; use crate::FL_CHUNK_SIZE; use crate::RLEArray; use crate::fill_forward_nulls; +use std::sync::Arc; impl RLEArray { /// Encodes a primitive array of unsigned integers using FastLanes RLE. @@ -117,7 +118,7 @@ fn padded_validity(array: &PrimitiveArray) -> Validity { let padded_len = len.next_multiple_of(FL_CHUNK_SIZE); if len == padded_len { - return Validity::Array(validity_array.clone()); + return Validity::Array(Arc::clone(&validity_array)); } let mut builder = BitBufferMut::with_capacity(padded_len); diff --git a/encodings/fastlanes/src/rle/array/rle_decompress.rs b/encodings/fastlanes/src/rle/array/rle_decompress.rs index 4bd5ac276ec..8a92a1f7d46 100644 --- a/encodings/fastlanes/src/rle/array/rle_decompress.rs +++ b/encodings/fastlanes/src/rle/array/rle_decompress.rs @@ -19,6 +19,7 @@ use vortex_error::vortex_panic; use crate::FL_CHUNK_SIZE; use crate::RLEArray; +use std::sync::Arc; /// Decompresses an RLE array back into a primitive array. #[expect( @@ -51,10 +52,10 @@ where I: NativePType + Into, O: NativePType + AsPrimitive, { - let values = array.values().clone().execute::(ctx)?; + let values = Arc::clone(&array.values()).execute::(ctx)?; let values = values.as_slice::(); - let indices = array.indices().clone().execute::(ctx)?; + let indices = Arc::clone(&array.indices()).execute::(ctx)?; let indices = indices.as_slice::(); assert!(indices.len().is_multiple_of(FL_CHUNK_SIZE)); diff --git a/encodings/fastlanes/src/rle/compute/cast.rs b/encodings/fastlanes/src/rle/compute/cast.rs index fca72d5afce..cf549249d29 100644 --- a/encodings/fastlanes/src/rle/compute/cast.rs +++ b/encodings/fastlanes/src/rle/compute/cast.rs @@ -10,6 +10,7 @@ use vortex_error::VortexResult; use crate::rle::RLE; use crate::rle::RLEArray; +use std::sync::Arc; impl CastReduce for RLE { fn cast(array: &RLEArray, dtype: &DType) -> VortexResult> { @@ -23,14 +24,14 @@ impl CastReduce for RLE { dtype.nullability(), ))? } else { - array.indices().clone() + Arc::clone(&array.indices()) }; Ok(Some(unsafe { RLEArray::new_unchecked( casted_values, casted_indices, - array.values_idx_offsets().clone(), + Arc::clone(&array.values_idx_offsets()), dtype.clone(), array.offset(), array.len(), diff --git a/encodings/fastlanes/src/rle/vtable/operations.rs b/encodings/fastlanes/src/rle/vtable/operations.rs index 9f00432c727..ec3355a5b95 100644 --- a/encodings/fastlanes/src/rle/vtable/operations.rs +++ b/encodings/fastlanes/src/rle/vtable/operations.rs @@ -10,6 +10,7 @@ use vortex_error::VortexResult; use super::RLE; use crate::FL_CHUNK_SIZE; use crate::RLEArray; +use std::sync::Arc; impl OperationsVTable for RLE { fn scalar_at(array: &RLEArray, index: usize, _ctx: &mut ExecutionCtx) -> VortexResult { @@ -62,7 +63,7 @@ mod tests { RLEArray::try_new( values, - indices.clone(), + Arc::clone(&indices), values_idx_offsets, 0, indices.len(), @@ -97,7 +98,7 @@ mod tests { RLEArray::try_new( values, - indices.clone(), + Arc::clone(&indices), values_idx_offsets, 0, indices.len(), diff --git a/encodings/fsst/benches/fsst_like.rs b/encodings/fsst/benches/fsst_like.rs index 12e78e2d7fb..d18d104c00d 100644 --- a/encodings/fsst/benches/fsst_like.rs +++ b/encodings/fsst/benches/fsst_like.rs @@ -25,6 +25,7 @@ use vortex_fsst::test_utils::make_fsst_log_lines; use vortex_fsst::test_utils::make_fsst_rare_match; use vortex_fsst::test_utils::make_fsst_short_urls; use vortex_session::VortexSession; +use std::sync::Arc; fn main() { divan::main(); @@ -110,7 +111,7 @@ fn bench_like(bencher: Bencher, fsst: &FSSTArray, pattern: &str) { let arr = fsst.clone().into_array(); let pattern = ConstantArray::new(pattern, len).into_array(); bencher.bench_local(|| { - Like.try_new_array(len, LikeOptions::default(), [arr.clone(), pattern.clone()]) + Like.try_new_array(len, LikeOptions::default(), [Arc::clone(&arr), Arc::clone(&pattern)]) .unwrap() .into_array() .execute::(&mut SESSION.create_execution_ctx()) diff --git a/encodings/fsst/src/array.rs b/encodings/fsst/src/array.rs index c716ebc68d2..f2b85ceb907 100644 --- a/encodings/fsst/src/array.rs +++ b/encodings/fsst/src/array.rs @@ -310,7 +310,7 @@ impl VTable for FSST { .clone() .vortex_expect("FSSTArray requires codes_offsets slot"); let codes_validity = match &slots[CODES_VALIDITY_SLOT] { - Some(arr) => Validity::Array(arr.clone()), + Some(arr) => Validity::Array(Arc::clone(&arr)), None => Validity::from(array.codes.dtype().nullability()), }; array.codes = VarBinArray::try_new_from_handle( @@ -454,7 +454,7 @@ impl FSSTArray { }) as Box Compressor + Send>)); let codes_array = codes.clone().into_array(); - let codes_offsets_slot = Some(codes.offsets().clone()); + let codes_offsets_slot = Some(Arc::clone(&codes.offsets())); let codes_validity_slot = validity_to_child(&codes.validity(), codes.len()); Self { @@ -599,7 +599,7 @@ mod test { // 2. The uncompressed lengths, stored as a Primitive array. let children = vec![ compressed_codes.into_array(), - fsst_array.uncompressed_lengths().clone(), + Arc::clone(&fsst_array.uncompressed_lengths()), ]; let fsst = FSST::build( diff --git a/encodings/fsst/src/compute/cast.rs b/encodings/fsst/src/compute/cast.rs index e21934665c6..9d6845a1038 100644 --- a/encodings/fsst/src/compute/cast.rs +++ b/encodings/fsst/src/compute/cast.rs @@ -11,6 +11,7 @@ use vortex_error::VortexResult; use crate::FSST; use crate::FSSTArray; +use std::sync::Arc; impl CastReduce for FSST { fn cast(array: &FSSTArray, dtype: &DType) -> VortexResult> { @@ -30,7 +31,7 @@ impl CastReduce for FSST { array.symbols().clone(), array.symbol_lengths().clone(), new_codes.as_::().clone(), - array.uncompressed_lengths().clone(), + Arc::clone(&array.uncompressed_lengths()), )? .into_array(), )) diff --git a/encodings/fsst/src/kernel.rs b/encodings/fsst/src/kernel.rs index 3ec36dd1b32..a1fc171424a 100644 --- a/encodings/fsst/src/kernel.rs +++ b/encodings/fsst/src/kernel.rs @@ -8,6 +8,7 @@ use vortex_array::scalar_fn::fns::binary::CompareExecuteAdaptor; use vortex_array::scalar_fn::fns::like::LikeExecuteAdaptor; use crate::FSST; +use std::sync::Arc; pub(super) const PARENT_KERNELS: ParentKernelSet = ParentKernelSet::new(&[ ParentKernelSet::lift(&CompareExecuteAdaptor(FSST)), @@ -72,7 +73,7 @@ mod tests { ]); // Create FilterArray and execute - let filter_array = FilterArray::new(fsst_array.clone(), mask.clone()).into_array(); + let filter_array = FilterArray::new(Arc::clone(&fsst_array), mask.clone()).into_array(); let mut ctx = SESSION.create_execution_ctx(); let result = filter_array.execute::(&mut ctx)?; @@ -93,7 +94,7 @@ mod tests { true, false, true, false, true, false, true, false, true, false, ]); - let filter_array = FilterArray::new(fsst_array.clone(), mask.clone()).into_array(); + let filter_array = FilterArray::new(Arc::clone(&fsst_array), mask.clone()).into_array(); let mut ctx = SESSION.create_execution_ctx(); let result = filter_array.execute::(&mut ctx)?; @@ -137,7 +138,7 @@ mod tests { mask.push(true); let mask = Mask::from_iter(mask); - let filter_array = FilterArray::new(fsst_array.clone(), mask.clone()).into_array(); + let filter_array = FilterArray::new(Arc::clone(&fsst_array), mask.clone()).into_array(); let mut ctx = SESSION.create_execution_ctx(); let result = filter_array.execute::(&mut ctx)?; @@ -162,7 +163,7 @@ mod tests { let mask = Mask::from_iter([true, false, true]); - let filter_array = FilterArray::new(fsst_array.clone(), mask.clone()).into_array(); + let filter_array = FilterArray::new(Arc::clone(&fsst_array), mask.clone()).into_array(); let mut ctx = SESSION.create_execution_ctx(); let result = filter_array.execute::(&mut ctx)?; diff --git a/encodings/parquet-variant/src/array.rs b/encodings/parquet-variant/src/array.rs index c886fddc660..4b7dc10f7bd 100644 --- a/encodings/parquet-variant/src/array.rs +++ b/encodings/parquet-variant/src/array.rs @@ -181,7 +181,7 @@ impl ParquetVariantArray { let mut fields = Vec::with_capacity(3); let mut arrays: Vec = Vec::with_capacity(3); - let metadata_arrow = metadata.clone().execute_arrow(None, ctx)?; + let metadata_arrow = Arc::clone(&metadata).execute_arrow(None, ctx)?; fields.push(Arc::new(Field::new( "metadata", metadata_arrow.data_type().clone(), @@ -190,7 +190,7 @@ impl ParquetVariantArray { arrays.push(metadata_arrow); if let Some(value) = self.value_array() { - let value_arrow = value.clone().execute_arrow(None, ctx)?; + let value_arrow = Arc::clone(&value).execute_arrow(None, ctx)?; fields.push(Arc::new(Field::new( "value", value_arrow.data_type().clone(), @@ -200,7 +200,7 @@ impl ParquetVariantArray { } if let Some(typed_value) = self.typed_value_array() { - let tv_arrow = typed_value.clone().execute_arrow(None, ctx)?; + let tv_arrow = Arc::clone(&typed_value).execute_arrow(None, ctx)?; fields.push(Arc::new(Field::new( "typed_value", tv_arrow.data_type().clone(), diff --git a/encodings/parquet-variant/src/vtable.rs b/encodings/parquet-variant/src/vtable.rs index 7023121313a..efbe946842c 100644 --- a/encodings/parquet-variant/src/vtable.rs +++ b/encodings/parquet-variant/src/vtable.rs @@ -278,7 +278,7 @@ impl VTable for ParquetVariant { ); // Update validity from the validity slot. if let Some(validity_child) = &slots[VALIDITY_SLOT] { - array.validity = Validity::Array(validity_child.clone()); + array.validity = Validity::Array(Arc::clone(&validity_child)); } array.slots = slots; Ok(()) @@ -374,7 +374,7 @@ mod tests { ) .unwrap(); let array = outer_pv.into_array(); - let decoded = roundtrip(array.clone()); + let decoded = roundtrip(Arc::clone(&array)); assert!(array.array_eq(&decoded, Precision::Value)); let decoded_pv = decoded.as_opt::().unwrap(); @@ -391,7 +391,7 @@ mod tests { let pv = ParquetVariantArray::try_new(validity, metadata, Some(value), None).unwrap(); let array = pv.into_array(); - let decoded = roundtrip(array.clone()); + let decoded = roundtrip(Arc::clone(&array)); assert!(array.array_eq(&decoded, Precision::Value)); assert_eq!(decoded.dtype(), &DType::Variant(Nullability::Nullable)); @@ -414,7 +414,7 @@ mod tests { ) .unwrap(); let array = outer_pv.into_array(); - let decoded = roundtrip(array.clone()); + let decoded = roundtrip(Arc::clone(&array)); assert!(array.array_eq(&decoded, Precision::Value)); let decoded_pv = decoded.as_opt::().unwrap(); diff --git a/encodings/pco/src/array.rs b/encodings/pco/src/array.rs index 2859e878afb..d46677a8313 100644 --- a/encodings/pco/src/array.rs +++ b/encodings/pco/src/array.rs @@ -250,7 +250,7 @@ impl VTable for Pco { slots.len() ); array.unsliced_validity = match &slots[VALIDITY_SLOT] { - Some(arr) => Validity::Array(arr.clone()), + Some(arr) => Validity::Array(Arc::clone(&arr)), None => Validity::from(array.dtype.nullability()), }; array.slots = slots; diff --git a/encodings/runend/benches/run_end_compress.rs b/encodings/runend/benches/run_end_compress.rs index bac8175b37a..4cec872f3bf 100644 --- a/encodings/runend/benches/run_end_compress.rs +++ b/encodings/runend/benches/run_end_compress.rs @@ -16,6 +16,7 @@ use vortex_array::validity::Validity; use vortex_buffer::Buffer; use vortex_runend::RunEndArray; use vortex_runend::compress::runend_encode; +use std::sync::Arc; fn main() { divan::main(); @@ -68,7 +69,7 @@ fn decompress(bencher: Bencher, (length, run_step): (usize, usi let array = run_end_array.into_array(); bencher - .with_inputs(|| (array.clone(), LEGACY_SESSION.create_execution_ctx())) + .with_inputs(|| (Arc::clone(&array), LEGACY_SESSION.create_execution_ctx())) .bench_values(|(array, mut execution_ctx)| { array .execute::(&mut execution_ctx) @@ -125,7 +126,7 @@ fn decompress_utf8(bencher: Bencher, (length, run_step): (usize, usize)) { let array = run_end_array.into_array(); bencher - .with_inputs(|| (array.clone(), LEGACY_SESSION.create_execution_ctx())) + .with_inputs(|| (Arc::clone(&array), LEGACY_SESSION.create_execution_ctx())) .bench_values(|(array, mut execution_ctx)| { array .execute::(&mut execution_ctx) diff --git a/encodings/runend/src/array.rs b/encodings/runend/src/array.rs index edba8a0f219..0c96a0ceeea 100644 --- a/encodings/runend/src/array.rs +++ b/encodings/runend/src/array.rs @@ -469,7 +469,7 @@ impl ValidityVTable for RunEnd { Validity::AllInvalid => Validity::AllInvalid, Validity::Array(values_validity) => Validity::Array(unsafe { RunEndArray::new_unchecked( - array.ends().clone(), + Arc::clone(&array.ends()), values_validity, array.offset(), array.len(), @@ -484,15 +484,15 @@ pub(super) fn run_end_canonicalize( array: &RunEndArray, ctx: &mut ExecutionCtx, ) -> VortexResult { - let pends = array.ends().clone().execute_as("ends", ctx)?; + let pends = Arc::clone(&array.ends()).execute_as("ends", ctx)?; Ok(match array.dtype() { DType::Bool(_) => { - let bools = array.values().clone().execute_as("values", ctx)?; + let bools = Arc::clone(&array.values()).execute_as("values", ctx)?; runend_decode_bools(pends, bools, array.offset(), array.len())? } DType::Primitive(..) => { - let pvalues = array.values().clone().execute_as("values", ctx)?; + let pvalues = Arc::clone(&array.values()).execute_as("values", ctx)?; runend_decode_primitive(pends, pvalues, array.offset(), array.len())?.into_array() } DType::Utf8(_) | DType::Binary(_) => { diff --git a/encodings/runend/src/compute/cast.rs b/encodings/runend/src/compute/cast.rs index d106c2e86aa..8ee649f8a55 100644 --- a/encodings/runend/src/compute/cast.rs +++ b/encodings/runend/src/compute/cast.rs @@ -10,6 +10,7 @@ use vortex_error::VortexResult; use crate::RunEnd; use crate::RunEndArray; +use std::sync::Arc; impl CastReduce for RunEnd { fn cast(array: &RunEndArray, dtype: &DType) -> VortexResult> { @@ -20,7 +21,7 @@ impl CastReduce for RunEnd { unsafe { Ok(Some( RunEndArray::new_unchecked( - array.ends().clone(), + Arc::clone(&array.ends()), casted_values, array.offset(), array.len(), diff --git a/encodings/runend/src/compute/compare.rs b/encodings/runend/src/compute/compare.rs index 9601d0502d8..24749fc6c6a 100644 --- a/encodings/runend/src/compute/compare.rs +++ b/encodings/runend/src/compute/compare.rs @@ -17,6 +17,7 @@ use vortex_error::VortexResult; use crate::RunEnd; use crate::RunEndArray; use crate::decompress_bool::runend_decode_bools; +use std::sync::Arc; impl CompareKernel for RunEnd { fn compare( @@ -32,7 +33,7 @@ impl CompareKernel for RunEnd { Operator::from(operator), )?; return runend_decode_bools( - lhs.ends().clone().execute::(ctx)?, + Arc::clone(&lhs.ends()).execute::(ctx)?, values.execute::(ctx)?, lhs.offset(), lhs.len(), diff --git a/encodings/runend/src/compute/filter.rs b/encodings/runend/src/compute/filter.rs index cf6f6043de9..b1a1d7ef6fe 100644 --- a/encodings/runend/src/compute/filter.rs +++ b/encodings/runend/src/compute/filter.rs @@ -22,6 +22,7 @@ use vortex_mask::Mask; use crate::RunEnd; use crate::RunEndArray; use crate::compute::take::take_indices_unchecked; +use std::sync::Arc; const FILTER_TAKE_THRESHOLD: f64 = 0.1; @@ -44,7 +45,7 @@ impl FilterKernel for RunEnd { &Validity::NonNullable, )?)) } else { - let primitive_run_ends = array.ends().clone().execute::(ctx)?; + let primitive_run_ends = Arc::clone(&array.ends()).execute::(ctx)?; let (run_ends, values_mask) = match_each_unsigned_integer_ptype!(primitive_run_ends.ptype(), |P| { filter_run_end_primitive( diff --git a/encodings/runend/src/compute/take.rs b/encodings/runend/src/compute/take.rs index f07a44cd3af..4001f67a473 100644 --- a/encodings/runend/src/compute/take.rs +++ b/encodings/runend/src/compute/take.rs @@ -21,6 +21,7 @@ use vortex_error::vortex_bail; use crate::RunEnd; use crate::RunEndArray; +use std::sync::Arc; impl TakeExecute for RunEnd { #[expect( @@ -32,7 +33,7 @@ impl TakeExecute for RunEnd { indices: &ArrayRef, ctx: &mut ExecutionCtx, ) -> VortexResult> { - let primitive_indices = indices.clone().execute::(ctx)?; + let primitive_indices = Arc::clone(&indices).execute::(ctx)?; let checked_indices = match_each_integer_ptype!(primitive_indices.ptype(), |P| { primitive_indices diff --git a/encodings/runend/src/compute/take_from.rs b/encodings/runend/src/compute/take_from.rs index 12cb415bd12..dca832e2f2f 100644 --- a/encodings/runend/src/compute/take_from.rs +++ b/encodings/runend/src/compute/take_from.rs @@ -12,6 +12,7 @@ use vortex_error::VortexResult; use crate::RunEnd; use crate::RunEndArray; +use std::sync::Arc; #[derive(Debug)] pub(crate) struct RunEndTakeFrom; @@ -39,8 +40,8 @@ impl ExecuteParentKernel for RunEndTakeFrom { // SAFETY: we are copying ends from an existing valid RunEndArray let ree_array = unsafe { RunEndArray::new_unchecked( - array.ends().clone(), - dict.values().take(array.values().clone())?, + Arc::clone(&array.ends()), + dict.values().take(Arc::clone(&array.values()))?, array.offset(), array.len(), ) @@ -99,8 +100,8 @@ mod tests { // Slice codes to positions 2..5 → logical codes [0, 1, 1] → values [2, 3, 3] let sliced_codes = unsafe { RunEndArray::new_unchecked( - codes.ends().clone(), - codes.values().clone(), + Arc::clone(&codes.ends()), + Arc::clone(&codes.values()), 2, // offset 3, // len ) @@ -122,8 +123,8 @@ mod tests { // Slice codes to positions 3..7 → logical codes [1, 1, 0, 0] → values [3, 3, 2, 2] let sliced_codes = unsafe { RunEndArray::new_unchecked( - codes.ends().clone(), - codes.values().clone(), + Arc::clone(&codes.ends()), + Arc::clone(&codes.values()), 3, // offset at exact run boundary 4, // len ) diff --git a/encodings/runend/src/rules.rs b/encodings/runend/src/rules.rs index 06f56fbafb3..f8ddb0f8acd 100644 --- a/encodings/runend/src/rules.rs +++ b/encodings/runend/src/rules.rs @@ -16,6 +16,7 @@ use vortex_error::VortexResult; use crate::RunEnd; use crate::RunEndArray; +use std::sync::Arc; pub(super) const RULES: ParentRuleSet = ParentRuleSet::new(&[ // CastReduceAdaptor must come before RunEndScalarFnRule so that cast operations are executed @@ -63,7 +64,7 @@ impl ArrayParentReduceRule for RunEndScalarFnRule { for (idx, child) in new_children.iter_mut().enumerate() { if idx == child_idx { // Replace ourselves with run end values - *child = run_end.values().clone(); + *child = Arc::clone(&run_end.values()); continue; } @@ -80,7 +81,7 @@ impl ArrayParentReduceRule for RunEndScalarFnRule { Ok(Some( unsafe { RunEndArray::new_unchecked( - run_end.ends().clone(), + Arc::clone(&run_end.ends()), new_values, run_end.offset(), run_end.len(), diff --git a/encodings/sequence/src/compute/take.rs b/encodings/sequence/src/compute/take.rs index 23b91cabc36..70512847b81 100644 --- a/encodings/sequence/src/compute/take.rs +++ b/encodings/sequence/src/compute/take.rs @@ -26,6 +26,7 @@ use vortex_mask::Mask; use crate::Sequence; use crate::SequenceArray; +use std::sync::Arc; fn take_inner( mul: S, @@ -79,7 +80,7 @@ impl TakeExecute for Sequence { ctx: &mut ExecutionCtx, ) -> VortexResult> { let mask = indices.validity_mask()?; - let indices = indices.clone().execute::(ctx)?; + let indices = Arc::clone(&indices).execute::(ctx)?; let result_nullability = array.dtype().nullability() | indices.dtype().nullability(); match_each_integer_ptype!(indices.ptype(), |T| { diff --git a/encodings/sparse/src/canonical.rs b/encodings/sparse/src/canonical.rs index 2e0f51843cd..bf38c6d5964 100644 --- a/encodings/sparse/src/canonical.rs +++ b/encodings/sparse/src/canonical.rs @@ -112,7 +112,7 @@ pub(super) fn execute_sparse( execute_varbin(array, dtype.clone(), fill_value, ctx)? } DType::List(values_dtype, nullability) => { - execute_sparse_lists(array, values_dtype.clone(), *nullability, ctx)? + execute_sparse_lists(array, Arc::clone(&values_dtype), *nullability, ctx)? } DType::FixedSizeList(.., nullability) => { execute_sparse_fixed_size_list(array, *nullability, ctx)? @@ -487,8 +487,8 @@ fn execute_varbin( ctx: &mut ExecutionCtx, ) -> VortexResult { let patches = array.resolved_patches()?; - let indices = patches.indices().clone().execute::(ctx)?; - let values = patches.values().clone().execute::(ctx)?; + let indices = Arc::clone(&patches.indices()).execute::(ctx)?; + let values = Arc::clone(&patches.values()).execute::(ctx)?; let validity = Validity::from_mask(array.validity_mask()?, dtype.nullability()); let len = array.len(); @@ -1466,7 +1466,7 @@ mod test { let sizes = buffer![3u32, 2, 4].into_array(); let list_view = unsafe { - ListViewArray::new_unchecked(elements.clone(), offsets, sizes, Validity::AllValid) + ListViewArray::new_unchecked(Arc::clone(&elements), offsets, sizes, Validity::AllValid) .with_zero_copy_to_list(true) }; diff --git a/encodings/sparse/src/lib.rs b/encodings/sparse/src/lib.rs index 52484cd9202..19a555eadb3 100644 --- a/encodings/sparse/src/lib.rs +++ b/encodings/sparse/src/lib.rs @@ -365,8 +365,8 @@ impl SparseArray { fn make_slots(patches: &Patches) -> Vec> { vec![ - Some(patches.indices().clone()), - Some(patches.values().clone()), + Some(Arc::clone(&patches.indices())), + Some(Arc::clone(&patches.values())), patches.chunk_offsets().clone(), ] } @@ -389,7 +389,7 @@ impl SparseArray { patches.array_len(), 0, indices, - patches.values().clone(), + Arc::clone(&patches.values()), // TODO(0ax1): handle chunk offsets None, ) @@ -468,7 +468,7 @@ impl SparseArray { let non_top_mask = Mask::from_buffer( array .to_array() - .binary(fill_array.clone(), Operator::NotEq)? + .binary(Arc::clone(&fill_array), Operator::NotEq)? .fill_null(Scalar::bool(true, Nullability::NonNullable))? .to_bool() .to_bit_buffer(), @@ -502,7 +502,7 @@ impl ValidityVTable for Sparse { Patches::new_unchecked( array.patches.array_len(), array.patches.offset(), - array.patches.indices().clone(), + Arc::clone(&array.patches.indices()), array .patches .values() diff --git a/encodings/zigzag/src/array.rs b/encodings/zigzag/src/array.rs index a417aae1af1..0866d815388 100644 --- a/encodings/zigzag/src/array.rs +++ b/encodings/zigzag/src/array.rs @@ -148,7 +148,7 @@ impl VTable for ZigZag { fn execute(array: Arc>, ctx: &mut ExecutionCtx) -> VortexResult { Ok(ExecutionResult::done( - zigzag_decode(array.encoded().clone().execute(ctx)?).into_array(), + zigzag_decode(Arc::clone(&array.encoded()).execute(ctx)?).into_array(), )) } diff --git a/encodings/zigzag/src/compute/mod.rs b/encodings/zigzag/src/compute/mod.rs index 86e343208b7..00ccd2b42e5 100644 --- a/encodings/zigzag/src/compute/mod.rs +++ b/encodings/zigzag/src/compute/mod.rs @@ -18,6 +18,7 @@ use vortex_mask::Mask; use crate::ZigZag; use crate::ZigZagArray; +use std::sync::Arc; impl FilterReduce for ZigZag { fn filter(array: &ZigZagArray, mask: &Mask) -> VortexResult> { @@ -42,7 +43,7 @@ impl MaskReduce for ZigZag { let masked_encoded = MaskExpr.try_new_array( array.encoded().len(), EmptyOptions, - [array.encoded().clone(), mask.clone()], + [Arc::clone(&array.encoded()), Arc::clone(&mask)], )?; Ok(Some(ZigZagArray::try_new(masked_encoded)?.into_array())) } diff --git a/encodings/zstd/src/array.rs b/encodings/zstd/src/array.rs index 200cffb0ff0..de8cf43aebd 100644 --- a/encodings/zstd/src/array.rs +++ b/encodings/zstd/src/array.rs @@ -263,7 +263,7 @@ impl VTable for Zstd { ); array.unsliced_validity = match &slots[VALIDITY_SLOT] { - Some(arr) => Validity::Array(arr.clone()), + Some(arr) => Validity::Array(Arc::clone(&arr)), None => Validity::from(array.dtype.nullability()), }; diff --git a/fuzz/fuzz_targets/file_io.rs b/fuzz/fuzz_targets/file_io.rs index a67ceb53fb3..45614ee7ab6 100644 --- a/fuzz/fuzz_targets/file_io.rs +++ b/fuzz/fuzz_targets/file_io.rs @@ -108,7 +108,7 @@ fuzz_target!(|fuzz: FuzzFileAction| -> Corpus { ); let bool_result = expected_array - .binary(output_array.clone(), Operator::Eq) + .binary(Arc::clone(&output_array), Operator::Eq) .vortex_expect("compare operation should succeed in fuzz test") .to_bool(); let true_count = bool_result.to_bit_buffer().true_count(); diff --git a/fuzz/src/array/fill_null.rs b/fuzz/src/array/fill_null.rs index 5954d6982f7..36405f3b952 100644 --- a/fuzz/src/array/fill_null.rs +++ b/fuzz/src/array/fill_null.rs @@ -21,6 +21,7 @@ use vortex_buffer::Buffer; use vortex_buffer::BufferMut; use vortex_error::VortexExpect; use vortex_error::VortexResult; +use std::sync::Arc; /// Apply fill_null on the canonical form of the array to get a consistent baseline. /// This implementation manually fills null values for each canonical type @@ -207,7 +208,7 @@ fn fill_varbinview_array( if result_nullability == Nullability::Nullable { VarBinViewArray::new_handle( result.to_varbinview().views_handle().clone(), - result.to_varbinview().buffers().clone(), + Arc::clone(&result.to_varbinview().buffers()), result.dtype().as_nullable(), result_nullability.into(), ) @@ -241,7 +242,7 @@ fn fill_varbinview_array( if result_nullability == Nullability::Nullable { VarBinViewArray::new_handle( result.to_varbinview().views_handle().clone(), - result.to_varbinview().buffers().clone(), + Arc::clone(&result.to_varbinview().buffers()), result.dtype().as_nullable(), result_nullability.into(), ) diff --git a/fuzz/src/array/mask.rs b/fuzz/src/array/mask.rs index 71049e8c748..a53171a513e 100644 --- a/fuzz/src/array/mask.rs +++ b/fuzz/src/array/mask.rs @@ -22,6 +22,7 @@ use vortex_error::VortexExpect; use vortex_error::VortexResult; use vortex_mask::AllOr; use vortex_mask::Mask; +use std::sync::Arc; /// Apply a logical AND of a validity and a mask. /// This needs to be coherent with applications of Mask. @@ -83,7 +84,7 @@ pub fn mask_canonical_array(canonical: Canonical, mask: &Mask) -> VortexResult VortexResult VortexResult { let new_validity = mask_validity(&array.validity(), mask); FixedSizeListArray::new( - array.elements().clone(), + Arc::clone(&array.elements()), array.list_size(), new_validity, array.len(), @@ -118,7 +119,7 @@ pub fn mask_canonical_array(canonical: Canonical, mask: &Mask) -> VortexResult { let new_validity = mask_validity(&array.validity(), mask); StructArray::try_new_with_dtype( - array.unmasked_fields().clone(), + Arc::clone(&array.unmasked_fields()), array.struct_fields().clone(), array.len(), new_validity, diff --git a/fuzz/src/array/mod.rs b/fuzz/src/array/mod.rs index 70094fed072..293381dfdd4 100644 --- a/fuzz/src/array/mod.rs +++ b/fuzz/src/array/mod.rs @@ -11,6 +11,8 @@ pub(crate) use scalar_at::*; pub(crate) use search_sorted::*; pub(crate) use slice::*; pub use sort::sort_canonical_array; + +use std::sync::Arc; pub(crate) use sum::*; pub(crate) use take::*; @@ -382,7 +384,7 @@ impl<'a> Arbitrary<'a> for FuzzArrayAction { ) .vortex_expect("fill_null_canonical_array should succeed in fuzz test"); // Update current_array to the result for chaining - current_array = expected_result.clone(); + current_array = Arc::clone(&expected_result); ( Action::FillNull(fill_value), ExpectedValue::Array(expected_result), @@ -403,7 +405,7 @@ impl<'a> Arbitrary<'a> for FuzzArrayAction { ) .vortex_expect("mask_canonical_array should succeed in fuzz test"); // Update current_array to the result for chaining - current_array = expected_result.clone(); + current_array = Arc::clone(&expected_result); ( Action::Mask(Mask::from_iter(mask)), ExpectedValue::Array(expected_result), @@ -717,8 +719,8 @@ fn assert_search_sorted( pub fn assert_array_eq(lhs: &ArrayRef, rhs: &ArrayRef, step: usize) -> VortexFuzzResult<()> { if lhs.dtype() != rhs.dtype() { return Err(VortexFuzzError::DTypeMismatch( - lhs.clone(), - rhs.clone(), + Arc::clone(&lhs), + Arc::clone(&rhs), step, Backtrace::capture(), )); @@ -743,8 +745,8 @@ pub fn assert_array_eq(lhs: &ArrayRef, rhs: &ArrayRef, step: usize) -> VortexFuz l, r, idx, - lhs.clone(), - rhs.clone(), + Arc::clone(&lhs), + Arc::clone(&rhs), step, Backtrace::capture(), )); diff --git a/fuzz/src/array/slice.rs b/fuzz/src/array/slice.rs index b5402cb5d21..87c0d11c6bd 100644 --- a/fuzz/src/array/slice.rs +++ b/fuzz/src/array/slice.rs @@ -18,6 +18,7 @@ use vortex_array::match_each_decimal_value_type; use vortex_array::match_each_native_ptype; use vortex_array::validity::Validity; use vortex_error::VortexResult; +use std::sync::Arc; #[allow(clippy::unnecessary_fallible_conversions)] pub fn slice_canonical_array( @@ -79,7 +80,7 @@ pub fn slice_canonical_array( let sizes = slice_canonical_array(list_array.sizes(), start, stop)?; // Since the list view elements can be stored out of order, we cannot slice it. - let elements = list_array.elements().clone(); + let elements = Arc::clone(&list_array.elements()); // SAFETY: If the array was already zero-copyable to list, slicing the offsets and sizes // only causes there to be leading and trailing garbage data, which is still diff --git a/fuzz/src/gpu/mod.rs b/fuzz/src/gpu/mod.rs index 6d762813000..055bd7ca5aa 100644 --- a/fuzz/src/gpu/mod.rs +++ b/fuzz/src/gpu/mod.rs @@ -20,6 +20,7 @@ use crate::SESSION; use crate::error::Backtrace; use crate::error::VortexFuzzError; use crate::error::VortexFuzzResult; +use std::sync::Arc; /// Which GPU-supported encoding to generate. #[derive(Debug, Clone, Copy)] @@ -121,7 +122,7 @@ pub async fn run_compress_gpu(fuzz: FuzzCompressGpu) -> VortexFuzzResult { let mut cuda_ctx = CudaSession::create_execution_ctx(&SESSION).vortex_expect("cannot create session"); - let gpu_canonical = match array.clone().execute_cuda(&mut cuda_ctx).await { + let gpu_canonical = match Arc::clone(&array).execute_cuda(&mut cuda_ctx).await { Ok(c) => c, Err(e) => { return Err(VortexFuzzError::VortexError(e, Backtrace::capture())); diff --git a/vortex-array/benches/chunked_dict_builder.rs b/vortex-array/benches/chunked_dict_builder.rs index 8b72d37eb3b..e59abab344c 100644 --- a/vortex-array/benches/chunked_dict_builder.rs +++ b/vortex-array/benches/chunked_dict_builder.rs @@ -15,6 +15,7 @@ use vortex_array::dtype::NativePType; use vortex_array::session::ArraySession; use vortex_error::VortexExpect; use vortex_session::VortexSession; +use std::sync::Arc; fn main() { divan::main(); @@ -60,6 +61,6 @@ fn chunked_dict_primitive_into_canonical( let chunk = gen_dict_primitive_chunks::(len, unique_values, chunk_count); bencher - .with_inputs(|| chunk.clone()) + .with_inputs(|| Arc::clone(&chunk)) .bench_values(|chunk| chunk.execute::(&mut SESSION.create_execution_ctx())) } diff --git a/vortex-array/benches/take_struct.rs b/vortex-array/benches/take_struct.rs index 96acd2e01ef..d5c8bdc3dfb 100644 --- a/vortex-array/benches/take_struct.rs +++ b/vortex-array/benches/take_struct.rs @@ -17,6 +17,7 @@ use vortex_array::arrays::StructArray; use vortex_array::dtype::FieldNames; use vortex_array::validity::Validity; use vortex_buffer::Buffer; +use std::sync::Arc; fn main() { divan::main(); @@ -101,7 +102,7 @@ fn take_struct_wide(bencher: Bencher, width: usize) { }) .bench_refs(|(array, indices, ctx)| { array - .take(indices.clone()) + .take(Arc::clone(&indices)) .unwrap() .execute::(ctx) }); diff --git a/vortex-array/benches/varbinview_zip.rs b/vortex-array/benches/varbinview_zip.rs index b3ce220f558..1cf4cbd56f4 100644 --- a/vortex-array/benches/varbinview_zip.rs +++ b/vortex-array/benches/varbinview_zip.rs @@ -13,6 +13,7 @@ use vortex_array::builtins::ArrayBuiltins; use vortex_array::dtype::DType; use vortex_array::dtype::Nullability; use vortex_mask::Mask; +use std::sync::Arc; fn main() { divan::main(); @@ -29,14 +30,14 @@ fn varbinview_zip_fragmented_mask(bencher: Bencher) { bencher .with_inputs(|| { ( - if_true.clone(), - if_false.clone(), + Arc::clone(&if_true), + Arc::clone(&if_false), mask.clone().into_array(), LEGACY_SESSION.create_execution_ctx(), ) }) .bench_refs(|(t, f, m, ctx)| { - m.zip(t.clone(), f.clone()) + m.zip(Arc::clone(&t), Arc::clone(&f)) .unwrap() .execute::(ctx) .unwrap(); @@ -54,14 +55,14 @@ fn varbinview_zip_block_mask(bencher: Bencher) { bencher .with_inputs(|| { ( - if_true.clone(), - if_false.clone(), + Arc::clone(&if_true), + Arc::clone(&if_false), mask.clone().into_array(), LEGACY_SESSION.create_execution_ctx(), ) }) .bench_refs(|(t, f, m, ctx)| { - m.zip(t.clone(), f.clone()) + m.zip(Arc::clone(&t), Arc::clone(&f)) .unwrap() .execute::(ctx) .unwrap(); diff --git a/vortex-array/src/aggregate_fn/accumulator.rs b/vortex-array/src/aggregate_fn/accumulator.rs index 95d5268b969..41d928529d8 100644 --- a/vortex-array/src/aggregate_fn/accumulator.rs +++ b/vortex-array/src/aggregate_fn/accumulator.rs @@ -17,6 +17,7 @@ use crate::aggregate_fn::session::AggregateFnSessionExt; use crate::dtype::DType; use crate::executor::MAX_ITERATIONS; use crate::scalar::Scalar; +use std::sync::Arc; /// Reference-counted type-erased accumulator. pub type AccumulatorRef = Box; @@ -103,7 +104,7 @@ impl DynAccumulator for Accumulator { let session = ctx.session().clone(); let kernels = &session.aggregate_fns().kernels; - let mut batch = batch.clone(); + let mut batch = Arc::clone(&batch); for _ in 0..*MAX_ITERATIONS { if batch.is::() { break; diff --git a/vortex-array/src/aggregate_fn/accumulator_grouped.rs b/vortex-array/src/aggregate_fn/accumulator_grouped.rs index 83b945708b2..cbbb1485d1f 100644 --- a/vortex-array/src/aggregate_fn/accumulator_grouped.rs +++ b/vortex-array/src/aggregate_fn/accumulator_grouped.rs @@ -34,6 +34,7 @@ use crate::dtype::IntegerPType; use crate::executor::MAX_ITERATIONS; use crate::match_each_integer_ptype; use crate::vtable::ValidityHelper; +use std::sync::Arc; /// Reference-counted type-erased grouped accumulator. pub type GroupedAccumulatorRef = Box; @@ -123,7 +124,7 @@ impl DynGroupedAccumulator for GroupedAccumulator { // We first execute the groups until it is a ListView or FixedSizeList, since we only // dispatch the aggregate kernel over the elements of these arrays. - let canonical = match groups.clone().execute::(ctx)? { + let canonical = match Arc::clone(&groups).execute::(ctx)? { Columnar::Canonical(c) => c, Columnar::Constant(c) => c.into_array().execute::(ctx)?, }; @@ -160,7 +161,7 @@ impl GroupedAccumulator { groups: &ListViewArray, ctx: &mut ExecutionCtx, ) -> VortexResult<()> { - let mut elements = groups.elements().clone(); + let mut elements = Arc::clone(&groups.elements()); let session = ctx.session().clone(); let kernels = &session.aggregate_fns().grouped_kernels; @@ -177,9 +178,9 @@ impl GroupedAccumulator { // SAFETY: we assume that elements execution is safe let groups = unsafe { ListViewArray::new_unchecked( - elements.clone(), - groups.offsets().clone(), - groups.sizes().clone(), + Arc::clone(&elements), + Arc::clone(&groups.offsets()), + Arc::clone(&groups.sizes()), groups.validity(), ) }; @@ -203,7 +204,7 @@ impl GroupedAccumulator { let validity = groups.validity().execute_mask(offsets.len(), ctx)?; match_each_integer_ptype!(offsets.dtype().as_ptype(), |O| { - let offsets = offsets.clone().execute::>(ctx)?; + let offsets = Arc::clone(&offsets).execute::>(ctx)?; let sizes = sizes.execute::>(ctx)?; self.accumulate_list_view_typed( &elements, @@ -251,7 +252,7 @@ impl GroupedAccumulator { groups: &FixedSizeListArray, ctx: &mut ExecutionCtx, ) -> VortexResult<()> { - let mut elements = groups.elements().clone(); + let mut elements = Arc::clone(&groups.elements()); let session = ctx.session().clone(); let kernels = &session.aggregate_fns().grouped_kernels; @@ -268,7 +269,7 @@ impl GroupedAccumulator { // SAFETY: we assume that elements execution is safe let groups = unsafe { FixedSizeListArray::new_unchecked( - elements.clone(), + Arc::clone(&elements), groups.list_size(), groups.validity(), groups.len(), diff --git a/vortex-array/src/aggregate_fn/fns/is_constant/mod.rs b/vortex-array/src/aggregate_fn/fns/is_constant/mod.rs index fa4c2a501fa..08efae5c3d9 100644 --- a/vortex-array/src/aggregate_fn/fns/is_constant/mod.rs +++ b/vortex-array/src/aggregate_fn/fns/is_constant/mod.rs @@ -47,6 +47,7 @@ use crate::expr::stats::StatsProvider; use crate::expr::stats::StatsProviderExt; use crate::scalar::Scalar; use crate::scalar_fn::fns::operators::Operator; +use std::sync::Arc; /// Check if two arrays of the same length have equal values at every position (null-safe). /// @@ -74,7 +75,7 @@ fn arrays_value_equal(a: &ArrayRef, b: &ArrayRef, ctx: &mut ExecutionCtx) -> Vor // Compare values element-wise. Result is null where both inputs are null, // true/false where both are valid. - let eq_result = a.binary(b.clone(), Operator::Eq)?; + let eq_result = a.binary(Arc::clone(&b), Operator::Eq)?; let eq_result = eq_result.execute::(ctx)?; Ok(eq_result.true_count() == valid_count) diff --git a/vortex-array/src/array/mod.rs b/vortex-array/src/array/mod.rs index 95643eff95d..e18baeb632e 100644 --- a/vortex-array/src/array/mod.rs +++ b/vortex-array/src/array/mod.rs @@ -176,7 +176,7 @@ impl DynArray for Arc { #[inline] fn to_array(&self) -> ArrayRef { - self.clone() + Arc::clone(&self) } #[inline] diff --git a/vortex-array/src/arrays/arbitrary.rs b/vortex-array/src/arrays/arbitrary.rs index 4ec802e8670..37c4dd71d3b 100644 --- a/vortex-array/src/arrays/arbitrary.rs +++ b/vortex-array/src/arrays/arbitrary.rs @@ -183,7 +183,7 @@ fn random_fixed_size_list( let array_length = chunk_len.unwrap_or(u.int_in_range(0..=20)?); let mut builder = - FixedSizeListBuilder::with_capacity(elem_dtype.clone(), list_size, null, array_length); + FixedSizeListBuilder::with_capacity(Arc::clone(&elem_dtype), list_size, null, array_length); for _ in 0..array_length { if null == Nullability::Nullable && u.arbitrary::()? { @@ -229,7 +229,7 @@ fn random_list_with_offset_type( ) -> Result { let array_length = chunk_len.unwrap_or(u.int_in_range(0..=20)?); - let mut builder = ListViewBuilder::::with_capacity(elem_dtype.clone(), null, 20, 10); + let mut builder = ListViewBuilder::::with_capacity(Arc::clone(&elem_dtype), null, 20, 10); for _ in 0..array_length { if null == Nullability::Nullable && u.arbitrary::()? { @@ -255,7 +255,7 @@ fn random_list_scalar( let elems = (0..list_size) .map(|_| random_scalar(u, elem_dtype)) .collect::>>()?; - Ok(Scalar::list(elem_dtype.clone(), elems, null)) + Ok(Scalar::list(Arc::clone(&elem_dtype), elems, null)) } fn random_string( diff --git a/vortex-array/src/arrays/assertions.rs b/vortex-array/src/arrays/assertions.rs index 9be7a8c16c6..aaeb68087af 100644 --- a/vortex-array/src/arrays/assertions.rs +++ b/vortex-array/src/arrays/assertions.rs @@ -13,6 +13,7 @@ use crate::IntoArray; use crate::LEGACY_SESSION; use crate::RecursiveCanonical; use crate::VortexSessionExecute; +use std::sync::Arc; fn format_indices>(indices: I) -> impl Display { indices.into_iter().format(",") @@ -111,7 +112,7 @@ macro_rules! assert_arrays_eq { #[track_caller] #[allow(clippy::panic)] pub fn assert_arrays_eq_impl(left: &ArrayRef, right: &ArrayRef) { - let executed = execute_to_canonical(left.clone(), &mut LEGACY_SESSION.create_execution_ctx()); + let executed = execute_to_canonical(Arc::clone(&left), &mut LEGACY_SESSION.create_execution_ctx()); let left_right = find_mismatched_indices(left, right); let executed_right = find_mismatched_indices(&executed, right); diff --git a/vortex-array/src/arrays/bool/compute/fill_null.rs b/vortex-array/src/arrays/bool/compute/fill_null.rs index d3ea9231e51..bf1ef9e7373 100644 --- a/vortex-array/src/arrays/bool/compute/fill_null.rs +++ b/vortex-array/src/arrays/bool/compute/fill_null.rs @@ -12,6 +12,7 @@ use crate::arrays::BoolArray; use crate::scalar::Scalar; use crate::scalar_fn::fns::fill_null::FillNullKernel; use crate::validity::Validity; +use std::sync::Arc; impl FillNullKernel for Bool { fn fill_null( @@ -26,7 +27,7 @@ impl FillNullKernel for Bool { Ok(Some(match array.validity() { Validity::Array(v) => { - let v_bool = v.clone().execute::(ctx)?; + let v_bool = Arc::clone(&v).execute::(ctx)?; let bool_buffer = if fill { array.to_bit_buffer() | &!v_bool.to_bit_buffer() } else { diff --git a/vortex-array/src/arrays/bool/compute/mask.rs b/vortex-array/src/arrays/bool/compute/mask.rs index 2570045c981..a63c2f2e377 100644 --- a/vortex-array/src/arrays/bool/compute/mask.rs +++ b/vortex-array/src/arrays/bool/compute/mask.rs @@ -9,13 +9,14 @@ use crate::arrays::Bool; use crate::arrays::BoolArray; use crate::scalar_fn::fns::mask::MaskReduce; use crate::validity::Validity; +use std::sync::Arc; impl MaskReduce for Bool { fn mask(array: &BoolArray, mask: &ArrayRef) -> VortexResult> { Ok(Some( BoolArray::new( array.to_bit_buffer(), - array.validity().and(Validity::Array(mask.clone()))?, + array.validity().and(Validity::Array(Arc::clone(&mask)))?, ) .into_array(), )) diff --git a/vortex-array/src/arrays/bool/patch.rs b/vortex-array/src/arrays/bool/patch.rs index 4d16a0e77e2..838950ad5ce 100644 --- a/vortex-array/src/arrays/bool/patch.rs +++ b/vortex-array/src/arrays/bool/patch.rs @@ -10,13 +10,14 @@ use crate::arrays::BoolArray; use crate::arrays::PrimitiveArray; use crate::match_each_unsigned_integer_ptype; use crate::patches::Patches; +use std::sync::Arc; impl BoolArray { pub fn patch(self, patches: &Patches, ctx: &mut ExecutionCtx) -> VortexResult { let len = self.len(); let offset = patches.offset(); - let indices = patches.indices().clone().execute::(ctx)?; - let values = patches.values().clone().execute::(ctx)?; + let indices = Arc::clone(&patches.indices()).execute::(ctx)?; + let values = Arc::clone(&patches.values()).execute::(ctx)?; let patched_validity = self.validity() diff --git a/vortex-array/src/arrays/chunked/array.rs b/vortex-array/src/arrays/chunked/array.rs index f787b9aa82f..1beec62566b 100644 --- a/vortex-array/src/arrays/chunked/array.rs +++ b/vortex-array/src/arrays/chunked/array.rs @@ -28,6 +28,7 @@ use crate::stats::ArrayStats; use crate::stream::ArrayStream; use crate::stream::ArrayStreamAdapter; use crate::validity::Validity; +use std::sync::Arc; // ChunkedArray has a variable number of slots: // slots[0] = chunk_offsets @@ -179,7 +180,7 @@ impl ChunkedArray { self.dtype().clone(), self.slots[1..] .iter() - .map(|s| Ok(s.as_ref().vortex_expect("ChunkedArray chunk slot").clone())), + .map(|s| Ok(Arc::clone(&s.as_ref().vortex_expect("ChunkedArray chunk slot")))), ) } @@ -189,7 +190,7 @@ impl ChunkedArray { stream::iter( self.slots[1..] .iter() - .map(|s| Ok(s.as_ref().vortex_expect("ChunkedArray chunk slot").clone())), + .map(|s| Ok(Arc::clone(&s.as_ref().vortex_expect("ChunkedArray chunk slot")))), ), ) } @@ -223,11 +224,11 @@ impl ChunkedArray { } if n_bytes > target_bytesize || n_elements > target_rowsize { - new_chunks.push(chunk.clone()); + new_chunks.push(Arc::clone(&chunk)); } else { new_chunk_n_bytes += n_bytes; new_chunk_n_elements += n_elements; - chunks_to_combine.push(chunk.clone()); + chunks_to_combine.push(Arc::clone(&chunk)); } } diff --git a/vortex-array/src/arrays/chunked/compute/filter.rs b/vortex-array/src/arrays/chunked/compute/filter.rs index 48c81821fb6..1c9adb27ec8 100644 --- a/vortex-array/src/arrays/chunked/compute/filter.rs +++ b/vortex-array/src/arrays/chunked/compute/filter.rs @@ -18,6 +18,7 @@ use crate::arrays::filter::FilterKernel; use crate::search_sorted::SearchSorted; use crate::search_sorted::SearchSortedSide; use crate::validity::Validity; +use std::sync::Arc; // This is modeled after the constant with the equivalent name in arrow-rs. pub(crate) const FILTER_SLICES_SELECTIVITY_THRESHOLD: f64 = 0.8; @@ -73,7 +74,7 @@ fn filter_slices( for (chunk, chunk_filter) in array.iter_chunks().zip(chunk_filters.into_iter()) { match chunk_filter { // All => preserve the entire chunk unfiltered. - ChunkFilter::All => result.push(chunk.clone()), + ChunkFilter::All => result.push(Arc::clone(&chunk)), // None => whole chunk is filtered out, skip ChunkFilter::None => {} // Slices => turn the slices into a boolean buffer. diff --git a/vortex-array/src/arrays/chunked/compute/mask.rs b/vortex-array/src/arrays/chunked/compute/mask.rs index 9217e5627f0..f7c5a65a97f 100644 --- a/vortex-array/src/arrays/chunked/compute/mask.rs +++ b/vortex-array/src/arrays/chunked/compute/mask.rs @@ -12,6 +12,7 @@ use crate::arrays::scalar_fn::ScalarFnArrayExt; use crate::scalar_fn::EmptyOptions; use crate::scalar_fn::fns::mask::Mask as MaskExpr; use crate::scalar_fn::fns::mask::MaskKernel; +use std::sync::Arc; impl MaskKernel for Chunked { fn mask( @@ -27,7 +28,7 @@ impl MaskKernel for Chunked { let start: usize = chunk_offsets[i].try_into()?; let end: usize = chunk_offsets[i + 1].try_into()?; let chunk_mask = mask.slice(start..end)?; - MaskExpr.try_new_array(chunk.len(), EmptyOptions, [chunk.clone(), chunk_mask]) + MaskExpr.try_new_array(chunk.len(), EmptyOptions, [Arc::clone(&chunk), chunk_mask]) }) .collect::>()?; diff --git a/vortex-array/src/arrays/chunked/compute/rules.rs b/vortex-array/src/arrays/chunked/compute/rules.rs index d20c96d6a3b..76cc720f578 100644 --- a/vortex-array/src/arrays/chunked/compute/rules.rs +++ b/vortex-array/src/arrays/chunked/compute/rules.rs @@ -17,6 +17,7 @@ use crate::optimizer::rules::ArrayParentReduceRule; use crate::optimizer::rules::ParentRuleSet; use crate::scalar_fn::fns::cast::CastReduceAdaptor; use crate::scalar_fn::fns::fill_null::FillNullReduceAdaptor; +use std::sync::Arc; pub(crate) const PARENT_RULES: ParentRuleSet = ParentRuleSet::new(&[ ParentRuleSet::lift(&CastReduceAdaptor(Chunked)), @@ -46,7 +47,7 @@ impl ArrayParentReduceRule for ChunkedUnaryScalarFnPushDownRule { .map(|chunk| { ScalarFnArray::try_new( parent.scalar_fn().clone(), - vec![chunk.clone()], + vec![Arc::clone(&chunk)], chunk.len(), )? .into_array() @@ -89,7 +90,7 @@ impl ArrayParentReduceRule for ChunkedConstantScalarFnPushDownRule { .enumerate() .map(|(idx, child)| { if idx == child_idx { - chunk.clone() + Arc::clone(&chunk) } else { ConstantArray::new( child.as_::().scalar().clone(), diff --git a/vortex-array/src/arrays/chunked/compute/slice.rs b/vortex-array/src/arrays/chunked/compute/slice.rs index d582387b372..a9dc01d0f9f 100644 --- a/vortex-array/src/arrays/chunked/compute/slice.rs +++ b/vortex-array/src/arrays/chunked/compute/slice.rs @@ -12,6 +12,7 @@ use crate::IntoArray; use crate::arrays::Chunked; use crate::arrays::ChunkedArray; use crate::arrays::slice::SliceKernel; +use std::sync::Arc; impl SliceKernel for Chunked { fn slice( @@ -46,7 +47,7 @@ impl SliceKernel for Chunked { } let mut chunks = (offset_chunk..length_chunk + 1) - .map(|i| array.chunk(i).clone()) + .map(|i| Arc::clone(&array.chunk(i))) .collect_vec(); if let Some(c) = chunks.first_mut() { *c = c.slice(offset_in_first_chunk..c.len())?; diff --git a/vortex-array/src/arrays/chunked/compute/take.rs b/vortex-array/src/arrays/chunked/compute/take.rs index ac29808fc6a..19d01589d3d 100644 --- a/vortex-array/src/arrays/chunked/compute/take.rs +++ b/vortex-array/src/arrays/chunked/compute/take.rs @@ -18,6 +18,7 @@ use crate::dtype::DType; use crate::dtype::PType; use crate::executor::ExecutionCtx; use crate::validity::Validity; +use std::sync::Arc; // TODO(joe): this is pretty unoptimized but better than before. We want canonical using a builder // we also want to return a chunked array ideally. @@ -131,7 +132,7 @@ mod test { #[test] fn test_take() { let a = buffer![1i32, 2, 3].into_array(); - let arr = ChunkedArray::try_new(vec![a.clone(), a.clone(), a.clone()], a.dtype().clone()) + let arr = ChunkedArray::try_new(vec![Arc::clone(&a), Arc::clone(&a), Arc::clone(&a)], a.dtype().clone()) .unwrap(); assert_eq!(arr.nchunks(), 3); assert_eq!(arr.len(), 9); @@ -144,7 +145,7 @@ mod test { #[test] fn test_take_nullable_values() { let a = PrimitiveArray::new(buffer![1i32, 2, 3], Validity::AllValid).into_array(); - let arr = ChunkedArray::try_new(vec![a.clone(), a.clone(), a.clone()], a.dtype().clone()) + let arr = ChunkedArray::try_new(vec![Arc::clone(&a), Arc::clone(&a), Arc::clone(&a)], a.dtype().clone()) .unwrap(); assert_eq!(arr.nchunks(), 3); assert_eq!(arr.len(), 9); @@ -160,7 +161,7 @@ mod test { #[test] fn test_take_nullable_indices() { let a = buffer![1i32, 2, 3].into_array(); - let arr = ChunkedArray::try_new(vec![a.clone(), a.clone(), a.clone()], a.dtype().clone()) + let arr = ChunkedArray::try_new(vec![Arc::clone(&a), Arc::clone(&a), Arc::clone(&a)], a.dtype().clone()) .unwrap(); assert_eq!(arr.nchunks(), 3); assert_eq!(arr.len(), 9); @@ -204,7 +205,7 @@ mod test { #[test] fn test_empty_take() { let a = buffer![1i32, 2, 3].into_array(); - let arr = ChunkedArray::try_new(vec![a.clone(), a.clone(), a.clone()], a.dtype().clone()) + let arr = ChunkedArray::try_new(vec![Arc::clone(&a), Arc::clone(&a), Arc::clone(&a)], a.dtype().clone()) .unwrap(); assert_eq!(arr.nchunks(), 3); assert_eq!(arr.len(), 9); @@ -339,7 +340,7 @@ mod test { // Test with multiple identical chunks let chunk = buffer![10i32, 20, 30, 40, 50].into_array(); let arr = ChunkedArray::try_new( - vec![chunk.clone(), chunk.clone(), chunk.clone()], + vec![Arc::clone(&chunk), Arc::clone(&chunk), Arc::clone(&chunk)], chunk.dtype().clone(), ) .unwrap(); diff --git a/vortex-array/src/arrays/chunked/tests.rs b/vortex-array/src/arrays/chunked/tests.rs index a4c169ad474..ab335393839 100644 --- a/vortex-array/src/arrays/chunked/tests.rs +++ b/vortex-array/src/arrays/chunked/tests.rs @@ -214,11 +214,11 @@ fn with_slots_updates_nchunks_len_and_offsets() { assert_eq!(array.len(), expected_len); assert_eq!(array.chunk_offsets(), buffer![0u64, 4, 9]); assert_arrays_eq!( - array.chunk(0).clone(), + Arc::clone(&array.chunk(0)), PrimitiveArray::from_iter([10u64, 11, 12, 13]) ); assert_arrays_eq!( - array.chunk(1).clone(), + Arc::clone(&array.chunk(1)), PrimitiveArray::from_iter([14u64, 15, 16, 17, 18]) ); assert_arrays_eq!( diff --git a/vortex-array/src/arrays/chunked/vtable/canonical.rs b/vortex-array/src/arrays/chunked/vtable/canonical.rs index 05b8bdfd42b..ab32b514c56 100644 --- a/vortex-array/src/arrays/chunked/vtable/canonical.rs +++ b/vortex-array/src/arrays/chunked/vtable/canonical.rs @@ -31,7 +31,7 @@ pub(super) fn _canonicalize( return Ok(Canonical::empty(array.dtype())); } if array.nchunks() == 1 { - return array.chunk(0).clone().execute::(ctx); + return Arc::clone(&array.chunk(0)).execute::(ctx); } let owned_chunks: Vec = array.iter_chunks().cloned().collect(); @@ -74,7 +74,7 @@ fn pack_struct_chunks( let executed_chunks: Vec = chunks .iter() - .map(|c| c.clone().execute::(ctx)) + .map(|c| Arc::clone(&c).execute::(ctx)) .collect::>()?; for (field_idx, field_dtype) in struct_dtype.fields().enumerate() { @@ -131,13 +131,13 @@ fn swizzle_list_chunks( let mut sizes = BufferMut::::with_capacity(len); for chunk in chunks { - let chunk_array = chunk.clone().execute::(ctx)?; + let chunk_array = Arc::clone(&chunk).execute::(ctx)?; // By rebuilding as zero-copy to `List` and trimming all elements (to prevent gaps), we make // the final output `ListView` also zero-copyable to `List`. let chunk_array = chunk_array.rebuild(ListViewRebuildMode::MakeExact)?; // Add the `elements` of the current array as a new chunk. - list_elements_chunks.push(chunk_array.elements().clone()); + list_elements_chunks.push(Arc::clone(&chunk_array.elements())); // Cast offsets and sizes to `u64`. let offsets_arr = chunk_array diff --git a/vortex-array/src/arrays/chunked/vtable/mod.rs b/vortex-array/src/arrays/chunked/vtable/mod.rs index e110d2542cf..93de00eba8d 100644 --- a/vortex-array/src/arrays/chunked/vtable/mod.rs +++ b/vortex-array/src/arrays/chunked/vtable/mod.rs @@ -286,7 +286,7 @@ impl VTable for Chunked { fn reduce(array: &Array) -> VortexResult> { Ok(match array.nchunks() { 0 => Some(Canonical::empty(array.dtype()).into_array()), - 1 => Some(array.chunk(0).clone()), + 1 => Some(Arc::clone(&array.chunk(0))), _ => None, }) } diff --git a/vortex-array/src/arrays/constant/compute/fill_null.rs b/vortex-array/src/arrays/constant/compute/fill_null.rs index 9854e184f0b..26f5f6cbde8 100644 --- a/vortex-array/src/arrays/constant/compute/fill_null.rs +++ b/vortex-array/src/arrays/constant/compute/fill_null.rs @@ -9,6 +9,7 @@ use crate::arrays::ConstantArray; use crate::scalar::Scalar; use crate::scalar_fn::fns::fill_null::FillNullReduce; use crate::scalar_fn::fns::fill_null::fill_null_constant; +use std::sync::Arc; impl FillNullReduce for Constant { fn fill_null(array: &ConstantArray, fill_value: &Scalar) -> VortexResult> { @@ -37,8 +38,8 @@ mod test { assert!(!actual.dtype().is_nullable()); - let actual_arrow = actual.clone().into_arrow_preferred().unwrap(); - let expected_arrow = expected.clone().into_arrow_preferred().unwrap(); + let actual_arrow = Arc::clone(&actual).into_arrow_preferred().unwrap(); + let expected_arrow = Arc::clone(&expected).into_arrow_preferred().unwrap(); assert_eq!( &actual_arrow, &expected_arrow, @@ -58,8 +59,8 @@ mod test { assert!(!actual.dtype().is_nullable()); - let actual_arrow = actual.clone().into_arrow_preferred().unwrap(); - let expected_arrow = expected.clone().into_arrow_preferred().unwrap(); + let actual_arrow = Arc::clone(&actual).into_arrow_preferred().unwrap(); + let expected_arrow = Arc::clone(&expected).into_arrow_preferred().unwrap(); assert_eq!( &actual_arrow, &expected_arrow, @@ -84,8 +85,8 @@ mod test { assert!(actual.dtype().is_nullable()); - let actual_arrow = actual.clone().into_arrow_preferred().unwrap(); - let expected_arrow = expected.clone().into_arrow_preferred().unwrap(); + let actual_arrow = Arc::clone(&actual).into_arrow_preferred().unwrap(); + let expected_arrow = Arc::clone(&expected).into_arrow_preferred().unwrap(); assert_eq!( &actual_arrow, &expected_arrow, diff --git a/vortex-array/src/arrays/decimal/array.rs b/vortex-array/src/arrays/decimal/array.rs index b0252b71abd..0faa954b4eb 100644 --- a/vortex-array/src/arrays/decimal/array.rs +++ b/vortex-array/src/arrays/decimal/array.rs @@ -29,6 +29,7 @@ use crate::stats::ArrayStats; use crate::validity::Validity; use crate::vtable::child_to_validity; use crate::vtable::validity_to_child; +use std::sync::Arc; /// The validity bitmap indicating which elements are non-null. pub(super) const VALIDITY_SLOT: usize = 0; @@ -391,8 +392,8 @@ impl DecimalArray { )] pub fn patch(self, patches: &Patches, ctx: &mut ExecutionCtx) -> VortexResult { let offset = patches.offset(); - let patch_indices = patches.indices().clone().execute::(ctx)?; - let patch_values = patches.values().clone().execute::(ctx)?; + let patch_indices = Arc::clone(&patches.indices()).execute::(ctx)?; + let patch_values = Arc::clone(&patches.values()).execute::(ctx)?; let patched_validity = self.validity().patch( self.len(), diff --git a/vortex-array/src/arrays/decimal/compute/mask.rs b/vortex-array/src/arrays/decimal/compute/mask.rs index be5d1854524..c26b3d61520 100644 --- a/vortex-array/src/arrays/decimal/compute/mask.rs +++ b/vortex-array/src/arrays/decimal/compute/mask.rs @@ -10,6 +10,7 @@ use crate::arrays::DecimalArray; use crate::match_each_decimal_value_type; use crate::scalar_fn::fns::mask::MaskReduce; use crate::validity::Validity; +use std::sync::Arc; impl MaskReduce for Decimal { fn mask(array: &DecimalArray, mask: &ArrayRef) -> VortexResult> { @@ -21,7 +22,7 @@ impl MaskReduce for Decimal { DecimalArray::new_unchecked( array.buffer::(), array.decimal_dtype(), - array.validity().and(Validity::Array(mask.clone()))?, + array.validity().and(Validity::Array(Arc::clone(&mask)))?, ) } .into_array() diff --git a/vortex-array/src/arrays/dict/compute/cast.rs b/vortex-array/src/arrays/dict/compute/cast.rs index 22457e875b2..1d8c7a0854b 100644 --- a/vortex-array/src/arrays/dict/compute/cast.rs +++ b/vortex-array/src/arrays/dict/compute/cast.rs @@ -11,6 +11,7 @@ use crate::IntoArray; use crate::builtins::ArrayBuiltins; use crate::dtype::DType; use crate::scalar_fn::fns::cast::CastReduce; +use std::sync::Arc; impl CastReduce for Dict { fn cast(array: &DictArray, dtype: &DType) -> VortexResult> { @@ -31,7 +32,7 @@ impl CastReduce for Dict { .codes() .cast(array.codes().dtype().with_nullability(dtype.nullability()))? } else { - array.codes().clone() + Arc::clone(&array.codes()) }; // SAFETY: casting does not alter invariants of the codes diff --git a/vortex-array/src/arrays/dict/compute/compare.rs b/vortex-array/src/arrays/dict/compute/compare.rs index 3dadc7d98e6..e6631fa6f74 100644 --- a/vortex-array/src/arrays/dict/compute/compare.rs +++ b/vortex-array/src/arrays/dict/compute/compare.rs @@ -15,6 +15,7 @@ use crate::builtins::ArrayBuiltins; use crate::scalar_fn::fns::binary::CompareKernel; use crate::scalar_fn::fns::operators::CompareOperator; use crate::scalar_fn::fns::operators::Operator; +use std::sync::Arc; impl CompareKernel for Dict { fn compare( @@ -37,7 +38,7 @@ impl CompareKernel for Dict { // SAFETY: values len preserved, codes all still point to valid values let result = unsafe { - DictArray::new_unchecked(lhs.codes().clone(), compare_result) + DictArray::new_unchecked(Arc::clone(&lhs.codes()), compare_result) .set_all_values_referenced(lhs.has_all_values_referenced()) .into_array() }; diff --git a/vortex-array/src/arrays/dict/compute/like.rs b/vortex-array/src/arrays/dict/compute/like.rs index fc2cb3681f5..4885a108cf8 100644 --- a/vortex-array/src/arrays/dict/compute/like.rs +++ b/vortex-array/src/arrays/dict/compute/like.rs @@ -14,6 +14,7 @@ use crate::optimizer::ArrayOptimizer; use crate::scalar_fn::fns::like::Like; use crate::scalar_fn::fns::like::LikeOptions; use crate::scalar_fn::fns::like::LikeReduce; +use std::sync::Arc; impl LikeReduce for Dict { fn like( @@ -29,7 +30,7 @@ impl LikeReduce for Dict { let pattern = ConstantArray::new(pattern, array.values().len()).into_array(); let values = Like - .try_new_array(pattern.len(), options, [array.values().clone(), pattern])? + .try_new_array(pattern.len(), options, [Arc::clone(&array.values()), pattern])? .optimize()?; // SAFETY: LIKE preserves the len of the values, so codes are still pointing at @@ -37,7 +38,7 @@ impl LikeReduce for Dict { // Preserve all_values_referenced since codes are unchanged. unsafe { Ok(Some( - DictArray::new_unchecked(array.codes().clone(), values) + DictArray::new_unchecked(Arc::clone(&array.codes()), values) .set_all_values_referenced(array.has_all_values_referenced()) .into_array(), )) diff --git a/vortex-array/src/arrays/dict/compute/mask.rs b/vortex-array/src/arrays/dict/compute/mask.rs index 6986a8c343a..ff2115ea294 100644 --- a/vortex-array/src/arrays/dict/compute/mask.rs +++ b/vortex-array/src/arrays/dict/compute/mask.rs @@ -11,17 +11,18 @@ use crate::arrays::scalar_fn::ScalarFnArrayExt; use crate::scalar_fn::EmptyOptions; use crate::scalar_fn::fns::mask::Mask as MaskExpr; use crate::scalar_fn::fns::mask::MaskReduce; +use std::sync::Arc; impl MaskReduce for Dict { fn mask(array: &DictArray, mask: &ArrayRef) -> VortexResult> { let masked_codes = MaskExpr.try_new_array( array.codes().len(), EmptyOptions, - [array.codes().clone(), mask.clone()], + [Arc::clone(&array.codes()), Arc::clone(&mask)], )?; // SAFETY: masking codes doesn't change dict invariants Ok(Some(unsafe { - DictArray::new_unchecked(masked_codes, array.values().clone()).into_array() + DictArray::new_unchecked(masked_codes, Arc::clone(&array.values())).into_array() })) } } diff --git a/vortex-array/src/arrays/dict/compute/mod.rs b/vortex-array/src/arrays/dict/compute/mod.rs index 0aa1586d29f..98ef315c90a 100644 --- a/vortex-array/src/arrays/dict/compute/mod.rs +++ b/vortex-array/src/arrays/dict/compute/mod.rs @@ -23,6 +23,7 @@ use crate::DynArray; use crate::ExecutionCtx; use crate::IntoArray; use crate::arrays::filter::FilterReduce; +use std::sync::Arc; impl TakeExecute for Dict { fn take( @@ -34,7 +35,7 @@ impl TakeExecute for Dict { // SAFETY: selecting codes doesn't change the invariants of DictArray // Preserve all_values_referenced since taking codes doesn't affect which values are referenced Ok(Some(unsafe { - DictArray::new_unchecked(codes, array.values().clone()).into_array() + DictArray::new_unchecked(codes, Arc::clone(&array.values())).into_array() })) } } @@ -46,7 +47,7 @@ impl FilterReduce for Dict { // SAFETY: filtering codes doesn't change invariants // Preserve all_values_referenced since filtering codes doesn't affect which values are referenced Ok(Some(unsafe { - DictArray::new_unchecked(codes, array.values().clone()).into_array() + DictArray::new_unchecked(codes, Arc::clone(&array.values())).into_array() })) } } diff --git a/vortex-array/src/arrays/dict/compute/rules.rs b/vortex-array/src/arrays/dict/compute/rules.rs index 939b2e16bce..58a04274d66 100644 --- a/vortex-array/src/arrays/dict/compute/rules.rs +++ b/vortex-array/src/arrays/dict/compute/rules.rs @@ -25,6 +25,7 @@ use crate::scalar_fn::fns::cast::CastReduceAdaptor; use crate::scalar_fn::fns::like::LikeReduceAdaptor; use crate::scalar_fn::fns::mask::MaskReduceAdaptor; use crate::scalar_fn::fns::pack::Pack; +use std::sync::Arc; pub(crate) const PARENT_RULES: ParentRuleSet = ParentRuleSet::new(&[ ParentRuleSet::lift(&FilterReduceAdaptor(Dict)), @@ -111,7 +112,7 @@ impl ArrayParentReduceRule for DictionaryScalarFnValuesPushDownRule { let mut new_children = Vec::with_capacity(parent.nchildren()); for (idx, child) in parent.iter_children().enumerate() { if idx == child_idx { - new_children.push(array.values().clone()); + new_children.push(Arc::clone(&array.values())); } else { let scalar = child.as_::().scalar().clone(); new_children.push(ConstantArray::new(scalar, values_len).into_array()); @@ -134,7 +135,7 @@ impl ArrayParentReduceRule for DictionaryScalarFnValuesPushDownRule { } Ok(Some( - unsafe { DictArray::new_unchecked(array.codes().clone(), new_values) }.into_array(), + unsafe { DictArray::new_unchecked(Arc::clone(&array.codes()), new_values) }.into_array(), )) } } @@ -179,9 +180,9 @@ impl ArrayParentReduceRule for DictionaryScalarFnCodesPullUpRule { let mut new_children = Vec::with_capacity(parent.nchildren()); for (idx, child) in parent.iter_children().enumerate() { if idx == child_idx { - new_children.push(array.values().clone()); + new_children.push(Arc::clone(&array.values())); } else { - new_children.push(child.as_::().values().clone()); + new_children.push(Arc::clone(&child.as_::().values())); } } @@ -194,7 +195,7 @@ impl ArrayParentReduceRule for DictionaryScalarFnCodesPullUpRule { .optimize()?; let new_dict = - unsafe { DictArray::new_unchecked(array.codes().clone(), new_values) }.into_array(); + unsafe { DictArray::new_unchecked(Arc::clone(&array.codes()), new_values) }.into_array(); Ok(Some(new_dict)) } diff --git a/vortex-array/src/arrays/dict/compute/slice.rs b/vortex-array/src/arrays/dict/compute/slice.rs index dd01c585a67..661ab8fce3f 100644 --- a/vortex-array/src/arrays/dict/compute/slice.rs +++ b/vortex-array/src/arrays/dict/compute/slice.rs @@ -13,6 +13,7 @@ use crate::arrays::Dict; use crate::arrays::DictArray; use crate::arrays::slice::SliceReduce; use crate::scalar::Scalar; +use std::sync::Arc; impl SliceReduce for Dict { fn slice(array: &Self::Array, range: Range) -> VortexResult> { @@ -38,7 +39,7 @@ impl SliceReduce for Dict { } // SAFETY: slicing the codes preserves invariants. Ok(Some( - unsafe { DictArray::new_unchecked(sliced_code, array.values().clone()) }.into_array(), + unsafe { DictArray::new_unchecked(sliced_code, Arc::clone(&array.values())) }.into_array(), )) } } diff --git a/vortex-array/src/arrays/dict/vtable/validity.rs b/vortex-array/src/arrays/dict/vtable/validity.rs index 95204c0d5b5..018a1647f0f 100644 --- a/vortex-array/src/arrays/dict/vtable/validity.rs +++ b/vortex-array/src/arrays/dict/vtable/validity.rs @@ -12,6 +12,7 @@ use crate::dtype::Nullability; use crate::scalar::Scalar; use crate::validity::Validity; use crate::vtable::ValidityVTable; +use std::sync::Arc; impl ValidityVTable for Dict { fn validity(array: &DictArray) -> VortexResult { @@ -38,7 +39,7 @@ impl ValidityVTable for Dict { (Validity::Array(_codes_validity), Validity::Array(values_validity)) => { // Create a mask representing "is the value at codes[i] valid?" let values_valid_mask = - unsafe { DictArray::new_unchecked(array.codes().clone(), values_validity) } + unsafe { DictArray::new_unchecked(Arc::clone(&array.codes()), values_validity) } .into_array(); let values_valid_mask = values_valid_mask .fill_null(Scalar::bool(false, Nullability::NonNullable))?; diff --git a/vortex-array/src/arrays/extension/compute/mask.rs b/vortex-array/src/arrays/extension/compute/mask.rs index af7770ee0ca..1b06e8c60ed 100644 --- a/vortex-array/src/arrays/extension/compute/mask.rs +++ b/vortex-array/src/arrays/extension/compute/mask.rs @@ -11,13 +11,14 @@ use crate::arrays::scalar_fn::ScalarFnArrayExt; use crate::scalar_fn::EmptyOptions; use crate::scalar_fn::fns::mask::Mask as MaskExpr; use crate::scalar_fn::fns::mask::MaskReduce; +use std::sync::Arc; impl MaskReduce for Extension { fn mask(array: &ExtensionArray, mask: &ArrayRef) -> VortexResult> { let masked_storage = MaskExpr.try_new_array( array.storage_array().len(), EmptyOptions, - [array.storage_array().clone(), mask.clone()], + [Arc::clone(&array.storage_array()), Arc::clone(&mask)], )?; Ok(Some( ExtensionArray::new( diff --git a/vortex-array/src/arrays/extension/compute/rules.rs b/vortex-array/src/arrays/extension/compute/rules.rs index 0703af6414a..53e63762988 100644 --- a/vortex-array/src/arrays/extension/compute/rules.rs +++ b/vortex-array/src/arrays/extension/compute/rules.rs @@ -15,6 +15,7 @@ use crate::optimizer::rules::ArrayParentReduceRule; use crate::optimizer::rules::ParentRuleSet; use crate::scalar_fn::fns::cast::CastReduceAdaptor; use crate::scalar_fn::fns::mask::MaskReduceAdaptor; +use std::sync::Arc; pub(crate) const PARENT_RULES: ParentRuleSet = ParentRuleSet::new(&[ ParentRuleSet::lift(&ExtensionFilterPushDownRule), @@ -218,7 +219,7 @@ mod tests { let const_array = ConstantArray::new(const_scalar, 3).into_array(); let scalar_fn_array = Binary - .try_new_array(3, Operator::Lt, [ext_array.clone(), const_array]) + .try_new_array(3, Operator::Lt, [Arc::clone(&ext_array), const_array]) .unwrap(); let optimized = scalar_fn_array.optimize().unwrap(); @@ -243,7 +244,7 @@ mod tests { // Both children are extension arrays (not constants) let scalar_fn_array = Binary - .try_new_array(3, Operator::Lt, [ext_array1.clone(), ext_array2]) + .try_new_array(3, Operator::Lt, [Arc::clone(&ext_array1), ext_array2]) .unwrap(); let optimized = scalar_fn_array.optimize().unwrap(); @@ -266,7 +267,7 @@ mod tests { let const_array = ConstantArray::new(Scalar::from(25i64), 3).into_array(); let scalar_fn_array = Binary - .try_new_array(3, Operator::Lt, [ext_array.clone(), const_array]) + .try_new_array(3, Operator::Lt, [Arc::clone(&ext_array), const_array]) .unwrap(); let optimized = scalar_fn_array.optimize().unwrap(); diff --git a/vortex-array/src/arrays/filter/execute/fixed_size_list.rs b/vortex-array/src/arrays/filter/execute/fixed_size_list.rs index aede1ae550b..05fc8f51a5c 100644 --- a/vortex-array/src/arrays/filter/execute/fixed_size_list.rs +++ b/vortex-array/src/arrays/filter/execute/fixed_size_list.rs @@ -59,7 +59,7 @@ pub fn filter_fixed_size_list( // - `elements` has length 0 (since it came from a valid `FixedSizeListArray`) // - `filtered_validity` has the correct length because we filter with the same // `selection_mask` as the array itself - elements.clone() + Arc::clone(&elements) } }; diff --git a/vortex-array/src/arrays/filter/execute/listview.rs b/vortex-array/src/arrays/filter/execute/listview.rs index 9459b710a72..1dae3430b60 100644 --- a/vortex-array/src/arrays/filter/execute/listview.rs +++ b/vortex-array/src/arrays/filter/execute/listview.rs @@ -62,7 +62,7 @@ pub fn filter_listview(array: &ListViewArray, selection_mask: &Arc) // - Offsets and sizes have the same length (both filtered by `selection_mask`). // - Validity matches the filtered array's nullability. let new_array = unsafe { - ListViewArray::new_unchecked(elements.clone(), new_offsets, new_sizes, new_validity) + ListViewArray::new_unchecked(Arc::clone(&elements), new_offsets, new_sizes, new_validity) }; // TODO(connor)[ListView]: Ideally, we would only rebuild after all `take`s and `filter` @@ -182,7 +182,7 @@ mod test { let offsets = buffer![5u32, 2, 8, 0, 1].into_array(); let sizes = buffer![3u32, 2, 2, 2, 4].into_array(); - let listview = ListViewArray::new(elements.clone(), offsets, sizes, Validity::NonNullable) + let listview = ListViewArray::new(Arc::clone(&elements), offsets, sizes, Validity::NonNullable) .into_array(); // Filter to keep only 2 lists. @@ -214,7 +214,7 @@ mod test { let offsets = buffer![0u32, 6, 10, 1, 7].into_array(); let sizes = buffer![3u32, 3, 2, 2, 2].into_array(); - let listview = ListViewArray::new(elements.clone(), offsets, sizes, Validity::NonNullable) + let listview = ListViewArray::new(Arc::clone(&elements), offsets, sizes, Validity::NonNullable) .into_array(); // Filter to keep lists with gaps and overlaps. @@ -254,7 +254,7 @@ mod test { let varying_sizes = buffer![1u32, 2, 3, 4].into_array(); let const_offset_list = ListViewArray::new( - elements.clone(), + Arc::clone(&elements), constant_offsets, varying_sizes, Validity::NonNullable, @@ -306,7 +306,7 @@ mod test { let offsets = buffer![0u32, 4999, 9995, 2500, 7500].into_array(); let sizes = buffer![5u32, 2, 5, 3, 4].into_array(); - let listview = ListViewArray::new(elements.clone(), offsets, sizes, Validity::NonNullable) + let listview = ListViewArray::new(Arc::clone(&elements), offsets, sizes, Validity::NonNullable) .into_array(); // Filter to keep only 2 lists, demonstrating we keep all 10000 elements. diff --git a/vortex-array/src/arrays/filter/execute/mod.rs b/vortex-array/src/arrays/filter/execute/mod.rs index df7098507ed..ef45b32c997 100644 --- a/vortex-array/src/arrays/filter/execute/mod.rs +++ b/vortex-array/src/arrays/filter/execute/mod.rs @@ -37,7 +37,7 @@ mod varbinview; /// Reconstruct a [`Mask`] from an [`Arc`]. fn values_to_mask(values: &Arc) -> Mask { - Mask::Values(values.clone()) + Mask::Values(Arc::clone(&values)) } /// A helper function that lazily filters a [`Validity`] with selection mask values. @@ -61,7 +61,7 @@ pub(super) fn execute_filter_fast_paths( // If the mask selects everything, then we can just fully decompress the whole thing. if true_count == array.mask.len() { - return Ok(Some(array.child().clone())); + return Ok(Some(Arc::clone(&array.child()))); } // Also check if the array itself is completely null, in which case we only care about the total diff --git a/vortex-array/src/arrays/filter/execute/struct_.rs b/vortex-array/src/arrays/filter/execute/struct_.rs index 74540a8739d..ee9d2459860 100644 --- a/vortex-array/src/arrays/filter/execute/struct_.rs +++ b/vortex-array/src/arrays/filter/execute/struct_.rs @@ -159,7 +159,7 @@ mod test { vec![ StructArray::try_new( ["left", "right"].into(), - vec![xs.clone(), xs], + vec![Arc::clone(&xs), xs], 5, Validity::NonNullable, ) diff --git a/vortex-array/src/arrays/filter/rules.rs b/vortex-array/src/arrays/filter/rules.rs index d54f0c0de8f..223d88892ac 100644 --- a/vortex-array/src/arrays/filter/rules.rs +++ b/vortex-array/src/arrays/filter/rules.rs @@ -17,6 +17,7 @@ use crate::optimizer::rules::ArrayParentReduceRule; use crate::optimizer::rules::ArrayReduceRule; use crate::optimizer::rules::ParentRuleSet; use crate::optimizer::rules::ReduceRuleSet; +use std::sync::Arc; pub(super) const PARENT_RULES: ParentRuleSet = ParentRuleSet::new(&[ParentRuleSet::lift(&FilterFilterRule)]); @@ -51,7 +52,7 @@ struct TrivialFilterRule; impl ArrayReduceRule for TrivialFilterRule { fn reduce(&self, array: &FilterArray) -> VortexResult> { match array.filter_mask() { - Mask::AllTrue(_) => Ok(Some(array.child().clone())), + Mask::AllTrue(_) => Ok(Some(Arc::clone(&array.child()))), Mask::AllFalse(_) => Ok(Some(Canonical::empty(array.dtype()).into_array())), Mask::Values(_) => Ok(None), } diff --git a/vortex-array/src/arrays/filter/vtable.rs b/vortex-array/src/arrays/filter/vtable.rs index 618908b7301..bb69e9d3852 100644 --- a/vortex-array/src/arrays/filter/vtable.rs +++ b/vortex-array/src/arrays/filter/vtable.rs @@ -158,7 +158,7 @@ impl VTable for Filter { // We rely on the optimization pass that runs prior to this execution for filter pushdown, // so now we can just execute the filter without worrying. Ok(ExecutionResult::done( - execute_filter(array.child().clone().execute(ctx)?, mask_values).into_array(), + execute_filter(Arc::clone(&array.child()).execute(ctx)?, mask_values).into_array(), )) } diff --git a/vortex-array/src/arrays/fixed_size_list/compute/mask.rs b/vortex-array/src/arrays/fixed_size_list/compute/mask.rs index bc4f44f75de..e6bdd20115c 100644 --- a/vortex-array/src/arrays/fixed_size_list/compute/mask.rs +++ b/vortex-array/src/arrays/fixed_size_list/compute/mask.rs @@ -10,6 +10,7 @@ use crate::arrays::FixedSizeListArray; use crate::scalar_fn::fns::mask::MaskReduce; use crate::validity::Validity; use crate::vtable::ValidityHelper; +use std::sync::Arc; impl MaskReduce for FixedSizeList { fn mask(array: &FixedSizeListArray, mask: &ArrayRef) -> VortexResult> { @@ -17,9 +18,9 @@ impl MaskReduce for FixedSizeList { Ok(Some( unsafe { FixedSizeListArray::new_unchecked( - array.elements().clone(), + Arc::clone(&array.elements()), array.list_size(), - array.validity().and(Validity::Array(mask.clone()))?, + array.validity().and(Validity::Array(Arc::clone(&mask)))?, array.len(), ) } diff --git a/vortex-array/src/arrays/fixed_size_list/compute/take.rs b/vortex-array/src/arrays/fixed_size_list/compute/take.rs index b38d10fc2bb..a7a4cb30f38 100644 --- a/vortex-array/src/arrays/fixed_size_list/compute/take.rs +++ b/vortex-array/src/arrays/fixed_size_list/compute/take.rs @@ -20,6 +20,7 @@ use crate::match_each_integer_ptype; use crate::match_smallest_offset_type; use crate::validity::Validity; use crate::vtable::ValidityHelper; +use std::sync::Arc; /// Take implementation for [`FixedSizeListArray`]. /// @@ -68,7 +69,7 @@ fn take_with_indices( // SAFETY: list_size is 0, elements array is empty, and validity has the correct length. unsafe { FixedSizeListArray::new_unchecked( - array.elements().clone(), // Remember that this is an empty array. + Arc::clone(&array.elements()), // Remember that this is an empty array. array.list_size(), new_validity, new_len, diff --git a/vortex-array/src/arrays/fixed_size_list/tests/nullability.rs b/vortex-array/src/arrays/fixed_size_list/tests/nullability.rs index 4cba013426c..5689c35e6da 100644 --- a/vortex-array/src/arrays/fixed_size_list/tests/nullability.rs +++ b/vortex-array/src/arrays/fixed_size_list/tests/nullability.rs @@ -209,7 +209,7 @@ fn test_validity_types() { // Test with AllInvalid. { - let fsl = FixedSizeListArray::new(elements.clone(), list_size, Validity::AllInvalid, len); + let fsl = FixedSizeListArray::new(Arc::clone(&elements), list_size, Validity::AllInvalid, len); for i in 0..len { assert!(fsl.scalar_at(i).unwrap().is_null()); } diff --git a/vortex-array/src/arrays/fixed_size_list/vtable/mod.rs b/vortex-array/src/arrays/fixed_size_list/vtable/mod.rs index c8b7030505d..4802b4829f5 100644 --- a/vortex-array/src/arrays/fixed_size_list/vtable/mod.rs +++ b/vortex-array/src/arrays/fixed_size_list/vtable/mod.rs @@ -200,7 +200,7 @@ impl VTable for FixedSizeList { slots.len() ); array.validity = match &slots[VALIDITY_SLOT] { - Some(arr) => Validity::Array(arr.clone()), + Some(arr) => Validity::Array(Arc::clone(&arr)), None => Validity::from(array.dtype.nullability()), }; array.slots = slots; diff --git a/vortex-array/src/arrays/list/compute/cast.rs b/vortex-array/src/arrays/list/compute/cast.rs index e0879c2e906..575a7e59773 100644 --- a/vortex-array/src/arrays/list/compute/cast.rs +++ b/vortex-array/src/arrays/list/compute/cast.rs @@ -24,7 +24,7 @@ impl CastReduce for List { let new_elements = array.elements().cast((**target_element_type).clone())?; - ListArray::try_new(new_elements, array.offsets().clone(), validity) + ListArray::try_new(new_elements, Arc::clone(&array.offsets()), validity) .map(|a| Some(a.into_array())) } } diff --git a/vortex-array/src/arrays/list/compute/filter.rs b/vortex-array/src/arrays/list/compute/filter.rs index e2691c0e82e..666b3900f9e 100644 --- a/vortex-array/src/arrays/list/compute/filter.rs +++ b/vortex-array/src/arrays/list/compute/filter.rs @@ -117,7 +117,7 @@ impl FilterKernel for List { }; // TODO(ngates): for ultra-sparse masks, we don't need to optimize the entire offsets. - let offsets = array.offsets().clone(); + let offsets = Arc::clone(&array.offsets()); let (new_offsets, element_mask) = match_each_integer_ptype!(offsets.dtype().as_ptype(), |O| { diff --git a/vortex-array/src/arrays/list/compute/mask.rs b/vortex-array/src/arrays/list/compute/mask.rs index 565540dd7db..69800bb0f26 100644 --- a/vortex-array/src/arrays/list/compute/mask.rs +++ b/vortex-array/src/arrays/list/compute/mask.rs @@ -10,13 +10,14 @@ use crate::arrays::ListArray; use crate::scalar_fn::fns::mask::MaskReduce; use crate::validity::Validity; use crate::vtable::ValidityHelper; +use std::sync::Arc; impl MaskReduce for List { fn mask(array: &ListArray, mask: &ArrayRef) -> VortexResult> { ListArray::try_new( - array.elements().clone(), - array.offsets().clone(), - array.validity().and(Validity::Array(mask.clone()))?, + Arc::clone(&array.elements()), + Arc::clone(&array.offsets()), + array.validity().and(Validity::Array(Arc::clone(&mask)))?, ) .map(|a| Some(a.into_array())) } diff --git a/vortex-array/src/arrays/list/compute/slice.rs b/vortex-array/src/arrays/list/compute/slice.rs index 46c571773ef..1ed0072112a 100644 --- a/vortex-array/src/arrays/list/compute/slice.rs +++ b/vortex-array/src/arrays/list/compute/slice.rs @@ -11,12 +11,13 @@ use crate::arrays::List; use crate::arrays::ListArray; use crate::arrays::slice::SliceReduce; use crate::vtable::ValidityHelper; +use std::sync::Arc; impl SliceReduce for List { fn slice(array: &Self::Array, range: Range) -> VortexResult> { Ok(Some( ListArray::new( - array.elements().clone(), + Arc::clone(&array.elements()), array.offsets().slice(range.start..range.end + 1)?, array.validity().slice(range)?, ) diff --git a/vortex-array/src/arrays/list/compute/take.rs b/vortex-array/src/arrays/list/compute/take.rs index e6094bd4ef3..b3be69f482f 100644 --- a/vortex-array/src/arrays/list/compute/take.rs +++ b/vortex-array/src/arrays/list/compute/take.rs @@ -233,7 +233,7 @@ mod test { assert_eq!( result.scalar_at(0).unwrap(), Scalar::list( - element_dtype.clone(), + Arc::clone(&element_dtype), vec![0i32.into(), 5.into()], Nullability::Nullable ) @@ -245,7 +245,7 @@ mod test { assert_eq!( result.scalar_at(2).unwrap(), Scalar::list( - element_dtype.clone(), + Arc::clone(&element_dtype), vec![3i32.into()], Nullability::Nullable ) @@ -313,7 +313,7 @@ mod test { assert_eq!( result.scalar_at(0).unwrap(), Scalar::list( - element_dtype.clone(), + Arc::clone(&element_dtype), vec![3i32.into()], Nullability::NonNullable ) @@ -323,7 +323,7 @@ mod test { assert_eq!( result.scalar_at(1).unwrap(), Scalar::list( - element_dtype.clone(), + Arc::clone(&element_dtype), vec![0i32.into(), 5.into()], Nullability::NonNullable ) diff --git a/vortex-array/src/arrays/list/test_harness.rs b/vortex-array/src/arrays/list/test_harness.rs index 7ced1eb878f..42351484c19 100644 --- a/vortex-array/src/arrays/list/test_harness.rs +++ b/vortex-array/src/arrays/list/test_harness.rs @@ -28,7 +28,7 @@ impl ListArray { { let iter = iter.into_iter(); let mut builder = ListBuilder::::with_capacity( - dtype.clone(), + Arc::clone(&dtype), crate::dtype::Nullability::NonNullable, 2 * iter.size_hint().0, iter.size_hint().0, @@ -36,7 +36,7 @@ impl ListArray { for v in iter { let elem = Scalar::list( - dtype.clone(), + Arc::clone(&dtype), v.into_iter().map(|x| x.into()).collect_vec(), dtype.nullability(), ); @@ -55,7 +55,7 @@ impl ListArray { { let iter = iter.into_iter(); let mut builder = ListBuilder::::with_capacity( - dtype.clone(), + Arc::clone(&dtype), crate::dtype::Nullability::Nullable, 2 * iter.size_hint().0, iter.size_hint().0, @@ -64,7 +64,7 @@ impl ListArray { for v in iter { if let Some(v) = v { let elem = Scalar::list( - dtype.clone(), + Arc::clone(&dtype), v.into_iter().map(|x| x.into()).collect_vec(), dtype.nullability(), ); diff --git a/vortex-array/src/arrays/list/tests.rs b/vortex-array/src/arrays/list/tests.rs index c6b6b99246c..2ca810db8ad 100644 --- a/vortex-array/src/arrays/list/tests.rs +++ b/vortex-array/src/arrays/list/tests.rs @@ -231,7 +231,7 @@ fn test_list_filter_all_true() { let offsets = buffer![0, 5, 10, 15, 20].into_array(); let validity = Validity::AllValid; - let list = ListArray::try_new(elements.clone(), offsets.clone(), validity.clone()) + let list = ListArray::try_new(Arc::clone(&elements), Arc::clone(&offsets), validity.clone()) .unwrap() .into_array(); diff --git a/vortex-array/src/arrays/list/vtable/mod.rs b/vortex-array/src/arrays/list/vtable/mod.rs index 114579a4bab..56408a21fd7 100644 --- a/vortex-array/src/arrays/list/vtable/mod.rs +++ b/vortex-array/src/arrays/list/vtable/mod.rs @@ -185,7 +185,7 @@ impl VTable for List { slots.len() ); array.validity = match &slots[VALIDITY_SLOT] { - Some(arr) => Validity::Array(arr.clone()), + Some(arr) => Validity::Array(Arc::clone(&arr)), None => Validity::from(array.dtype.nullability()), }; array.slots = slots; diff --git a/vortex-array/src/arrays/listview/compute/cast.rs b/vortex-array/src/arrays/listview/compute/cast.rs index 6b662827220..998a22a2a33 100644 --- a/vortex-array/src/arrays/listview/compute/cast.rs +++ b/vortex-array/src/arrays/listview/compute/cast.rs @@ -11,6 +11,7 @@ use crate::builtins::ArrayBuiltins; use crate::dtype::DType; use crate::scalar_fn::fns::cast::CastReduce; use crate::vtable::ValidityHelper; +use std::sync::Arc; impl CastReduce for ListView { fn cast(array: &ListViewArray, dtype: &DType) -> VortexResult> { @@ -30,8 +31,8 @@ impl CastReduce for ListView { unsafe { ListViewArray::new_unchecked( new_elements, - array.offsets().clone(), - array.sizes().clone(), + Arc::clone(&array.offsets()), + Arc::clone(&array.sizes()), validity, ) .with_zero_copy_to_list(array.is_zero_copy_to_list()) diff --git a/vortex-array/src/arrays/listview/compute/mask.rs b/vortex-array/src/arrays/listview/compute/mask.rs index 6732fc25f66..43a6f369e81 100644 --- a/vortex-array/src/arrays/listview/compute/mask.rs +++ b/vortex-array/src/arrays/listview/compute/mask.rs @@ -10,6 +10,7 @@ use crate::arrays::ListViewArray; use crate::scalar_fn::fns::mask::MaskReduce; use crate::validity::Validity; use crate::vtable::ValidityHelper; +use std::sync::Arc; impl MaskReduce for ListView { fn mask(array: &ListViewArray, mask: &ArrayRef) -> VortexResult> { @@ -17,10 +18,10 @@ impl MaskReduce for ListView { Ok(Some( unsafe { ListViewArray::new_unchecked( - array.elements().clone(), - array.offsets().clone(), - array.sizes().clone(), - array.validity().and(Validity::Array(mask.clone()))?, + Arc::clone(&array.elements()), + Arc::clone(&array.offsets()), + Arc::clone(&array.sizes()), + array.validity().and(Validity::Array(Arc::clone(&mask)))?, ) .with_zero_copy_to_list(array.is_zero_copy_to_list()) } diff --git a/vortex-array/src/arrays/listview/compute/rules.rs b/vortex-array/src/arrays/listview/compute/rules.rs index 6eedee9d8f9..0d1b703edca 100644 --- a/vortex-array/src/arrays/listview/compute/rules.rs +++ b/vortex-array/src/arrays/listview/compute/rules.rs @@ -17,6 +17,7 @@ use crate::optimizer::rules::ParentRuleSet; use crate::scalar_fn::fns::cast::CastReduceAdaptor; use crate::scalar_fn::fns::mask::MaskReduceAdaptor; use crate::vtable::ValidityHelper; +use std::sync::Arc; pub(crate) const PARENT_RULES: ParentRuleSet = ParentRuleSet::new(&[ ParentRuleSet::lift(&ListViewFilterPushDown), @@ -45,7 +46,7 @@ impl ArrayParentReduceRule for ListViewFilterPushDown { Ok(Some( unsafe { ListViewArray::new_unchecked( - array.elements().clone(), + Arc::clone(&array.elements()), array.offsets().filter(parent.filter_mask().clone())?, array.sizes().filter(parent.filter_mask().clone())?, array.validity().filter(parent.filter_mask())?, diff --git a/vortex-array/src/arrays/listview/compute/slice.rs b/vortex-array/src/arrays/listview/compute/slice.rs index be5855ce473..35de31de84f 100644 --- a/vortex-array/src/arrays/listview/compute/slice.rs +++ b/vortex-array/src/arrays/listview/compute/slice.rs @@ -10,13 +10,14 @@ use crate::IntoArray; use crate::arrays::ListView; use crate::arrays::ListViewArray; use crate::arrays::slice::SliceReduce; +use std::sync::Arc; impl SliceReduce for ListView { fn slice(array: &Self::Array, range: Range) -> VortexResult> { Ok(Some( unsafe { ListViewArray::new_unchecked( - array.elements().clone(), + Arc::clone(&array.elements()), array.offsets().slice(range.clone())?, array.sizes().slice(range.clone())?, array.validity()?.slice(range)?, diff --git a/vortex-array/src/arrays/listview/compute/take.rs b/vortex-array/src/arrays/listview/compute/take.rs index 0e6e7289579..ac89ac7e9fe 100644 --- a/vortex-array/src/arrays/listview/compute/take.rs +++ b/vortex-array/src/arrays/listview/compute/take.rs @@ -16,6 +16,7 @@ use crate::dtype::Nullability; use crate::match_each_integer_ptype; use crate::scalar::Scalar; use crate::vtable::ValidityHelper; +use std::sync::Arc; // TODO(connor)[ListView]: Make use of this threshold after we start migrating operators. /// The threshold for triggering a rebuild of the [`ListViewArray`]. @@ -72,7 +73,7 @@ impl TakeReduce for ListView { // `indices`). // - Validity correctly reflects the combination of array and indices validity. let new_array = unsafe { - ListViewArray::new_unchecked(elements.clone(), new_offsets, new_sizes, new_validity) + ListViewArray::new_unchecked(Arc::clone(&elements), new_offsets, new_sizes, new_validity) }; // TODO(connor)[ListView]: Ideally, we would only rebuild after all `take`s and `filter` diff --git a/vortex-array/src/arrays/listview/conversion.rs b/vortex-array/src/arrays/listview/conversion.rs index fb34d9b45e8..891c17ec980 100644 --- a/vortex-array/src/arrays/listview/conversion.rs +++ b/vortex-array/src/arrays/listview/conversion.rs @@ -41,7 +41,7 @@ pub fn list_view_from_list(list: ListArray, ctx: &mut ExecutionCtx) -> VortexRes // garbage data when they turn it back into a `ListArray`. let list = list.reset_offsets(false).vortex_expect("This can't fail"); - let list_offsets = list.offsets().clone(); + let list_offsets = Arc::clone(&list.offsets()); // Create `sizes` array by computing differences between consecutive offsets. // We use the same `DType` for the sizes as the `offsets` array to ensure compatibility. @@ -58,7 +58,7 @@ pub fn list_view_from_list(list: ListArray, ctx: &mut ExecutionCtx) -> VortexRes // We also just came directly from a `ListArray`, so we know this is zero-copyable. Ok(unsafe { ListViewArray::new_unchecked( - list.elements().clone(), + Arc::clone(&list.elements()), adjusted_offsets, sizes, list.validity(), @@ -78,7 +78,7 @@ fn build_sizes_from_offsets( // Create `UninitRange` for direct memory access. let mut sizes_range = sizes_builder.uninit_range(len); - let offsets = list.offsets().clone().execute::(ctx)?; + let offsets = Arc::clone(&list.offsets()).execute::(ctx)?; let offsets_slice = offsets.as_slice::(); debug_assert_eq!(len + 1, offsets_slice.len()); debug_assert!(offsets_slice.is_sorted()); @@ -122,7 +122,7 @@ pub fn list_from_list_view(list_view: ListViewArray) -> VortexResult // make it easier for the caller to use the `ListArray`. Ok(unsafe { ListArray::new_unchecked( - zctl_array.elements().clone(), + Arc::clone(&zctl_array.elements()), list_offsets, zctl_array.validity(), ) @@ -190,7 +190,7 @@ pub fn recursive_list_from_list_view(array: ArrayRef) -> VortexResult Ok(match canonical { Canonical::List(listview) => { - let converted_elements = recursive_list_from_list_view(listview.elements().clone())?; + let converted_elements = recursive_list_from_list_view(Arc::clone(&listview.elements()))?; debug_assert_eq!(converted_elements.len(), listview.elements().len()); // Avoid cloning if elements didn't change. @@ -201,8 +201,8 @@ pub fn recursive_list_from_list_view(array: ArrayRef) -> VortexResult unsafe { ListViewArray::new_unchecked( converted_elements, - listview.offsets().clone(), - listview.sizes().clone(), + Arc::clone(&listview.offsets()), + Arc::clone(&listview.sizes()), listview.validity(), ) .with_zero_copy_to_list(listview.is_zero_copy_to_list()) @@ -217,7 +217,7 @@ pub fn recursive_list_from_list_view(array: ArrayRef) -> VortexResult } Canonical::FixedSizeList(fixed_size_list) => { let converted_elements = - recursive_list_from_list_view(fixed_size_list.elements().clone())?; + recursive_list_from_list_view(Arc::clone(&fixed_size_list.elements()))?; // Avoid cloning if elements didn't change. if !Arc::ptr_eq(&converted_elements, fixed_size_list.elements()) { @@ -241,7 +241,7 @@ pub fn recursive_list_from_list_view(array: ArrayRef) -> VortexResult let mut any_changed = false; for field in fields.iter() { - let converted_field = recursive_list_from_list_view(field.clone())?; + let converted_field = recursive_list_from_list_view(Arc::clone(&field))?; // Avoid cloning if elements didn't change. any_changed |= !Arc::ptr_eq(&converted_field, field); converted_fields.push(converted_field); @@ -262,7 +262,7 @@ pub fn recursive_list_from_list_view(array: ArrayRef) -> VortexResult } Canonical::Extension(ext_array) => { let converted_storage = - recursive_list_from_list_view(ext_array.storage_array().clone())?; + recursive_list_from_list_view(Arc::clone(&ext_array.storage_array()))?; // Avoid cloning if elements didn't change. if !Arc::ptr_eq(&converted_storage, ext_array.storage_array()) { @@ -312,22 +312,22 @@ mod tests { let elements = buffer![0i32, 1, 2, 3, 4, 5, 6, 7, 8, 9].into_array(); let offsets = buffer![0u32, 3, 5, 7, 10].into_array(); let list_array = - ListArray::try_new(elements.clone(), offsets.clone(), Validity::NonNullable)?; + ListArray::try_new(Arc::clone(&elements), Arc::clone(&offsets), Validity::NonNullable)?; let mut ctx = LEGACY_SESSION.create_execution_ctx(); let list_view = list_view_from_list(list_array.clone(), &mut ctx)?; // Verify structure. assert_eq!(list_view.len(), 4); - assert_arrays_eq!(elements, list_view.elements().clone()); + assert_arrays_eq!(elements, Arc::clone(&list_view.elements())); // Verify offsets (should be same but without last element). let expected_offsets = buffer![0u32, 3, 5, 7].into_array(); - assert_arrays_eq!(expected_offsets, list_view.offsets().clone()); + assert_arrays_eq!(expected_offsets, Arc::clone(&list_view.offsets())); // Verify sizes. let expected_sizes = buffer![3u32, 2, 2, 3].into_array(); - assert_arrays_eq!(expected_sizes, list_view.sizes().clone()); + assert_arrays_eq!(expected_sizes, Arc::clone(&list_view.sizes())); // Verify data integrity. assert_arrays_eq!(list_array, list_view); @@ -340,12 +340,12 @@ mod tests { let list_array = list_from_list_view(list_view.clone())?; // Should have same elements. - assert_arrays_eq!(list_view.elements().clone(), list_array.elements().clone()); + assert_arrays_eq!(Arc::clone(&list_view.elements()), Arc::clone(&list_array.elements())); // ListArray offsets should have n+1 elements for n lists (add the final offset). // Check that the first n offsets match. let list_array_offsets_without_last = list_array.offsets().slice(0..list_view.len())?; - assert_arrays_eq!(list_view.offsets().clone(), list_array_offsets_without_last); + assert_arrays_eq!(Arc::clone(&list_view.offsets()), list_array_offsets_without_last); // Verify data integrity. assert_arrays_eq!(list_view, list_array); @@ -358,7 +358,7 @@ mod tests { let empty_elements = PrimitiveArray::from_iter::<[i32; 0]>([]).into_array(); let empty_offsets = buffer![0u32].into_array(); let empty_list = - ListArray::try_new(empty_elements.clone(), empty_offsets, Validity::NonNullable)?; + ListArray::try_new(Arc::clone(&empty_elements), empty_offsets, Validity::NonNullable)?; // This conversion will create an empty ListViewArray. // Note: list_view_from_list handles the empty case specially. @@ -382,7 +382,7 @@ mod tests { let offsets = buffer![0u32, 2, 4, 5].into_array(); let validity = Validity::Array(BoolArray::from_iter(vec![true, false, true]).into_array()); let nullable_list = - ListArray::try_new(elements.clone(), offsets.clone(), validity.clone())?; + ListArray::try_new(Arc::clone(&elements), Arc::clone(&offsets), validity.clone())?; let mut ctx = LEGACY_SESSION.create_execution_ctx(); let nullable_list_view = list_view_from_list(nullable_list.clone(), &mut ctx)?; @@ -445,7 +445,7 @@ mod tests { let elements = buffer![1i32, 2, 3, 4, 5].into_array(); let i32_offsets = buffer![0i32, 2, 5].into_array(); let list_i32 = - ListArray::try_new(elements.clone(), i32_offsets.clone(), Validity::NonNullable)?; + ListArray::try_new(Arc::clone(&elements), Arc::clone(&i32_offsets), Validity::NonNullable)?; let mut ctx = LEGACY_SESSION.create_execution_ctx(); let list_view_i32 = list_view_from_list(list_i32.clone(), &mut ctx)?; @@ -455,7 +455,7 @@ mod tests { // Test with i64 offsets. let i64_offsets = buffer![0i64, 2, 5].into_array(); let list_i64 = - ListArray::try_new(elements.clone(), i64_offsets.clone(), Validity::NonNullable)?; + ListArray::try_new(Arc::clone(&elements), Arc::clone(&i64_offsets), Validity::NonNullable)?; let list_view_i64 = list_view_from_list(list_i64.clone(), &mut ctx)?; assert_eq!(list_view_i64.offsets().dtype(), i64_offsets.dtype()); @@ -498,7 +498,7 @@ mod tests { let elements = buffer![100i32, 200, 300].into_array(); let offsets = buffer![0u32, 1, 2, 3].into_array(); let single_elem_list = - ListArray::try_new(elements.clone(), offsets, Validity::NonNullable)?; + ListArray::try_new(Arc::clone(&elements), offsets, Validity::NonNullable)?; let mut ctx = LEGACY_SESSION.create_execution_ctx(); let list_view = list_view_from_list(single_elem_list.clone(), &mut ctx)?; @@ -506,7 +506,7 @@ mod tests { // Verify sizes are all 1. let expected_sizes = buffer![1u32, 1, 1].into_array(); - assert_arrays_eq!(expected_sizes, list_view.sizes().clone()); + assert_arrays_eq!(expected_sizes, Arc::clone(&list_view.sizes())); // Round-trip. let converted_back = list_from_list_view(list_view)?; @@ -520,7 +520,7 @@ mod tests { let elements = buffer![1i32, 2, 3, 4, 5, 6].into_array(); let offsets = buffer![0u32, 2, 2, 3, 3, 6].into_array(); let mixed_list = - ListArray::try_new(elements.clone(), offsets.clone(), Validity::NonNullable)?; + ListArray::try_new(Arc::clone(&elements), Arc::clone(&offsets), Validity::NonNullable)?; let mut ctx = LEGACY_SESSION.create_execution_ctx(); let list_view = list_view_from_list(mixed_list.clone(), &mut ctx)?; @@ -528,7 +528,7 @@ mod tests { // Verify sizes. let expected_sizes = buffer![2u32, 0, 1, 0, 3].into_array(); - assert_arrays_eq!(expected_sizes, list_view.sizes().clone()); + assert_arrays_eq!(expected_sizes, Arc::clone(&list_view.sizes())); // Round-trip. let converted_back = list_from_list_view(list_view)?; @@ -685,7 +685,7 @@ mod tests { #[test] fn test_recursive_primitive_unchanged() -> VortexResult<()> { let prim = buffer![1i32, 2, 3].into_array(); - let prim_clone = prim.clone(); + let prim_clone = Arc::clone(&prim); let result = recursive_list_from_list_view(prim)?; assert!(Arc::ptr_eq(&result, &prim_clone)); diff --git a/vortex-array/src/arrays/listview/rebuild.rs b/vortex-array/src/arrays/listview/rebuild.rs index cf2725e5c68..e4953965064 100644 --- a/vortex-array/src/arrays/listview/rebuild.rs +++ b/vortex-array/src/arrays/listview/rebuild.rs @@ -24,6 +24,7 @@ use crate::match_each_integer_ptype; use crate::scalar::Scalar; use crate::scalar_fn::fns::operators::Operator; use crate::vtable::ValidityHelper; +use std::sync::Arc; /// Modes for rebuilding a [`ListViewArray`]. pub enum ListViewRebuildMode { @@ -350,7 +351,7 @@ impl ListViewArray { ListViewArray::new_unchecked( sliced_elements, adjusted_offsets, - self.sizes().clone(), + Arc::clone(&self.sizes()), self.validity(), ) .with_zero_copy_to_list(self.is_zero_copy_to_list()) diff --git a/vortex-array/src/arrays/listview/tests/filter.rs b/vortex-array/src/arrays/listview/tests/filter.rs index 8fad7569534..8c04f0c3d28 100644 --- a/vortex-array/src/arrays/listview/tests/filter.rs +++ b/vortex-array/src/arrays/listview/tests/filter.rs @@ -19,6 +19,7 @@ use crate::arrays::PrimitiveArray; use crate::assert_arrays_eq; use crate::compute::conformance::filter::test_filter_conformance; use crate::validity::Validity; +use std::sync::Arc; // Conformance tests for common filter scenarios. #[rstest] @@ -43,7 +44,7 @@ fn test_filter_preserves_unreferenced_elements() { let sizes = buffer![3u32, 2, 2, 2, 4].into_array(); let listview = - ListViewArray::new(elements.clone(), offsets, sizes, Validity::NonNullable).into_array(); + ListViewArray::new(Arc::clone(&elements), offsets, sizes, Validity::NonNullable).into_array(); // Filter to keep only 2 lists. let mask = Mask::from_iter([true, false, false, true, false]); @@ -75,7 +76,7 @@ fn test_filter_with_gaps() { let sizes = buffer![3u32, 3, 2, 2, 2].into_array(); let listview = - ListViewArray::new(elements.clone(), offsets, sizes, Validity::NonNullable).into_array(); + ListViewArray::new(Arc::clone(&elements), offsets, sizes, Validity::NonNullable).into_array(); // Filter to keep lists with gaps and overlaps. let mask = Mask::from_iter([false, true, true, true, false]); @@ -114,7 +115,7 @@ fn test_filter_constant_arrays() { let varying_sizes = buffer![1u32, 2, 3, 4].into_array(); let const_offset_list = ListViewArray::new( - elements.clone(), + Arc::clone(&elements), constant_offsets, varying_sizes, Validity::NonNullable, @@ -167,7 +168,7 @@ fn test_filter_extreme_offsets() { let sizes = buffer![5u32, 2, 5, 3, 4].into_array(); let listview = - ListViewArray::new(elements.clone(), offsets, sizes, Validity::NonNullable).into_array(); + ListViewArray::new(Arc::clone(&elements), offsets, sizes, Validity::NonNullable).into_array(); // Filter to keep only 2 lists, demonstrating we keep all 10000 elements. let mask = Mask::from_iter([false, true, false, false, true]); diff --git a/vortex-array/src/arrays/listview/tests/nested.rs b/vortex-array/src/arrays/listview/tests/nested.rs index c10e30838f0..f988c1f529a 100644 --- a/vortex-array/src/arrays/listview/tests/nested.rs +++ b/vortex-array/src/arrays/listview/tests/nested.rs @@ -15,6 +15,7 @@ use crate::dtype::Nullability; use crate::dtype::PType; use crate::dtype::StructFields; use crate::validity::Validity; +use std::sync::Arc; //////////////////////////////////////////////////////////////////////////////////////////////////// // ListView of ListView with overlapping data @@ -202,8 +203,8 @@ fn test_mixed_offset_size_types() { let inner_listview = ListViewArray::new( elements, - inner_offsets.clone(), - inner_sizes.clone(), + Arc::clone(&inner_offsets), + Arc::clone(&inner_sizes), Validity::NonNullable, ); diff --git a/vortex-array/src/arrays/listview/tests/operations.rs b/vortex-array/src/arrays/listview/tests/operations.rs index c22a21954d5..68bdfbc6012 100644 --- a/vortex-array/src/arrays/listview/tests/operations.rs +++ b/vortex-array/src/arrays/listview/tests/operations.rs @@ -445,9 +445,9 @@ fn test_constant_with_nulls() { let validity_mixed = Validity::Array(BoolArray::from_iter(vec![true, false]).into_array()); let listview_mixed = unsafe { ListViewArray::new_unchecked( - elements.clone(), - offsets.clone(), - sizes.clone(), + Arc::clone(&elements), + Arc::clone(&offsets), + Arc::clone(&sizes), validity_mixed, ) .with_zero_copy_to_list(true) @@ -460,9 +460,9 @@ fn test_constant_with_nulls() { let validity_all_null = Validity::AllInvalid; let listview_all_null = unsafe { ListViewArray::new_unchecked( - elements.clone(), - offsets.clone(), - sizes.clone(), + Arc::clone(&elements), + Arc::clone(&offsets), + Arc::clone(&sizes), validity_all_null, ) .with_zero_copy_to_list(true) @@ -516,7 +516,7 @@ fn test_mask_preserves_structure() { // Mask sets elements to null where true. let selection = Mask::from_iter([true, false, true, true]); - let result = listview.clone().mask((!&selection).into_array()).unwrap(); + let result = Arc::clone(&listview).mask((!&selection).into_array()).unwrap(); assert_eq!(result.len(), 4); // Length is preserved. let result_list = result.to_listview(); @@ -555,7 +555,7 @@ fn test_mask_with_existing_nulls() { // Mask additional elements. let selection = Mask::from_iter([false, true, true]); - let result = listview.clone().mask((!&selection).into_array()).unwrap(); + let result = Arc::clone(&listview).mask((!&selection).into_array()).unwrap(); let result_list = result.to_listview(); // Check combined validity: @@ -575,7 +575,7 @@ fn test_mask_with_gaps() { let listview = ListViewArray::new(elements, offsets, sizes, Validity::NonNullable).into_array(); let selection = Mask::from_iter([true, false, false]); - let result = listview.clone().mask((!&selection).into_array()).unwrap(); + let result = Arc::clone(&listview).mask((!&selection).into_array()).unwrap(); let result_list = result.to_listview(); assert_eq!(result_list.len(), 3); @@ -607,7 +607,7 @@ fn test_mask_constant_arrays() { .into_array(); let selection = Mask::from_iter([false, true, false]); - let result = const_list.clone().mask((!&selection).into_array()).unwrap(); + let result = Arc::clone(&const_list).mask((!&selection).into_array()).unwrap(); let result_list = result.to_listview(); assert_eq!(result_list.len(), 3); diff --git a/vortex-array/src/arrays/listview/tests/take.rs b/vortex-array/src/arrays/listview/tests/take.rs index a2c0aa52d87..af828b1357f 100644 --- a/vortex-array/src/arrays/listview/tests/take.rs +++ b/vortex-array/src/arrays/listview/tests/take.rs @@ -18,6 +18,7 @@ use crate::arrays::PrimitiveArray; use crate::assert_arrays_eq; use crate::compute::conformance::take::test_take_conformance; use crate::validity::Validity; +use std::sync::Arc; // Conformance tests for common take scenarios. #[rstest] @@ -42,7 +43,7 @@ fn test_take_preserves_unreferenced_elements() { let sizes = buffer![3u32, 2, 2, 2, 4].into_array(); let listview = - ListViewArray::new(elements.clone(), offsets, sizes, Validity::NonNullable).into_array(); + ListViewArray::new(Arc::clone(&elements), offsets, sizes, Validity::NonNullable).into_array(); // Take only 2 lists. let indices = buffer![1u32, 3].into_array(); @@ -72,7 +73,7 @@ fn test_take_with_gaps() { let sizes = buffer![3u32, 3, 2, 2, 2].into_array(); let listview = - ListViewArray::new(elements.clone(), offsets, sizes, Validity::NonNullable).into_array(); + ListViewArray::new(Arc::clone(&elements), offsets, sizes, Validity::NonNullable).into_array(); let indices = buffer![1u32, 3, 4, 2].into_array(); let result = listview.take(indices.to_array()).unwrap(); @@ -102,7 +103,7 @@ fn test_take_constant_arrays() { let varying_sizes = buffer![1u32, 2, 3, 4].into_array(); let const_offset_list = ListViewArray::new( - elements.clone(), + Arc::clone(&elements), constant_offsets, varying_sizes, Validity::NonNullable, @@ -156,7 +157,7 @@ fn test_take_extreme_offsets() { let sizes = buffer![5u32, 2, 5, 3, 4].into_array(); let listview = - ListViewArray::new(elements.clone(), offsets, sizes, Validity::NonNullable).into_array(); + ListViewArray::new(Arc::clone(&elements), offsets, sizes, Validity::NonNullable).into_array(); // Take only 2 lists, demonstrating we keep all 10000 elements. let indices = buffer![1u32, 4].into_array(); diff --git a/vortex-array/src/arrays/listview/vtable/mod.rs b/vortex-array/src/arrays/listview/vtable/mod.rs index d69d1ce8f18..a509fa4893e 100644 --- a/vortex-array/src/arrays/listview/vtable/mod.rs +++ b/vortex-array/src/arrays/listview/vtable/mod.rs @@ -207,7 +207,7 @@ impl VTable for ListView { slots.len() ); array.validity = match &slots[VALIDITY_SLOT] { - Some(arr) => Validity::Array(arr.clone()), + Some(arr) => Validity::Array(Arc::clone(&arr)), None => Validity::from(array.dtype.nullability()), }; array.slots = slots; diff --git a/vortex-array/src/arrays/masked/compute/mask.rs b/vortex-array/src/arrays/masked/compute/mask.rs index c23f499d71a..a5e35491e72 100644 --- a/vortex-array/src/arrays/masked/compute/mask.rs +++ b/vortex-array/src/arrays/masked/compute/mask.rs @@ -11,18 +11,19 @@ use crate::scalar_fn::EmptyOptions; use crate::scalar_fn::fns::mask::Mask as MaskExpr; use crate::scalar_fn::fns::mask::MaskReduce; use crate::validity::Validity; +use std::sync::Arc; impl MaskReduce for Masked { fn mask(array: &MaskedArray, mask: &ArrayRef) -> VortexResult> { // AND the existing validity mask with the new mask and push into child. let combined_mask = array .validity() - .and(Validity::Array(mask.clone()))? + .and(Validity::Array(Arc::clone(&mask)))? .to_array(array.len()); let masked_child = MaskExpr.try_new_array( array.child().len(), EmptyOptions, - [array.child().clone(), combined_mask], + [Arc::clone(&array.child()), combined_mask], )?; Ok(Some(masked_child)) } diff --git a/vortex-array/src/arrays/masked/execute.rs b/vortex-array/src/arrays/masked/execute.rs index 3d100338895..ad7a2221609 100644 --- a/vortex-array/src/arrays/masked/execute.rs +++ b/vortex-array/src/arrays/masked/execute.rs @@ -25,6 +25,7 @@ use crate::dtype::Nullability; use crate::executor::ExecutionCtx; use crate::match_each_decimal_value_type; use crate::validity::Validity; +use std::sync::Arc; /// TODO: replace usage of compute fn. /// Apply a validity mask to a canonical array, ANDing with existing validity. @@ -130,7 +131,7 @@ fn mask_validity_varbinview( Ok(unsafe { VarBinViewArray::new_handle_unchecked( array.views_handle().clone(), - array.buffers().clone(), + Arc::clone(&array.buffers()), dtype, new_validity, ) @@ -147,9 +148,9 @@ fn mask_validity_listview( // SAFETY: We're only changing validity, not the data structure Ok(unsafe { ListViewArray::new_unchecked( - array.elements().clone(), - array.offsets().clone(), - array.sizes().clone(), + Arc::clone(&array.elements()), + Arc::clone(&array.offsets()), + Arc::clone(&array.sizes()), new_validity, ) }) @@ -165,7 +166,7 @@ fn mask_validity_fixed_size_list( let new_validity = combine_validity(&array.validity()?, mask, len, ctx)?; // SAFETY: We're only changing validity, not the data structure Ok(unsafe { - FixedSizeListArray::new_unchecked(array.elements().clone(), list_size, new_validity, len) + FixedSizeListArray::new_unchecked(Arc::clone(&array.elements()), list_size, new_validity, len) }) } @@ -176,7 +177,7 @@ fn mask_validity_struct( ) -> VortexResult { let len = array.len(); let new_validity = combine_validity(&array.validity(), mask, len, ctx)?; - let fields = array.unmasked_fields().clone(); + let fields = Arc::clone(&array.unmasked_fields()); let struct_fields = array.struct_fields().clone(); // SAFETY: We're only changing validity, not the data structure Ok(unsafe { StructArray::new_unchecked(fields, struct_fields, len, new_validity) }) @@ -188,7 +189,7 @@ fn mask_validity_extension( ctx: &mut ExecutionCtx, ) -> VortexResult { // For extension arrays, we need to mask the underlying storage - let storage = array.storage_array().clone().execute::(ctx)?; + let storage = Arc::clone(&array.storage_array()).execute::(ctx)?; let masked_storage = mask_validity_canonical(storage, mask, ctx)?; let masked_storage = masked_storage.into_array(); Ok(ExtensionArray::new( @@ -204,7 +205,7 @@ fn mask_validity_variant( mask: &Mask, ctx: &mut ExecutionCtx, ) -> VortexResult { - let child = array.child().clone(); + let child = Arc::clone(&array.child()); let len = child.len(); let child_validity = child.validity()?; diff --git a/vortex-array/src/arrays/masked/tests.rs b/vortex-array/src/arrays/masked/tests.rs index 2046ce691f1..1c86890525c 100644 --- a/vortex-array/src/arrays/masked/tests.rs +++ b/vortex-array/src/arrays/masked/tests.rs @@ -15,6 +15,7 @@ use crate::assert_arrays_eq; use crate::dtype::DType; use crate::dtype::Nullability; use crate::validity::Validity; +use std::sync::Arc; #[rstest] #[case(Validity::AllValid, Nullability::Nullable)] @@ -73,7 +74,7 @@ fn test_masked_child_with_validity() { fn test_masked_child_all_valid() { // When validity is AllValid, masked_child should invert to AllInvalid. let child = PrimitiveArray::from_iter([10i32, 20, 30]).into_array(); - let array = MaskedArray::try_new(child.clone(), Validity::AllValid).unwrap(); + let array = MaskedArray::try_new(Arc::clone(&child), Validity::AllValid).unwrap(); assert_eq!(array.len(), 3); assert_eq!(array.valid_count().unwrap(), 3); diff --git a/vortex-array/src/arrays/masked/vtable/mod.rs b/vortex-array/src/arrays/masked/vtable/mod.rs index 3b8b3b792f8..da12daf9618 100644 --- a/vortex-array/src/arrays/masked/vtable/mod.rs +++ b/vortex-array/src/arrays/masked/vtable/mod.rs @@ -162,7 +162,7 @@ impl VTable for Masked { // While we could manually convert the dtype, `mask_validity_canonical` is already O(1) for // `AllTrue` masks (no data copying), so there's no benefit. - let child = array.child().clone().execute::(ctx)?; + let child = Arc::clone(&array.child()).execute::(ctx)?; Ok(ExecutionResult::done( mask_validity_canonical(child, &validity_mask, ctx)?.into_array(), )) diff --git a/vortex-array/src/arrays/patched/array.rs b/vortex-array/src/arrays/patched/array.rs index 6a7b9a28e21..31d0caa1f2b 100644 --- a/vortex-array/src/arrays/patched/array.rs +++ b/vortex-array/src/arrays/patched/array.rs @@ -27,6 +27,7 @@ use crate::match_each_unsigned_integer_ptype; use crate::patches::Patches; use crate::stats::ArrayStats; use crate::validity::Validity; +use std::sync::Arc; /// An array that partially "patches" another array with new values. /// @@ -276,8 +277,8 @@ impl PatchedArray { let sliced_lane_offsets = self .lane_offsets() .slice(lane_offsets_start..lane_offsets_stop)?; - let indices = self.patch_indices().clone(); - let values = self.patch_values().clone(); + let indices = Arc::clone(&self.patch_indices()); + let values = Arc::clone(&self.patch_values()); // Find the new start/end for slicing the inner array. // The inner array has already been sliced to start at position `offset` in absolute terms, diff --git a/vortex-array/src/arrays/patched/compute/compare.rs b/vortex-array/src/arrays/patched/compute/compare.rs index 43279501cdb..ed6bf916516 100644 --- a/vortex-array/src/arrays/patched/compute/compare.rs +++ b/vortex-array/src/arrays/patched/compute/compare.rs @@ -20,6 +20,7 @@ use crate::dtype::NativePType; use crate::match_each_native_ptype; use crate::scalar_fn::fns::binary::CompareKernel; use crate::scalar_fn::fns::operators::CompareOperator; +use std::sync::Arc; impl CompareKernel for Patched { fn compare( @@ -58,9 +59,9 @@ impl CompareKernel for Patched { let mut bits = BitBufferMut::from_buffer(bits.unwrap_host().into_mut(), offset, len); - let lane_offsets = lhs.lane_offsets().clone().execute::(ctx)?; - let indices = lhs.patch_indices().clone().execute::(ctx)?; - let values = lhs.patch_values().clone().execute::(ctx)?; + let lane_offsets = Arc::clone(&lhs.lane_offsets()).execute::(ctx)?; + let indices = Arc::clone(&lhs.patch_indices()).execute::(ctx)?; + let values = Arc::clone(&lhs.patch_values()).execute::(ctx)?; let n_lanes = lhs.n_lanes; match_each_native_ptype!(values.ptype(), |V| { diff --git a/vortex-array/src/arrays/patched/compute/take.rs b/vortex-array/src/arrays/patched/compute/take.rs index ec2a66d87dd..813da5a4080 100644 --- a/vortex-array/src/arrays/patched/compute/take.rs +++ b/vortex-array/src/arrays/patched/compute/take.rs @@ -17,6 +17,7 @@ use crate::dtype::IntegerPType; use crate::dtype::NativePType; use crate::match_each_native_ptype; use crate::match_each_unsigned_integer_ptype; +use std::sync::Arc; impl TakeExecute for Patched { fn take( @@ -32,7 +33,7 @@ impl TakeExecute for Patched { // Perform take on the inner array, including the placeholders. let inner = array .base_array() - .take(indices.clone())? + .take(Arc::clone(&indices))? .execute::(ctx)?; let PrimitiveArrayParts { @@ -45,7 +46,7 @@ impl TakeExecute for Patched { match_each_unsigned_integer_ptype!(indices_ptype, |I| { match_each_native_ptype!(ptype, |V| { - let indices = indices.clone().execute::(ctx)?; + let indices = Arc::clone(&indices).execute::(ctx)?; let lane_offsets = array .lane_offsets() .clone() diff --git a/vortex-array/src/arrays/patched/vtable/mod.rs b/vortex-array/src/arrays/patched/vtable/mod.rs index e015af1b352..31d4fafd7f0 100644 --- a/vortex-array/src/arrays/patched/vtable/mod.rs +++ b/vortex-array/src/arrays/patched/vtable/mod.rs @@ -146,10 +146,10 @@ impl VTable for Patched { fn child(array: &Self::Array, idx: usize) -> ArrayRef { match idx { - 0 => array.base_array().clone(), - 1 => array.lane_offsets().clone(), - 2 => array.patch_indices().clone(), - 3 => array.patch_values().clone(), + 0 => Arc::clone(&array.base_array()), + 1 => Arc::clone(&array.lane_offsets()), + 2 => Arc::clone(&array.patch_indices()), + 3 => Arc::clone(&array.patch_values()), _ => vortex_panic!("invalid child index for PatchedArray: {idx}"), } } @@ -659,10 +659,10 @@ mod tests { let array = make_patched_array(vec![0u16; 1024], &[1, 2, 3], &[10, 20, 30])?; // Get original children via accessor methods - let inner = array.base_array().clone(); - let lane_offsets = array.lane_offsets().clone(); - let indices = array.patch_indices().clone(); - let values = array.patch_values().clone(); + let inner = Arc::clone(&array.base_array()); + let lane_offsets = Arc::clone(&array.lane_offsets()); + let indices = Arc::clone(&array.patch_indices()); + let values = Arc::clone(&array.patch_values()); // Create new PatchedArray with same children using with_slots let array_ref = array.clone().into_array(); @@ -695,9 +695,9 @@ mod tests { // Create a different inner array (all 5s instead of 0s) let new_inner = PrimitiveArray::from_iter(vec![5u16; 10]).into_array(); - let lane_offsets = array.lane_offsets().clone(); - let indices = array.patch_indices().clone(); - let values = array.patch_values().clone(); + let lane_offsets = Arc::clone(&array.lane_offsets()); + let indices = Arc::clone(&array.patch_indices()); + let values = Arc::clone(&array.patch_values()); let array_ref = array.into_array(); let vtable = array_ref.vtable().clone_boxed(); diff --git a/vortex-array/src/arrays/patched/vtable/slice.rs b/vortex-array/src/arrays/patched/vtable/slice.rs index 543f6378426..a1edc458992 100644 --- a/vortex-array/src/arrays/patched/vtable/slice.rs +++ b/vortex-array/src/arrays/patched/vtable/slice.rs @@ -12,6 +12,7 @@ use crate::arrays::Patched; use crate::arrays::PatchedArray; use crate::arrays::slice::SliceReduce; use crate::stats::ArrayStats; +use std::sync::Arc; impl SliceReduce for Patched { fn slice(array: &Self::Array, range: Range) -> VortexResult> { @@ -36,8 +37,8 @@ impl SliceReduce for Patched { slots: vec![ Some(inner), Some(sliced_lane_offsets), - Some(array.patch_indices().clone()), - Some(array.patch_values().clone()), + Some(Arc::clone(&array.patch_indices())), + Some(Arc::clone(&array.patch_values())), ], n_lanes: array.n_lanes, offset: new_offset, diff --git a/vortex-array/src/arrays/primitive/array/patch.rs b/vortex-array/src/arrays/primitive/array/patch.rs index a8b1479ed80..ce5fe5090ee 100644 --- a/vortex-array/src/arrays/primitive/array/patch.rs +++ b/vortex-array/src/arrays/primitive/array/patch.rs @@ -16,11 +16,12 @@ use crate::match_each_native_ptype; use crate::patches::PATCH_CHUNK_SIZE; use crate::patches::Patches; use crate::validity::Validity; +use std::sync::Arc; impl PrimitiveArray { pub fn patch(self, patches: &Patches, ctx: &mut ExecutionCtx) -> VortexResult { - let patch_indices = patches.indices().clone().execute::(ctx)?; - let patch_values = patches.values().clone().execute::(ctx)?; + let patch_indices = Arc::clone(&patches.indices()).execute::(ctx)?; + let patch_values = Arc::clone(&patches.values()).execute::(ctx)?; let patched_validity = self.validity().patch( self.len(), diff --git a/vortex-array/src/arrays/primitive/compute/mask.rs b/vortex-array/src/arrays/primitive/compute/mask.rs index 1fb20d696ba..b8d908d7531 100644 --- a/vortex-array/src/arrays/primitive/compute/mask.rs +++ b/vortex-array/src/arrays/primitive/compute/mask.rs @@ -9,6 +9,7 @@ use crate::arrays::Primitive; use crate::arrays::PrimitiveArray; use crate::scalar_fn::fns::mask::MaskReduce; use crate::validity::Validity; +use std::sync::Arc; impl MaskReduce for Primitive { fn mask(array: &PrimitiveArray, mask: &ArrayRef) -> VortexResult> { @@ -17,7 +18,7 @@ impl MaskReduce for Primitive { PrimitiveArray::new_unchecked_from_handle( array.buffer_handle().clone(), array.ptype(), - array.validity().and(Validity::Array(mask.clone()))?, + array.validity().and(Validity::Array(Arc::clone(&mask)))?, ) .into_array() })) diff --git a/vortex-array/src/arrays/scalar_fn/rules.rs b/vortex-array/src/arrays/scalar_fn/rules.rs index 7b69d8f2431..e29c08bc18a 100644 --- a/vortex-array/src/arrays/scalar_fn/rules.rs +++ b/vortex-array/src/arrays/scalar_fn/rules.rs @@ -145,7 +145,7 @@ impl ReduceNode for ScalarFnArray { } fn child(&self, idx: usize) -> ReduceNodeRef { - Arc::new(self.get_child(idx).clone()) + Arc::new(Arc::clone(&self.get_child(idx))) } fn child_count(&self) -> usize { diff --git a/vortex-array/src/arrays/scalar_fn/vtable/mod.rs b/vortex-array/src/arrays/scalar_fn/vtable/mod.rs index d6eb44f9e65..b5c8c58dc84 100644 --- a/vortex-array/src/arrays/scalar_fn/vtable/mod.rs +++ b/vortex-array/src/arrays/scalar_fn/vtable/mod.rs @@ -358,7 +358,7 @@ impl scalar_fn::ScalarFnVTable for ArrayExpr { _args: &dyn ExecutionArgs, ctx: &mut ExecutionCtx, ) -> VortexResult { - crate::Executable::execute(options.0.clone(), ctx) + crate::Executable::execute(Arc::clone(&options.0), ctx) } fn validity( diff --git a/vortex-array/src/arrays/scalar_fn/vtable/validity.rs b/vortex-array/src/arrays/scalar_fn/vtable/validity.rs index 3bf356c82b4..6ea555bee85 100644 --- a/vortex-array/src/arrays/scalar_fn/vtable/validity.rs +++ b/vortex-array/src/arrays/scalar_fn/vtable/validity.rs @@ -19,6 +19,7 @@ use crate::scalar_fn::fns::literal::Literal; use crate::scalar_fn::fns::root::Root; use crate::validity::Validity; use crate::vtable::ValidityVTable; +use std::sync::Arc; /// Execute an expression tree recursively. /// @@ -57,7 +58,7 @@ impl ValidityVTable for ScalarFnVTable { if let Some(scalar) = child.as_constant() { return Ok(lit(scalar)); } - Expression::try_new(ScalarFn::new(ArrayExpr, FakeEq(child.clone())).erased(), []) + Expression::try_new(ScalarFn::new(ArrayExpr, FakeEq(Arc::clone(&child))).erased(), []) }) .collect::>()?; diff --git a/vortex-array/src/arrays/shared/array.rs b/vortex-array/src/arrays/shared/array.rs index 25f41f66ecd..b7e7d6cf991 100644 --- a/vortex-array/src/arrays/shared/array.rs +++ b/vortex-array/src/arrays/shared/array.rs @@ -95,7 +95,7 @@ impl SharedArray { return result.clone().map_err(Into::into); } - let computed = f(self.source().clone()) + let computed = f(Arc::clone(&self.source())) .await .map(|c| c.into_array()) .map_err(Arc::new); diff --git a/vortex-array/src/arrays/shared/tests.rs b/vortex-array/src/arrays/shared/tests.rs index b828aa8191a..87920d60f97 100644 --- a/vortex-array/src/arrays/shared/tests.rs +++ b/vortex-array/src/arrays/shared/tests.rs @@ -14,6 +14,7 @@ use crate::hash::ArrayEq; use crate::hash::Precision as HashPrecision; use crate::session::ArraySession; use crate::validity::Validity; +use std::sync::Arc; #[test] fn shared_array_caches_on_canonicalize() -> VortexResult<()> { @@ -23,7 +24,7 @@ fn shared_array_caches_on_canonicalize() -> VortexResult<()> { let session = VortexSession::empty().with::(); let mut ctx = ExecutionCtx::new(session); - let first = shared.get_or_compute(|source| source.clone().execute::(&mut ctx))?; + let first = shared.get_or_compute(|source| Arc::clone(&source).execute::(&mut ctx))?; // Second call should return cached without invoking the closure. let second = shared.get_or_compute(|_| panic!("should not execute twice"))?; diff --git a/vortex-array/src/arrays/shared/vtable.rs b/vortex-array/src/arrays/shared/vtable.rs index fbbfeb31316..c50ef366482 100644 --- a/vortex-array/src/arrays/shared/vtable.rs +++ b/vortex-array/src/arrays/shared/vtable.rs @@ -146,7 +146,7 @@ impl VTable for Shared { fn execute(array: Arc>, ctx: &mut ExecutionCtx) -> VortexResult { array - .get_or_compute(|source| source.clone().execute::(ctx)) + .get_or_compute(|source| Arc::clone(&source).execute::(ctx)) .map(ExecutionResult::done) } } diff --git a/vortex-array/src/arrays/slice/slice_.rs b/vortex-array/src/arrays/slice/slice_.rs index 6c1f10628be..52bb8cd5ce2 100644 --- a/vortex-array/src/arrays/slice/slice_.rs +++ b/vortex-array/src/arrays/slice/slice_.rs @@ -10,6 +10,7 @@ use crate::IntoArray; use crate::arrays::Slice; use crate::arrays::SliceArray; use crate::arrays::slice::SliceReduce; +use std::sync::Arc; impl SliceReduce for Slice { fn slice(array: &Self::Array, range: Range) -> VortexResult> { @@ -19,7 +20,7 @@ impl SliceReduce for Slice { let combined_end = inner_range.start + range.end; Ok(Some( - SliceArray::new(array.child().clone(), combined_start..combined_end).into_array(), + SliceArray::new(Arc::clone(&array.child()), combined_start..combined_end).into_array(), )) } } diff --git a/vortex-array/src/arrays/struct_/array.rs b/vortex-array/src/arrays/struct_/array.rs index 64e89fe23b9..8c17846d5ca 100644 --- a/vortex-array/src/arrays/struct_/array.rs +++ b/vortex-array/src/arrays/struct_/array.rs @@ -309,7 +309,7 @@ impl StructArray { let validity_slot = validity_to_child(&validity, length); let slots = once(validity_slot) - .chain(fields.iter().map(|f| Some(f.clone()))) + .chain(fields.iter().map(|f| Some(Arc::clone(&f)))) .collect(); Self { @@ -515,7 +515,7 @@ impl StructArray { let children: Arc<[ArrayRef]> = self.slots[FIELDS_OFFSET..] .iter() - .map(|s| s.as_ref().vortex_expect("StructArray field slot").clone()) + .map(|s| Arc::clone(&s.as_ref().vortex_expect("StructArray field slot"))) .chain(once(array)) .collect(); diff --git a/vortex-array/src/arrays/struct_/compute/mask.rs b/vortex-array/src/arrays/struct_/compute/mask.rs index 09f43e6b981..5f4c3e5096d 100644 --- a/vortex-array/src/arrays/struct_/compute/mask.rs +++ b/vortex-array/src/arrays/struct_/compute/mask.rs @@ -9,6 +9,7 @@ use crate::arrays::Struct; use crate::arrays::StructArray; use crate::scalar_fn::fns::mask::MaskReduce; use crate::validity::Validity; +use std::sync::Arc; impl MaskReduce for Struct { fn mask(array: &StructArray, mask: &ArrayRef) -> VortexResult> { @@ -16,7 +17,7 @@ impl MaskReduce for Struct { array.unmasked_fields().iter().cloned().collect::>(), array.struct_fields().clone(), array.len(), - array.validity().and(Validity::Array(mask.clone()))?, + array.validity().and(Validity::Array(Arc::clone(&mask)))?, ) .map(|a| Some(a.into_array())) } diff --git a/vortex-array/src/arrays/struct_/compute/mod.rs b/vortex-array/src/arrays/struct_/compute/mod.rs index af6d73cca69..55f16259359 100644 --- a/vortex-array/src/arrays/struct_/compute/mod.rs +++ b/vortex-array/src/arrays/struct_/compute/mod.rs @@ -38,6 +38,7 @@ mod tests { use crate::dtype::PType; use crate::dtype::StructFields; use crate::validity::Validity; +use std::sync::Arc; #[test] fn take_empty_struct() { @@ -129,7 +130,7 @@ mod tests { vec![ StructArray::try_new( ["left", "right"].into(), - vec![xs.clone(), xs], + vec![Arc::clone(&xs), xs], 5, Validity::NonNullable, ) diff --git a/vortex-array/src/arrays/struct_/compute/rules.rs b/vortex-array/src/arrays/struct_/compute/rules.rs index 78fa9af66fd..4b708d00ac7 100644 --- a/vortex-array/src/arrays/struct_/compute/rules.rs +++ b/vortex-array/src/arrays/struct_/compute/rules.rs @@ -24,6 +24,7 @@ use crate::scalar_fn::fns::get_item::GetItem; use crate::scalar_fn::fns::mask::Mask; use crate::scalar_fn::fns::mask::MaskReduceAdaptor; use crate::validity::Validity; +use std::sync::Arc; pub(crate) const PARENT_RULES: ParentRuleSet = ParentRuleSet::new(&[ ParentRuleSet::lift(&StructCastPushDownRule), @@ -113,7 +114,7 @@ impl ArrayParentReduceRule for StructGetItemRule { match child.validity() { Validity::NonNullable | Validity::AllValid => { // If the struct is non-nullable or all valid, the field's validity is unchanged - Ok(Some(field.clone())) + Ok(Some(Arc::clone(&field))) } Validity::AllInvalid => { // If everything is invalid, the field is also all invalid @@ -127,7 +128,7 @@ impl ArrayParentReduceRule for StructGetItemRule { } Validity::Array(mask) => { // If the validity is an array, we need to combine it with the field's validity - Mask.try_new_array(field.len(), EmptyOptions, [field.clone(), mask.clone()]) + Mask.try_new_array(field.len(), EmptyOptions, [Arc::clone(&field), Arc::clone(&mask)]) .map(Some) } } diff --git a/vortex-array/src/arrays/struct_/compute/take.rs b/vortex-array/src/arrays/struct_/compute/take.rs index 967f9eafc3f..5609f6c177a 100644 --- a/vortex-array/src/arrays/struct_/compute/take.rs +++ b/vortex-array/src/arrays/struct_/compute/take.rs @@ -12,6 +12,7 @@ use crate::arrays::dict::TakeReduce; use crate::builtins::ArrayBuiltins; use crate::scalar::Scalar; use crate::validity::Validity; +use std::sync::Arc; impl TakeReduce for Struct { fn take(array: &StructArray, indices: &ArrayRef) -> VortexResult> { @@ -39,7 +40,7 @@ impl TakeReduce for Struct { StructArray::try_new_with_dtype( array .iter_unmasked_fields() - .map(|field| field.take(inner_indices.clone())) + .map(|field| field.take(Arc::clone(&inner_indices))) .collect::, _>>()?, array.struct_fields().clone(), indices.len(), diff --git a/vortex-array/src/arrays/struct_/compute/zip.rs b/vortex-array/src/arrays/struct_/compute/zip.rs index d79ee278955..84de2ae49e1 100644 --- a/vortex-array/src/arrays/struct_/compute/zip.rs +++ b/vortex-array/src/arrays/struct_/compute/zip.rs @@ -15,6 +15,7 @@ use crate::arrays::StructArray; use crate::builtins::ArrayBuiltins; use crate::scalar_fn::fns::zip::ZipKernel; use crate::validity::Validity; +use std::sync::Arc; impl ZipKernel for Struct { fn zip( @@ -35,7 +36,7 @@ impl ZipKernel for Struct { let fields = if_true .iter_unmasked_fields() .zip(if_false.iter_unmasked_fields()) - .map(|(t, f)| ArrayBuiltins::zip(mask, t.clone(), f.clone())) + .map(|(t, f)| ArrayBuiltins::zip(mask, Arc::clone(&t), Arc::clone(&f))) .collect::>>()?; let v1 = if_true.validity(); @@ -99,7 +100,7 @@ mod tests { let result = mask .into_array() - .zip(if_true.clone(), if_false.clone()) + .zip(Arc::clone(&if_true), Arc::clone(&if_false)) .unwrap(); insta::assert_snapshot!(result.display_table(), @r" @@ -139,7 +140,7 @@ mod tests { let result = mask .into_array() - .zip(if_true.clone(), if_false.clone()) + .zip(Arc::clone(&if_true), Arc::clone(&if_false)) .unwrap(); insta::assert_snapshot!(result.display_table(), @r" diff --git a/vortex-array/src/arrays/varbin/compute/cast.rs b/vortex-array/src/arrays/varbin/compute/cast.rs index 28e493a3120..ac8bed7239a 100644 --- a/vortex-array/src/arrays/varbin/compute/cast.rs +++ b/vortex-array/src/arrays/varbin/compute/cast.rs @@ -9,6 +9,7 @@ use crate::arrays::VarBin; use crate::arrays::VarBinArray; use crate::dtype::DType; use crate::scalar_fn::fns::cast::CastReduce; +use std::sync::Arc; impl CastReduce for VarBin { fn cast(array: &VarBinArray, dtype: &DType) -> VortexResult> { @@ -23,7 +24,7 @@ impl CastReduce for VarBin { let new_dtype = array.dtype().with_nullability(new_nullability); Ok(Some( VarBinArray::try_new( - array.offsets().clone(), + Arc::clone(&array.offsets()), array.bytes().clone(), new_dtype, new_validity, diff --git a/vortex-array/src/arrays/varbin/compute/compare.rs b/vortex-array/src/arrays/varbin/compute/compare.rs index b65d652680e..70c01fd3472 100644 --- a/vortex-array/src/arrays/varbin/compute/compare.rs +++ b/vortex-array/src/arrays/varbin/compute/compare.rs @@ -28,6 +28,7 @@ use crate::match_each_integer_ptype; use crate::scalar_fn::fns::binary::CompareKernel; use crate::scalar_fn::fns::operators::CompareOperator; use crate::scalar_fn::fns::operators::Operator; +use std::sync::Arc; // This implementation exists so we can have custom translation of RHS to arrow that's not the same as IntoCanonical impl CompareKernel for VarBin { @@ -58,13 +59,13 @@ impl CompareKernel for VarBin { CompareOperator::Gte => BitBuffer::new_set(len), // Every possible value is >= "" CompareOperator::Lt => BitBuffer::new_unset(len), // No value is < "" CompareOperator::Eq | CompareOperator::Lte => { - let lhs_offsets = lhs.offsets().clone().execute::(ctx)?; + let lhs_offsets = Arc::clone(&lhs.offsets()).execute::(ctx)?; match_each_integer_ptype!(lhs_offsets.ptype(), |P| { compare_offsets_to_empty::

(lhs_offsets, true) }) } CompareOperator::NotEq | CompareOperator::Gt => { - let lhs_offsets = lhs.offsets().clone().execute::(ctx)?; + let lhs_offsets = Arc::clone(&lhs.offsets()).execute::(ctx)?; match_each_integer_ptype!(lhs_offsets.ptype(), |P| { compare_offsets_to_empty::

(lhs_offsets, false) }) diff --git a/vortex-array/src/arrays/varbin/compute/mask.rs b/vortex-array/src/arrays/varbin/compute/mask.rs index 3a796be28fe..036650024e2 100644 --- a/vortex-array/src/arrays/varbin/compute/mask.rs +++ b/vortex-array/src/arrays/varbin/compute/mask.rs @@ -9,15 +9,16 @@ use crate::arrays::VarBin; use crate::arrays::VarBinArray; use crate::scalar_fn::fns::mask::MaskReduce; use crate::validity::Validity; +use std::sync::Arc; impl MaskReduce for VarBin { fn mask(array: &VarBinArray, mask: &ArrayRef) -> VortexResult> { Ok(Some( VarBinArray::try_new( - array.offsets().clone(), + Arc::clone(&array.offsets()), array.bytes().clone(), array.dtype().as_nullable(), - array.validity().and(Validity::Array(mask.clone()))?, + array.validity().and(Validity::Array(Arc::clone(&mask)))?, )? .into_array(), )) diff --git a/vortex-array/src/arrays/varbinview/compute/cast.rs b/vortex-array/src/arrays/varbinview/compute/cast.rs index b15c2ed11ba..0c875384d2a 100644 --- a/vortex-array/src/arrays/varbinview/compute/cast.rs +++ b/vortex-array/src/arrays/varbinview/compute/cast.rs @@ -9,6 +9,7 @@ use crate::arrays::VarBinView; use crate::arrays::VarBinViewArray; use crate::dtype::DType; use crate::scalar_fn::fns::cast::CastReduce; +use std::sync::Arc; impl CastReduce for VarBinView { fn cast(array: &VarBinViewArray, dtype: &DType) -> VortexResult> { @@ -27,7 +28,7 @@ impl CastReduce for VarBinView { Ok(Some( VarBinViewArray::new_handle_unchecked( array.views_handle().clone(), - array.buffers().clone(), + Arc::clone(&array.buffers()), new_dtype, new_validity, ) diff --git a/vortex-array/src/arrays/varbinview/compute/mask.rs b/vortex-array/src/arrays/varbinview/compute/mask.rs index ac6d64779c5..201f1374d1c 100644 --- a/vortex-array/src/arrays/varbinview/compute/mask.rs +++ b/vortex-array/src/arrays/varbinview/compute/mask.rs @@ -9,6 +9,7 @@ use crate::arrays::VarBinView; use crate::arrays::VarBinViewArray; use crate::scalar_fn::fns::mask::MaskReduce; use crate::validity::Validity; +use std::sync::Arc; impl MaskReduce for VarBinView { fn mask(array: &VarBinViewArray, mask: &ArrayRef) -> VortexResult> { @@ -17,9 +18,9 @@ impl MaskReduce for VarBinView { Ok(Some( VarBinViewArray::new_handle_unchecked( array.views_handle().clone(), - array.buffers().clone(), + Arc::clone(&array.buffers()), array.dtype().as_nullable(), - array.validity().and(Validity::Array(mask.clone()))?, + array.validity().and(Validity::Array(Arc::clone(&mask)))?, ) .into_array(), )) diff --git a/vortex-array/src/arrays/varbinview/compute/take.rs b/vortex-array/src/arrays/varbinview/compute/take.rs index 388124fb007..78f4f4be514 100644 --- a/vortex-array/src/arrays/varbinview/compute/take.rs +++ b/vortex-array/src/arrays/varbinview/compute/take.rs @@ -19,6 +19,7 @@ use crate::arrays::varbinview::BinaryView; use crate::buffer::BufferHandle; use crate::executor::ExecutionCtx; use crate::match_each_integer_ptype; +use std::sync::Arc; impl TakeExecute for VarBinView { /// Take involves creating a new array that references the old array, just with the given set of views. @@ -40,7 +41,7 @@ impl TakeExecute for VarBinView { Ok(Some( VarBinViewArray::new_handle_unchecked( BufferHandle::new_host(views_buffer.into_byte_buffer()), - array.buffers().clone(), + Arc::clone(&array.buffers()), array .dtype() .union_nullability(indices.dtype().nullability()), diff --git a/vortex-array/src/arrow/convert.rs b/vortex-array/src/arrow/convert.rs index c901bdc7fd2..007a5d0830c 100644 --- a/vortex-array/src/arrow/convert.rs +++ b/vortex-array/src/arrow/convert.rs @@ -1008,14 +1008,14 @@ mod tests { assert_eq!(vortex_array_non_null.len(), 4); // Verify metadata - should be TemporalArray with Second time unit - let temporal_array = TemporalArray::try_from(vortex_array.clone()).unwrap(); + let temporal_array = TemporalArray::try_from(Arc::clone(&vortex_array)).unwrap(); assert_eq!( temporal_array.temporal_metadata().time_unit(), TimeUnit::Seconds ); let temporal_array_non_null = - TemporalArray::try_from(vortex_array_non_null.clone()).unwrap(); + TemporalArray::try_from(Arc::clone(&vortex_array_non_null)).unwrap(); assert_eq!( temporal_array_non_null.temporal_metadata().time_unit(), TimeUnit::Seconds @@ -1112,14 +1112,14 @@ mod tests { assert_eq!(vortex_array_non_null.len(), 4); // Verify metadata - should be TemporalArray with Second time unit - let temporal_array = TemporalArray::try_from(vortex_array.clone()).unwrap(); + let temporal_array = TemporalArray::try_from(Arc::clone(&vortex_array)).unwrap(); assert_eq!( temporal_array.temporal_metadata().time_unit(), TimeUnit::Seconds ); let temporal_array_non_null = - TemporalArray::try_from(vortex_array_non_null.clone()).unwrap(); + TemporalArray::try_from(Arc::clone(&vortex_array_non_null)).unwrap(); assert_eq!( temporal_array_non_null.temporal_metadata().time_unit(), TimeUnit::Seconds @@ -1506,7 +1506,7 @@ mod tests { // Create a FixedSizeListArray with list_size=3 let field = Arc::new(Field::new("item", DataType::Int32, true)); let arrow_array = - ArrowFixedSizeListArray::try_new(field.clone(), 3, Arc::new(values), None).unwrap(); + ArrowFixedSizeListArray::try_new(Arc::clone(&field), 3, Arc::new(values), None).unwrap(); let vortex_array = ArrayRef::from_arrow(&arrow_array, false).unwrap(); assert_eq!(vortex_array.len(), 4); @@ -1572,7 +1572,7 @@ mod tests { let field = Arc::new(Field::new("item", DataType::Int32, true)); let arrow_array = GenericListViewArray::try_new( - field.clone(), + Arc::clone(&field), offsets.clone(), sizes.clone(), Arc::new(values.clone()), @@ -1598,7 +1598,7 @@ mod tests { arrow_buffer::NullBuffer::new(BooleanBuffer::from(vec![true, false, true, true])); let arrow_array_nullable = GenericListViewArray::try_new( - field.clone(), + Arc::clone(&field), offsets, sizes, Arc::new(values.clone()), diff --git a/vortex-array/src/arrow/executor/fixed_size_list.rs b/vortex-array/src/arrow/executor/fixed_size_list.rs index 92546322cf6..1e6b1c601d1 100644 --- a/vortex-array/src/arrow/executor/fixed_size_list.rs +++ b/vortex-array/src/arrow/executor/fixed_size_list.rs @@ -57,7 +57,7 @@ fn list_to_list( Ok(Arc::new( arrow_array::FixedSizeListArray::try_new_with_length( - elements_field.clone(), + Arc::clone(&elements_field), list_size, elements, null_buffer, diff --git a/vortex-array/src/arrow/executor/list.rs b/vortex-array/src/arrow/executor/list.rs index a4996ce43bb..dc166ec57b2 100644 --- a/vortex-array/src/arrow/executor/list.rs +++ b/vortex-array/src/arrow/executor/list.rs @@ -47,7 +47,7 @@ pub(super) fn to_arrow_list( if let Some(chunked) = array.as_opt::() { let mut arrow_chunks: Vec = Vec::with_capacity(chunked.nchunks()); for chunk in chunked.chunks() { - arrow_chunks.push(to_arrow_list::(chunk.clone(), elements_field, ctx)?); + arrow_chunks.push(to_arrow_list::(Arc::clone(&chunk), elements_field, ctx)?); } let refs = arrow_chunks.iter().map(|a| a.as_ref()).collect::>(); @@ -108,7 +108,7 @@ fn list_to_list( // TODO(ngates): use new_unchecked when it is added to arrow-rs. Ok(Arc::new(GenericListArray::::new( - elements_field.clone(), + Arc::clone(&elements_field), offsets, elements, null_buffer, @@ -128,7 +128,7 @@ fn list_view_zctl( .clone() .execute_arrow(Some(elements_field.data_type()), ctx)?; return Ok(Arc::new(GenericListArray::::new( - elements_field.clone(), + Arc::clone(&elements_field), OffsetBuffer::new_empty(), elements, None, @@ -184,7 +184,7 @@ fn list_view_zctl( let null_buffer = to_arrow_null_buffer(validity, sizes.len(), ctx)?; Ok(Arc::new(GenericListArray::::new( - elements_field.clone(), + Arc::clone(&elements_field), offsets.freeze().into_arrow_offset_buffer(), elements, null_buffer, diff --git a/vortex-array/src/arrow/executor/list_view.rs b/vortex-array/src/arrow/executor/list_view.rs index ad822f6db5e..7631b151f46 100644 --- a/vortex-array/src/arrow/executor/list_view.rs +++ b/vortex-array/src/arrow/executor/list_view.rs @@ -71,7 +71,7 @@ fn list_view_to_list_view( let null_buffer = to_arrow_null_buffer(validity, offsets.len(), ctx)?; Ok(Arc::new(GenericListViewArray::::new( - elements_field.clone(), + Arc::clone(&elements_field), offsets, sizes, elements, diff --git a/vortex-array/src/arrow/executor/run_end.rs b/vortex-array/src/arrow/executor/run_end.rs index 095d3280829..8de0969e70b 100644 --- a/vortex-array/src/arrow/executor/run_end.rs +++ b/vortex-array/src/arrow/executor/run_end.rs @@ -96,7 +96,7 @@ fn run_end_to_arrow( children.len() ); - let arrow_ends = children[0].clone().execute_arrow(Some(ends_type), ctx)?; + let arrow_ends = Arc::clone(&children[0]).execute_arrow(Some(ends_type), ctx)?; let arrow_values = children[1] .clone() .execute_arrow(Some(values_type.data_type()), ctx)?; diff --git a/vortex-array/src/arrow/executor/struct_.rs b/vortex-array/src/arrow/executor/struct_.rs index 415a7503ee7..71ce4969465 100644 --- a/vortex-array/src/arrow/executor/struct_.rs +++ b/vortex-array/src/arrow/executor/struct_.rs @@ -158,7 +158,7 @@ fn create_from_fields( // No target fields specified - use preferred types for each child let mut arrow_arrays = Vec::with_capacity(vortex_fields.len()); for vx_field in vortex_fields.iter() { - let arrow_array = vx_field.clone().execute_arrow(None, ctx)?; + let arrow_array = Arc::clone(&vx_field).execute_arrow(None, ctx)?; arrow_arrays.push(arrow_array); } diff --git a/vortex-array/src/builders/fixed_size_list.rs b/vortex-array/src/builders/fixed_size_list.rs index c7ecf0a59b4..8d037c8fdb5 100644 --- a/vortex-array/src/builders/fixed_size_list.rs +++ b/vortex-array/src/builders/fixed_size_list.rs @@ -301,12 +301,12 @@ mod tests { #[test] fn test_values() { let dtype: Arc = Arc::new(I32.into()); - let mut builder = FixedSizeListBuilder::with_capacity(dtype.clone(), 3, NonNullable, 0); + let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 3, NonNullable, 0); builder .append_value( Scalar::fixed_size_list( - dtype.clone(), + Arc::clone(&dtype), vec![1i32.into(), 2i32.into(), 3i32.into()], NonNullable, ) @@ -337,12 +337,12 @@ mod tests { fn test_degenerate_size_zero_non_nullable() { let dtype: Arc = Arc::new(I32.into()); let mut builder = - FixedSizeListBuilder::with_capacity(dtype.clone(), 0, NonNullable, 10000000); + FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 0, NonNullable, 10000000); // Append multiple "empty" lists. for _ in 0..100 { builder - .append_value(Scalar::fixed_size_list(dtype.clone(), vec![], NonNullable).as_list()) + .append_value(Scalar::fixed_size_list(Arc::clone(&dtype), vec![], NonNullable).as_list()) .unwrap(); } @@ -359,14 +359,14 @@ mod tests { fn test_degenerate_size_zero_nullable() { // Use nullable elements since we'll be appending nulls let dtype: Arc = Arc::new(DType::Primitive(I32, Nullable)); - let mut builder = FixedSizeListBuilder::with_capacity(dtype.clone(), 0, Nullable, 10000000); + let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 0, Nullable, 10000000); // Mix of null and non-null empty lists. for i in 0..100 { if i % 2 == 0 { builder .append_value( - Scalar::fixed_size_list(dtype.clone(), vec![], Nullable).as_list(), + Scalar::fixed_size_list(Arc::clone(&dtype), vec![], Nullable).as_list(), ) .unwrap(); } else { @@ -386,14 +386,14 @@ mod tests { fn test_capacity_growth() { let dtype: Arc = Arc::new(I32.into()); // Start with capacity 0. - let mut builder = FixedSizeListBuilder::with_capacity(dtype.clone(), 2, NonNullable, 0); + let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 2, NonNullable, 0); // Add more items than initial capacity. for i in 0..5 { builder .append_value( Scalar::fixed_size_list( - dtype.clone(), + Arc::clone(&dtype), vec![(i * 2).into(), (i * 2 + 1).into()], NonNullable, ) @@ -426,11 +426,11 @@ mod tests { #[test] fn test_nullable_lists_non_nullable_elements() { let dtype: Arc = Arc::new(DType::Primitive(I32, NonNullable)); - let mut builder = FixedSizeListBuilder::with_capacity(dtype.clone(), 2, Nullable, 0); + let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 2, Nullable, 0); builder .append_value( - Scalar::fixed_size_list(dtype.clone(), vec![1i32.into(), 2i32.into()], Nullable) + Scalar::fixed_size_list(Arc::clone(&dtype), vec![1i32.into(), 2i32.into()], Nullable) .as_list(), ) .unwrap(); @@ -455,12 +455,12 @@ mod tests { #[test] fn test_non_nullable_lists_nullable_elements() { let dtype: Arc = Arc::new(DType::Primitive(I32, Nullable)); - let mut builder = FixedSizeListBuilder::with_capacity(dtype.clone(), 3, NonNullable, 0); + let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 3, NonNullable, 0); builder .append_value( Scalar::fixed_size_list( - dtype.clone(), + Arc::clone(&dtype), vec![ Scalar::primitive(1i32, Nullable), Scalar::null(dtype.as_ref().clone()), @@ -578,7 +578,7 @@ mod tests { #[test] fn test_invalid_size_error() { let dtype: Arc = Arc::new(I32.into()); - let mut builder = FixedSizeListBuilder::with_capacity(dtype.clone(), 3, NonNullable, 0); + let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 3, NonNullable, 0); // Try to append a list with wrong size. let result = builder.append_value( @@ -683,7 +683,7 @@ mod tests { 0, ); - let mut builder = FixedSizeListBuilder::with_capacity(dtype.clone(), 3, NonNullable, 0); + let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 3, NonNullable, 0); // Add some initial data. builder @@ -708,7 +708,7 @@ mod tests { fn test_mixed_operations() { // Use nullable elements since we'll be appending nulls let dtype: Arc = Arc::new(DType::Primitive(I32, Nullable)); - let mut builder = FixedSizeListBuilder::with_capacity(dtype.clone(), 2, Nullable, 0); + let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 2, Nullable, 0); // Mix of operations. builder @@ -755,16 +755,16 @@ mod tests { #[test] fn test_append_scalar() { let dtype: Arc = Arc::new(I32.into()); - let mut builder = FixedSizeListBuilder::with_capacity(dtype.clone(), 2, Nullable, 10); + let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 2, Nullable, 10); // Test appending a valid fixed-size list. let list_scalar1 = - Scalar::fixed_size_list(dtype.clone(), vec![1i32.into(), 2i32.into()], Nullable); + Scalar::fixed_size_list(Arc::clone(&dtype), vec![1i32.into(), 2i32.into()], Nullable); builder.append_scalar(&list_scalar1).unwrap(); // Test appending another list. let list_scalar2 = - Scalar::fixed_size_list(dtype.clone(), vec![3i32.into(), 4i32.into()], Nullable); + Scalar::fixed_size_list(Arc::clone(&dtype), vec![3i32.into(), 4i32.into()], Nullable); builder.append_scalar(&list_scalar2).unwrap(); // Test appending null via builder method (since fixed-size list null handling is special). @@ -805,7 +805,7 @@ mod tests { #[test] fn test_append_array_as_list() { let dtype: Arc = Arc::new(I32.into()); - let mut builder = FixedSizeListBuilder::with_capacity(dtype.clone(), 3, NonNullable, 10); + let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 3, NonNullable, 10); // Append a primitive array as a single list entry. let arr1 = buffer![1i32, 2, 3].into_array(); @@ -815,7 +815,7 @@ mod tests { builder .append_value( Scalar::fixed_size_list( - dtype.clone(), + Arc::clone(&dtype), vec![10i32.into(), 11i32.into(), 12i32.into()], NonNullable, ) @@ -831,7 +831,7 @@ mod tests { builder .append_value( Scalar::fixed_size_list( - dtype.clone(), + Arc::clone(&dtype), vec![20i32.into(), 21i32.into(), 22i32.into()], NonNullable, ) @@ -851,7 +851,7 @@ mod tests { ); // Test dtype mismatch error. - let mut builder = FixedSizeListBuilder::with_capacity(dtype.clone(), 3, NonNullable, 10); + let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 3, NonNullable, 10); let wrong_dtype_arr = buffer![1i64, 2, 3].into_array(); assert!(builder.append_array_as_list(&wrong_dtype_arr).is_err()); diff --git a/vortex-array/src/builders/list.rs b/vortex-array/src/builders/list.rs index efdd44bd739..e51f6a26cd1 100644 --- a/vortex-array/src/builders/list.rs +++ b/vortex-array/src/builders/list.rs @@ -344,12 +344,12 @@ mod tests { #[test] fn test_values() { let dtype: Arc = Arc::new(I32.into()); - let mut builder = ListBuilder::::with_capacity(dtype.clone(), NonNullable, 0, 0); + let mut builder = ListBuilder::::with_capacity(Arc::clone(&dtype), NonNullable, 0, 0); builder .append_value( Scalar::list( - dtype.clone(), + Arc::clone(&dtype), vec![1i32.into(), 2i32.into(), 3i32.into()], NonNullable, ) @@ -380,7 +380,7 @@ mod tests { #[test] fn test_append_empty_list() { let dtype: Arc = Arc::new(I32.into()); - let mut builder = ListBuilder::::with_capacity(dtype.clone(), NonNullable, 0, 0); + let mut builder = ListBuilder::::with_capacity(Arc::clone(&dtype), NonNullable, 0, 0); assert!( builder @@ -392,12 +392,12 @@ mod tests { #[test] fn test_nullable_values() { let dtype: Arc = Arc::new(I32.into()); - let mut builder = ListBuilder::::with_capacity(dtype.clone(), Nullable, 0, 0); + let mut builder = ListBuilder::::with_capacity(Arc::clone(&dtype), Nullable, 0, 0); builder .append_value( Scalar::list( - dtype.clone(), + Arc::clone(&dtype), vec![1i32.into(), 2i32.into(), 3i32.into()], NonNullable, ) @@ -406,7 +406,7 @@ mod tests { .unwrap(); builder - .append_value(Scalar::list_empty(dtype.clone(), NonNullable).as_list()) + .append_value(Scalar::list_empty(Arc::clone(&dtype), NonNullable).as_list()) .unwrap(); builder @@ -528,22 +528,22 @@ mod tests { #[test] fn test_append_scalar() { let dtype: Arc = Arc::new(I32.into()); - let mut builder = ListBuilder::::with_capacity(dtype.clone(), Nullable, 20, 10); + let mut builder = ListBuilder::::with_capacity(Arc::clone(&dtype), Nullable, 20, 10); // Test appending a valid list. - let list_scalar1 = Scalar::list(dtype.clone(), vec![1i32.into(), 2i32.into()], Nullable); + let list_scalar1 = Scalar::list(Arc::clone(&dtype), vec![1i32.into(), 2i32.into()], Nullable); builder.append_scalar(&list_scalar1).unwrap(); // Test appending another list. let list_scalar2 = Scalar::list( - dtype.clone(), + Arc::clone(&dtype), vec![3i32.into(), 4i32.into(), 5i32.into()], Nullable, ); builder.append_scalar(&list_scalar2).unwrap(); // Test appending null value. - let null_scalar = Scalar::null(DType::List(dtype.clone(), Nullable)); + let null_scalar = Scalar::null(DType::List(Arc::clone(&dtype), Nullable)); builder.append_scalar(&null_scalar).unwrap(); let array = builder.finish_into_list(); @@ -586,7 +586,7 @@ mod tests { #[test] fn test_append_array_as_list() { let dtype: Arc = Arc::new(I32.into()); - let mut builder = ListBuilder::::with_capacity(dtype.clone(), NonNullable, 20, 10); + let mut builder = ListBuilder::::with_capacity(Arc::clone(&dtype), NonNullable, 20, 10); // Append a primitive array as a single list entry. let arr1 = buffer![1i32, 2, 3].into_array(); @@ -595,7 +595,7 @@ mod tests { // Interleave with a list scalar. builder .append_value( - Scalar::list(dtype.clone(), vec![10i32.into(), 11i32.into()], NonNullable) + Scalar::list(Arc::clone(&dtype), vec![10i32.into(), 11i32.into()], NonNullable) .as_list(), ) .unwrap(); @@ -610,7 +610,7 @@ mod tests { // Interleave with another list scalar (empty list). builder - .append_value(Scalar::list_empty(dtype.clone(), NonNullable).as_list()) + .append_value(Scalar::list_empty(Arc::clone(&dtype), NonNullable).as_list()) .unwrap(); let list = builder.finish_into_list(); diff --git a/vortex-array/src/builders/listview.rs b/vortex-array/src/builders/listview.rs index c8e4044c915..f36bcf7b31a 100644 --- a/vortex-array/src/builders/listview.rs +++ b/vortex-array/src/builders/listview.rs @@ -455,13 +455,13 @@ mod tests { #[test] fn test_basic_append_and_nulls() { let dtype: Arc = Arc::new(I32.into()); - let mut builder = ListViewBuilder::::with_capacity(dtype.clone(), Nullable, 0, 0); + let mut builder = ListViewBuilder::::with_capacity(Arc::clone(&dtype), Nullable, 0, 0); // Append a regular list. builder .append_value( Scalar::list( - dtype.clone(), + Arc::clone(&dtype), vec![1i32.into(), 2i32.into(), 3i32.into()], NonNullable, ) @@ -471,7 +471,7 @@ mod tests { // Append an empty list. builder - .append_value(Scalar::list_empty(dtype.clone(), NonNullable).as_list()) + .append_value(Scalar::list_empty(Arc::clone(&dtype), NonNullable).as_list()) .unwrap(); // Append a null list. @@ -511,11 +511,11 @@ mod tests { // Test u32 offsets with u8 sizes. let dtype: Arc = Arc::new(I32.into()); let mut builder = - ListViewBuilder::::with_capacity(dtype.clone(), NonNullable, 0, 0); + ListViewBuilder::::with_capacity(Arc::clone(&dtype), NonNullable, 0, 0); builder .append_value( - Scalar::list(dtype.clone(), vec![1i32.into(), 2i32.into()], NonNullable).as_list(), + Scalar::list(Arc::clone(&dtype), vec![1i32.into(), 2i32.into()], NonNullable).as_list(), ) .unwrap(); @@ -548,12 +548,12 @@ mod tests { // Test u64 offsets with u16 sizes. let dtype2: Arc = Arc::new(I32.into()); let mut builder2 = - ListViewBuilder::::with_capacity(dtype2.clone(), NonNullable, 0, 0); + ListViewBuilder::::with_capacity(Arc::clone(&dtype2), NonNullable, 0, 0); for i in 0..5 { builder2 .append_value( - Scalar::list(dtype2.clone(), vec![(i * 10).into()], NonNullable).as_list(), + Scalar::list(Arc::clone(&dtype2), vec![(i * 10).into()], NonNullable).as_list(), ) .unwrap(); } @@ -573,7 +573,7 @@ mod tests { #[test] fn test_builder_trait_methods() { let dtype: Arc = Arc::new(I32.into()); - let mut builder = ListViewBuilder::::with_capacity(dtype.clone(), Nullable, 0, 0); + let mut builder = ListViewBuilder::::with_capacity(Arc::clone(&dtype), Nullable, 0, 0); // Test append_zeros (creates empty lists). builder.append_zeros(2); @@ -619,7 +619,7 @@ mod tests { ) .unwrap(); - let mut builder = ListViewBuilder::::with_capacity(dtype.clone(), Nullable, 0, 0); + let mut builder = ListViewBuilder::::with_capacity(Arc::clone(&dtype), Nullable, 0, 0); // Add initial data. builder @@ -667,7 +667,7 @@ mod tests { fn test_error_append_null_to_non_nullable() { let dtype: Arc = Arc::new(I32.into()); let mut builder = - ListViewBuilder::::with_capacity(dtype.clone(), NonNullable, 0, 0); + ListViewBuilder::::with_capacity(Arc::clone(&dtype), NonNullable, 0, 0); // Create a null list with nullable type (since Scalar::null requires nullable type). let null_scalar = Scalar::null(DType::List(dtype, Nullable)); @@ -690,7 +690,7 @@ mod tests { let dtype: Arc = Arc::new(I32.into()); let mut builder = - ListViewBuilder::::with_capacity(dtype.clone(), NonNullable, 20, 10); + ListViewBuilder::::with_capacity(Arc::clone(&dtype), NonNullable, 20, 10); // Append a primitive array as a single list entry. let arr1 = buffer![1i32, 2, 3].into_array(); @@ -699,7 +699,7 @@ mod tests { // Interleave with a list scalar. builder .append_value( - Scalar::list(dtype.clone(), vec![10i32.into(), 11i32.into()], NonNullable) + Scalar::list(Arc::clone(&dtype), vec![10i32.into(), 11i32.into()], NonNullable) .as_list(), ) .unwrap(); @@ -714,7 +714,7 @@ mod tests { // Interleave with another list scalar. builder - .append_value(Scalar::list_empty(dtype.clone(), NonNullable).as_list()) + .append_value(Scalar::list_empty(Arc::clone(&dtype), NonNullable).as_list()) .unwrap(); let listview = builder.finish_into_listview(); diff --git a/vortex-array/src/builders/mod.rs b/vortex-array/src/builders/mod.rs index f9914c8fb84..ddf8f40ec61 100644 --- a/vortex-array/src/builders/mod.rs +++ b/vortex-array/src/builders/mod.rs @@ -40,6 +40,7 @@ use crate::dtype::DType; use crate::match_each_decimal_value_type; use crate::match_each_native_ptype; use crate::scalar::Scalar; +use std::sync::Arc; mod lazy_null_builder; pub(crate) use lazy_null_builder::LazyBitBufferBuilder; @@ -269,13 +270,13 @@ pub fn builder_with_capacity(dtype: &DType, capacity: usize) -> Box Box::new(ListViewBuilder::::with_capacity( - dtype.clone(), + Arc::clone(&dtype), *n, 2 * capacity, // Arbitrarily choose 2 times the `offsets` capacity here. capacity, )), DType::FixedSizeList(elem_dtype, list_size, null) => Box::new( - FixedSizeListBuilder::with_capacity(elem_dtype.clone(), *list_size, *null, capacity), + FixedSizeListBuilder::with_capacity(Arc::clone(&elem_dtype), *list_size, *null, capacity), ), DType::Extension(ext_dtype) => { Box::new(ExtensionBuilder::with_capacity(ext_dtype.clone(), capacity)) diff --git a/vortex-array/src/builders/tests.rs b/vortex-array/src/builders/tests.rs index 52b7db95bae..e0a73f0fe48 100644 --- a/vortex-array/src/builders/tests.rs +++ b/vortex-array/src/builders/tests.rs @@ -608,7 +608,7 @@ fn create_test_scalars_for_dtype(dtype: &DType, count: usize) -> Vec { _ => Scalar::default_value(element_dtype.as_ref()), }) .collect(); - Scalar::list(element_dtype.clone(), elements, *n) + Scalar::list(Arc::clone(&element_dtype), elements, *n) } DType::FixedSizeList(element_dtype, size, n) => { // Create fixed-size list scalars. @@ -620,7 +620,7 @@ fn create_test_scalars_for_dtype(dtype: &DType, count: usize) -> Vec { _ => Scalar::default_value(element_dtype.as_ref()), }) .collect(); - Scalar::fixed_size_list(element_dtype.clone(), elements, *n) + Scalar::fixed_size_list(Arc::clone(&element_dtype), elements, *n) } DType::Extension(ext_dtype) => { // Create extension scalars with storage values. diff --git a/vortex-array/src/builtins.rs b/vortex-array/src/builtins.rs index ba3b8542eb7..cf4d9a765c2 100644 --- a/vortex-array/src/builtins.rs +++ b/vortex-array/src/builtins.rs @@ -34,6 +34,7 @@ use crate::scalar_fn::fns::mask::Mask; use crate::scalar_fn::fns::not::Not; use crate::scalar_fn::fns::operators::Operator; use crate::scalar_fn::fns::zip::Zip; +use std::sync::Arc; /// A collection of built-in scalar functions that can be applied to expressions or arrays. pub trait ExprBuiltins: Sized { @@ -147,9 +148,9 @@ pub trait ArrayBuiltins: Sized { impl ArrayBuiltins for ArrayRef { fn cast(&self, dtype: DType) -> VortexResult { if self.dtype() == &dtype { - return Ok(self.clone()); + return Ok(Arc::clone(&self)); } - Cast.try_new_array(self.len(), dtype, [self.clone()])? + Cast.try_new_array(self.len(), dtype, [Arc::clone(&self)])? .optimize() } @@ -163,7 +164,7 @@ impl ArrayBuiltins for ArrayRef { self.len(), EmptyOptions, [ - self.clone(), + Arc::clone(&self), ConstantArray::new(fill_value, self.len()).into_array(), ], )? @@ -172,13 +173,13 @@ impl ArrayBuiltins for ArrayRef { fn get_item(&self, field_name: impl Into) -> VortexResult { GetItem - .try_new_array(self.len(), field_name.into(), [self.clone()])? + .try_new_array(self.len(), field_name.into(), [Arc::clone(&self)])? .optimize() } fn is_null(&self) -> VortexResult { IsNull - .try_new_array(self.len(), EmptyOptions, [self.clone()])? + .try_new_array(self.len(), EmptyOptions, [Arc::clone(&self)])? .optimize() } @@ -188,23 +189,23 @@ impl ArrayBuiltins for ArrayRef { } fn not(&self) -> VortexResult { - Not.try_new_array(self.len(), EmptyOptions, [self.clone()])? + Not.try_new_array(self.len(), EmptyOptions, [Arc::clone(&self)])? .optimize() } fn zip(&self, if_true: ArrayRef, if_false: ArrayRef) -> VortexResult { - Zip.try_new_array(self.len(), EmptyOptions, [if_true, if_false, self.clone()]) + Zip.try_new_array(self.len(), EmptyOptions, [if_true, if_false, Arc::clone(&self)]) } fn list_contains(&self, value: ArrayRef) -> VortexResult { ListContains - .try_new_array(self.len(), EmptyOptions, [self.clone(), value])? + .try_new_array(self.len(), EmptyOptions, [Arc::clone(&self), value])? .optimize() } fn binary(&self, rhs: ArrayRef, op: Operator) -> VortexResult { Binary - .try_new_array(self.len(), op, [self.clone(), rhs])? + .try_new_array(self.len(), op, [Arc::clone(&self), rhs])? .optimize() } diff --git a/vortex-array/src/canonical.rs b/vortex-array/src/canonical.rs index fe0c563ad1e..457df485169 100644 --- a/vortex-array/src/canonical.rs +++ b/vortex-array/src/canonical.rs @@ -763,7 +763,7 @@ impl Executable for RecursiveCanonical { } = st.into_parts(); let executed_fields = fields .iter() - .map(|f| Ok(f.clone().execute::(ctx)?.0.into_array())) + .map(|f| Ok(Arc::clone(&f).execute::(ctx)?.0.into_array())) .collect::>>()?; Ok(RecursiveCanonical(Canonical::Struct(unsafe { diff --git a/vortex-array/src/compute/conformance/binary_numeric.rs b/vortex-array/src/compute/conformance/binary_numeric.rs index 1f4061f5cd9..1fae781af51 100644 --- a/vortex-array/src/compute/conformance/binary_numeric.rs +++ b/vortex-array/src/compute/conformance/binary_numeric.rs @@ -42,6 +42,7 @@ use crate::dtype::PType; use crate::scalar::NumericOperator; use crate::scalar::PrimitiveScalar; use crate::scalar::Scalar; +use std::sync::Arc; fn to_vec_of_scalar(array: &ArrayRef) -> Vec { // Not fast, but obviously correct @@ -83,7 +84,7 @@ where Scalar: From, { // First test with the standard scalar value of 1 - test_standard_binary_numeric::(array.clone()); + test_standard_binary_numeric::(Arc::clone(&array)); // Then test edge cases test_binary_numeric_edge_cases(array); @@ -116,7 +117,7 @@ where // Test array operator scalar (e.g., array + 1) let result = array - .binary(rhs_const.clone(), op.into()) + .binary(Arc::clone(&rhs_const), op.into()) .vortex_expect("apply shouldn't fail") .execute::(&mut LEGACY_SESSION.create_execution_ctx()) .map(|c| c.0.into_array()); @@ -158,7 +159,7 @@ where } // Test scalar operator array (e.g., 1 + array) - let result = rhs_const.binary(array.clone(), op.into()).and_then(|a| { + let result = rhs_const.binary(Arc::clone(&array), op.into()).and_then(|a| { a.execute::(&mut LEGACY_SESSION.create_execution_ctx()) .map(|c| c.0.into_array()) }); @@ -274,13 +275,13 @@ where Scalar: From, { // Test with zero - test_binary_numeric_with_scalar(array.clone(), T::zero()); + test_binary_numeric_with_scalar(Arc::clone(&array), T::zero()); // Test with -1 - test_binary_numeric_with_scalar(array.clone(), -T::one()); + test_binary_numeric_with_scalar(Arc::clone(&array), -T::one()); // Test with max value - test_binary_numeric_with_scalar(array.clone(), T::max_value()); + test_binary_numeric_with_scalar(Arc::clone(&array), T::max_value()); // Test with min value test_binary_numeric_with_scalar(array, T::min_value()); @@ -292,7 +293,7 @@ where Scalar: From, { // Test with zero - test_binary_numeric_with_scalar(array.clone(), T::zero()); + test_binary_numeric_with_scalar(Arc::clone(&array), T::zero()); // Test with max value test_binary_numeric_with_scalar(array, T::max_value()); @@ -304,26 +305,26 @@ where Scalar: From, { // Test with zero - test_binary_numeric_with_scalar(array.clone(), T::zero()); + test_binary_numeric_with_scalar(Arc::clone(&array), T::zero()); // Test with -1 - test_binary_numeric_with_scalar(array.clone(), -T::one()); + test_binary_numeric_with_scalar(Arc::clone(&array), -T::one()); // Test with max value - test_binary_numeric_with_scalar(array.clone(), T::max_value()); + test_binary_numeric_with_scalar(Arc::clone(&array), T::max_value()); // Test with min value - test_binary_numeric_with_scalar(array.clone(), T::min_value()); + test_binary_numeric_with_scalar(Arc::clone(&array), T::min_value()); // Test with small positive value - test_binary_numeric_with_scalar(array.clone(), T::epsilon()); + test_binary_numeric_with_scalar(Arc::clone(&array), T::epsilon()); // Test with min positive value (subnormal) - test_binary_numeric_with_scalar(array.clone(), T::min_positive_value()); + test_binary_numeric_with_scalar(Arc::clone(&array), T::min_positive_value()); // Test with special float values (NaN, Infinity) - test_binary_numeric_with_scalar(array.clone(), T::nan()); - test_binary_numeric_with_scalar(array.clone(), T::infinity()); + test_binary_numeric_with_scalar(Arc::clone(&array), T::nan()); + test_binary_numeric_with_scalar(Arc::clone(&array), T::infinity()); test_binary_numeric_with_scalar(array, T::neg_infinity()); } diff --git a/vortex-array/src/compute/conformance/consistency.rs b/vortex-array/src/compute/conformance/consistency.rs index e6055da5e2c..fc09e9f0ad2 100644 --- a/vortex-array/src/compute/conformance/consistency.rs +++ b/vortex-array/src/compute/conformance/consistency.rs @@ -36,6 +36,7 @@ use crate::dtype::DType; use crate::dtype::Nullability; use crate::dtype::PType; use crate::scalar_fn::fns::operators::Operator; +use std::sync::Arc; /// Tests that filter and take operations produce consistent results. /// @@ -934,7 +935,7 @@ fn test_boolean_demorgan_consistency(array: &ArrayRef) { // Test first De Morgan's law: NOT(A AND B) = (NOT A) OR (NOT B) if let (Ok(a_and_b), Ok(not_a), Ok(not_b)) = ( - array.to_array().binary(bool_mask.clone(), Operator::And), + array.to_array().binary(Arc::clone(&bool_mask), Operator::And), array.not(), bool_mask.not(), ) { @@ -942,7 +943,7 @@ fn test_boolean_demorgan_consistency(array: &ArrayRef) { .not() .vortex_expect("not should succeed in conformance test"); let not_a_or_not_b = not_a - .binary(not_b.clone(), Operator::Or) + .binary(Arc::clone(¬_b), Operator::Or) .vortex_expect("or should succeed in conformance test"); assert_eq!( @@ -968,7 +969,7 @@ fn test_boolean_demorgan_consistency(array: &ArrayRef) { // Test second De Morgan's law: NOT(A OR B) = (NOT A) AND (NOT B) if let (Ok(a_or_b), Ok(not_a), Ok(not_b)) = ( - array.to_array().binary(bool_mask.clone(), Operator::Or), + array.to_array().binary(Arc::clone(&bool_mask), Operator::Or), array.not(), bool_mask.not(), ) { @@ -976,7 +977,7 @@ fn test_boolean_demorgan_consistency(array: &ArrayRef) { .not() .vortex_expect("not should succeed in conformance test"); let not_a_and_not_b = not_a - .binary(not_b.clone(), Operator::And) + .binary(Arc::clone(¬_b), Operator::And) .vortex_expect("and should succeed in conformance test"); for i in 0..not_a_or_b.len() { @@ -1231,7 +1232,7 @@ fn test_cast_slice_consistency(array: &ArrayRef) { Nullability::NonNullable => Nullability::Nullable, Nullability::Nullable => Nullability::NonNullable, }; - vec![DType::List(element_type.clone(), opposite)] + vec![DType::List(Arc::clone(&element_type), opposite)] } DType::FixedSizeList(element_type, list_size, nullability) => { let opposite = match nullability { @@ -1239,7 +1240,7 @@ fn test_cast_slice_consistency(array: &ArrayRef) { Nullability::Nullable => Nullability::NonNullable, }; vec![DType::FixedSizeList( - element_type.clone(), + Arc::clone(&element_type), *list_size, opposite, )] diff --git a/vortex-array/src/dtype/dtype_impl.rs b/vortex-array/src/dtype/dtype_impl.rs index fa655755b56..a56cddbd552 100644 --- a/vortex-array/src/dtype/dtype_impl.rs +++ b/vortex-array/src/dtype/dtype_impl.rs @@ -88,8 +88,8 @@ impl DType { Utf8(_) => Utf8(nullability), Binary(_) => Binary(nullability), Struct(sf, _) => Struct(sf.clone(), nullability), - List(edt, _) => List(edt.clone(), nullability), - FixedSizeList(edt, size, _) => FixedSizeList(edt.clone(), *size, nullability), + List(edt, _) => List(Arc::clone(&edt), nullability), + FixedSizeList(edt, size, _) => FixedSizeList(Arc::clone(&edt), *size, nullability), Extension(ext) => Extension(ext.with_nullability(nullability)), Variant(_) => Variant(nullability), } @@ -539,7 +539,7 @@ mod tests { fn element_size_fixed_size_list() { let elem = Arc::new(DType::Primitive(PType::F64, NonNullable)); assert_eq!( - DType::FixedSizeList(elem.clone(), 1000, NonNullable).element_size(), + DType::FixedSizeList(Arc::clone(&elem), 1000, NonNullable).element_size(), Some(8000) ); diff --git a/vortex-array/src/iter.rs b/vortex-array/src/iter.rs index 354aa5bbf7b..7095ebda2ef 100644 --- a/vortex-array/src/iter.rs +++ b/vortex-array/src/iter.rs @@ -122,7 +122,7 @@ impl Iterator for ArrayChunkIterator { ArrayChunkIterator::Chunked(chunked, idx) => (*idx < chunked.nchunks()).then(|| { let chunk = chunked.chunk(*idx); *idx += 1; - Ok(chunk.clone()) + Ok(Arc::clone(&chunk)) }), } } diff --git a/vortex-array/src/optimizer/mod.rs b/vortex-array/src/optimizer/mod.rs index ee5cd6af210..9a5673407ea 100644 --- a/vortex-array/src/optimizer/mod.rs +++ b/vortex-array/src/optimizer/mod.rs @@ -12,6 +12,7 @@ use vortex_error::vortex_bail; use crate::DynArray; use crate::array::ArrayRef; +use std::sync::Arc; pub mod rules; @@ -26,16 +27,16 @@ pub trait ArrayOptimizer { impl ArrayOptimizer for ArrayRef { fn optimize(&self) -> VortexResult { - Ok(try_optimize(self)?.unwrap_or_else(|| self.clone())) + Ok(try_optimize(self)?.unwrap_or_else(|| Arc::clone(&self))) } fn optimize_recursive(&self) -> VortexResult { - Ok(try_optimize_recursive(self)?.unwrap_or_else(|| self.clone())) + Ok(try_optimize_recursive(self)?.unwrap_or_else(|| Arc::clone(&self))) } } fn try_optimize(array: &ArrayRef) -> VortexResult> { - let mut current_array = array.clone(); + let mut current_array = Arc::clone(&array); let mut any_optimizations = false; // Apply reduction rules to the current array until no more rules apply. @@ -82,7 +83,7 @@ fn try_optimize(array: &ArrayRef) -> VortexResult> { } fn try_optimize_recursive(array: &ArrayRef) -> VortexResult> { - let mut current_array = array.clone(); + let mut current_array = Arc::clone(&array); let mut any_optimizations = false; if let Some(new_array) = try_optimize(¤t_array)? { @@ -99,7 +100,7 @@ fn try_optimize_recursive(array: &ArrayRef) -> VortexResult> { new_slots.push(Some(new_child)); any_slot_optimized = true; } else { - new_slots.push(Some(child.clone())); + new_slots.push(Some(Arc::clone(&child))); } } None => new_slots.push(None), diff --git a/vortex-array/src/patches.rs b/vortex-array/src/patches.rs index 2c2300ae2b4..f0a27fb9a33 100644 --- a/vortex-array/src/patches.rs +++ b/vortex-array/src/patches.rs @@ -45,6 +45,7 @@ use crate::search_sorted::SearchResult; use crate::search_sorted::SearchSorted; use crate::search_sorted::SearchSortedSide; use crate::validity::Validity; +use std::sync::Arc; /// One patch index offset is stored for each chunk. /// This allows for constant time patch index lookups. @@ -584,7 +585,7 @@ impl Patches { AllOr::All => Ok(Some(self.clone())), AllOr::None => Ok(None), AllOr::Some(mask_indices) => { - let flat_indices = self.indices().clone().execute::(ctx)?; + let flat_indices = Arc::clone(&self.indices()).execute::(ctx)?; match_each_unsigned_integer_ptype!(flat_indices.ptype(), |I| { filter_patches_with_mask( flat_indices.as_slice::(), @@ -614,7 +615,7 @@ impl Patches { AllOr::All => return Ok(None), AllOr::None => return Ok(Some(self.clone())), AllOr::Some(masked) => { - let patch_indices = self.indices().clone().execute::(ctx)?; + let patch_indices = Arc::clone(&self.indices()).execute::(ctx)?; match_each_unsigned_integer_ptype!(patch_indices.ptype(), |P| { let patch_indices = patch_indices.as_slice::

(); Mask::from_buffer(BitBuffer::collect_bool(patch_indices.len(), |i| { @@ -749,11 +750,11 @@ impl Patches { ctx: &mut ExecutionCtx, ) -> VortexResult> { let take_indices_validity = take_indices.validity(); - let patch_indices = self.indices.clone().execute::(ctx)?; + let patch_indices = Arc::clone(&self.indices).execute::(ctx)?; let chunk_offsets = self .chunk_offsets() .as_ref() - .map(|co| co.clone().execute::(ctx)) + .map(|co| Arc::clone(&co).execute::(ctx)) .transpose()?; let (values_indices, new_indices): (BufferMut, BufferMut) = @@ -810,7 +811,7 @@ impl Patches { Ok(Some(Self { array_len: new_array_len, offset: 0, - indices: new_indices.clone(), + indices: Arc::clone(&new_indices), values: self .values() .take(PrimitiveArray::new(values_indices, values_validity).into_array())?, @@ -825,7 +826,7 @@ impl Patches { include_nulls: bool, ctx: &mut ExecutionCtx, ) -> VortexResult> { - let indices = self.indices.clone().execute::(ctx)?; + let indices = Arc::clone(&self.indices).execute::(ctx)?; let new_length = take_indices.len(); let min_index = self.min_index()?; diff --git a/vortex-array/src/scalar/tests/nested.rs b/vortex-array/src/scalar/tests/nested.rs index c4b28418c36..0aadd4ce2c9 100644 --- a/vortex-array/src/scalar/tests/nested.rs +++ b/vortex-array/src/scalar/tests/nested.rs @@ -19,14 +19,14 @@ mod tests { // Create FixedSizeList[2] of FixedSizeList[3] of I32. let inner_element_dtype = Arc::new(DType::Primitive(PType::I32, Nullability::NonNullable)); let inner_dtype = Arc::new(DType::FixedSizeList( - inner_element_dtype.clone(), + Arc::clone(&inner_element_dtype), 3, Nullability::NonNullable, )); // Create inner FixedSizeLists. let inner_list1 = Scalar::fixed_size_list( - inner_element_dtype.clone(), + Arc::clone(&inner_element_dtype), vec![ Scalar::primitive(1i32, Nullability::NonNullable), Scalar::primitive(2i32, Nullability::NonNullable), @@ -87,12 +87,12 @@ mod tests { // Create FixedSizeList[2] of variable List of I32. let inner_element_dtype = Arc::new(DType::Primitive(PType::I32, Nullability::NonNullable)); let inner_dtype = Arc::new(DType::List( - inner_element_dtype.clone(), + Arc::clone(&inner_element_dtype), Nullability::NonNullable, )); let inner_list1 = Scalar::list( - inner_element_dtype.clone(), + Arc::clone(&inner_element_dtype), vec![ Scalar::primitive(10i32, Nullability::NonNullable), Scalar::primitive(20i32, Nullability::NonNullable), @@ -133,13 +133,13 @@ mod tests { // Create variable List of FixedSizeList[3] of I32. let inner_element_dtype = Arc::new(DType::Primitive(PType::I32, Nullability::NonNullable)); let inner_dtype = Arc::new(DType::FixedSizeList( - inner_element_dtype.clone(), + Arc::clone(&inner_element_dtype), 3, Nullability::NonNullable, )); let fixed_list1 = Scalar::fixed_size_list( - inner_element_dtype.clone(), + Arc::clone(&inner_element_dtype), vec![ Scalar::primitive(1i32, Nullability::NonNullable), Scalar::primitive(2i32, Nullability::NonNullable), @@ -639,7 +639,7 @@ mod tests { )); let middle_fixed_list_dtype = Arc::new(DType::FixedSizeList( - struct_dtype.clone(), + Arc::clone(&struct_dtype), 2, Nullability::NonNullable, )); @@ -799,7 +799,7 @@ mod tests { )); let middle_dtype = Arc::new(DType::List( - innermost_dtype.clone(), + Arc::clone(&innermost_dtype), Nullability::NonNullable, )); @@ -824,7 +824,7 @@ mod tests { // Create middle Lists. let middle_list1 = Scalar::list( - innermost_dtype.clone(), + Arc::clone(&innermost_dtype), vec![inner_fixed1.clone()], Nullability::NonNullable, ); @@ -927,7 +927,7 @@ mod tests { // Test FixedSizeList[0] behavior. let element_dtype = Arc::new(DType::Primitive(PType::I32, Nullability::NonNullable)); let empty_fixed_list = - Scalar::fixed_size_list(element_dtype.clone(), vec![], Nullability::NonNullable); + Scalar::fixed_size_list(Arc::clone(&element_dtype), vec![], Nullability::NonNullable); assert!(matches!( empty_fixed_list.dtype(), @@ -949,7 +949,7 @@ mod tests { fn test_fixed_size_list_cast_to_list() { let element_dtype = Arc::new(DType::Primitive(PType::I32, Nullability::NonNullable)); let fixed_list = Scalar::fixed_size_list( - element_dtype.clone(), + Arc::clone(&element_dtype), vec![ Scalar::primitive(1i32, Nullability::NonNullable), Scalar::primitive(2i32, Nullability::NonNullable), @@ -985,7 +985,7 @@ mod tests { fn test_list_cast_to_fixed_size_list() { let element_dtype = Arc::new(DType::Primitive(PType::I32, Nullability::NonNullable)); let list = Scalar::list( - element_dtype.clone(), + Arc::clone(&element_dtype), vec![ Scalar::primitive(10i32, Nullability::NonNullable), Scalar::primitive(20i32, Nullability::NonNullable), @@ -1022,7 +1022,7 @@ mod tests { fn test_fixed_size_list_size_validation() { let element_dtype = Arc::new(DType::Primitive(PType::I32, Nullability::NonNullable)); let list = Scalar::list( - element_dtype.clone(), + Arc::clone(&element_dtype), vec![ Scalar::primitive(1i32, Nullability::NonNullable), Scalar::primitive(2i32, Nullability::NonNullable), @@ -1032,7 +1032,7 @@ mod tests { // Try to cast to wrong size - should fail. let wrong_size_target = - DType::FixedSizeList(element_dtype.clone(), 3, Nullability::NonNullable); + DType::FixedSizeList(Arc::clone(&element_dtype), 3, Nullability::NonNullable); let result = list.cast(&wrong_size_target); assert!(result.is_err()); assert!( @@ -1072,7 +1072,7 @@ mod tests { // Create two equal fixed size lists. let list1 = Scalar::fixed_size_list( - element_dtype.clone(), + Arc::clone(&element_dtype), vec![ Scalar::primitive(1i32, Nullability::NonNullable), Scalar::primitive(2i32, Nullability::NonNullable), @@ -1081,7 +1081,7 @@ mod tests { ); let list2 = Scalar::fixed_size_list( - element_dtype.clone(), + Arc::clone(&element_dtype), vec![ Scalar::primitive(1i32, Nullability::NonNullable), Scalar::primitive(2i32, Nullability::NonNullable), @@ -1113,7 +1113,7 @@ mod tests { // Test FixedSizeList[1]. let element_dtype = Arc::new(DType::Primitive(PType::I64, Nullability::NonNullable)); let single_element = Scalar::fixed_size_list( - element_dtype.clone(), + Arc::clone(&element_dtype), vec![Scalar::primitive(42i64, Nullability::NonNullable)], Nullability::NonNullable, ); @@ -1172,7 +1172,7 @@ mod tests { // FixedSizeList[3] of i32 = 3 * 4 bytes = 12 bytes. let fixed_list = Scalar::fixed_size_list( - element_dtype.clone(), + Arc::clone(&element_dtype), vec![ Scalar::primitive(1i32, Nullability::NonNullable), Scalar::primitive(2i32, Nullability::NonNullable), diff --git a/vortex-array/src/scalar/tests/nullability.rs b/vortex-array/src/scalar/tests/nullability.rs index d70796d20ce..4bc7016d6a7 100644 --- a/vortex-array/src/scalar/tests/nullability.rs +++ b/vortex-array/src/scalar/tests/nullability.rs @@ -589,7 +589,7 @@ mod tests { Nullability::Nullable, )); - let middle_dtype = Arc::new(DType::List(innermost_dtype.clone(), Nullability::Nullable)); + let middle_dtype = Arc::new(DType::List(Arc::clone(&innermost_dtype), Nullability::Nullable)); // Create innermost FixedSizeLists with different null patterns. let inner1 = Scalar::fixed_size_list( @@ -618,7 +618,7 @@ mod tests { // Create middle Lists. let middle1 = Scalar::list( - innermost_dtype.clone(), + Arc::clone(&innermost_dtype), vec![inner1, inner2], Nullability::Nullable, ); diff --git a/vortex-array/src/scalar/tests/round_trip.rs b/vortex-array/src/scalar/tests/round_trip.rs index c904a27f2ae..db5f09a5c6c 100644 --- a/vortex-array/src/scalar/tests/round_trip.rs +++ b/vortex-array/src/scalar/tests/round_trip.rs @@ -220,7 +220,7 @@ mod tests { // Test nested lists let inner_dtype = Arc::new(DType::Primitive(PType::I32, Nullability::NonNullable)); - let outer_dtype = Arc::new(DType::List(inner_dtype.clone(), Nullability::NonNullable)); + let outer_dtype = Arc::new(DType::List(Arc::clone(&inner_dtype), Nullability::NonNullable)); let inner_list1 = Scalar::list( inner_dtype, diff --git a/vortex-array/src/scalar/typed_view/list.rs b/vortex-array/src/scalar/typed_view/list.rs index 6c4206f2a0e..3cd744db1c2 100644 --- a/vortex-array/src/scalar/typed_view/list.rs +++ b/vortex-array/src/scalar/typed_view/list.rs @@ -340,7 +340,7 @@ mod tests { Scalar::primitive(1i32, Nullability::NonNullable), Scalar::primitive(2i32, Nullability::NonNullable), ]; - let list_scalar1 = Scalar::list(element_dtype.clone(), children1, Nullability::NonNullable); + let list_scalar1 = Scalar::list(Arc::clone(&element_dtype), children1, Nullability::NonNullable); let children2 = vec![ Scalar::primitive(1i32, Nullability::NonNullable), @@ -361,7 +361,7 @@ mod tests { Scalar::primitive(1i32, Nullability::NonNullable), Scalar::primitive(2i32, Nullability::NonNullable), ]; - let list_scalar1 = Scalar::list(element_dtype.clone(), children1, Nullability::NonNullable); + let list_scalar1 = Scalar::list(Arc::clone(&element_dtype), children1, Nullability::NonNullable); let children2 = vec![ Scalar::primitive(1i32, Nullability::NonNullable), @@ -380,7 +380,7 @@ mod tests { let element_dtype = Arc::new(DType::Primitive(PType::I32, Nullability::NonNullable)); let children1 = vec![Scalar::primitive(1i32, Nullability::NonNullable)]; - let list_scalar1 = Scalar::list(element_dtype.clone(), children1, Nullability::NonNullable); + let list_scalar1 = Scalar::list(Arc::clone(&element_dtype), children1, Nullability::NonNullable); let children2 = vec![Scalar::primitive(2i32, Nullability::NonNullable)]; let list_scalar2 = Scalar::list(element_dtype, children2, Nullability::NonNullable); @@ -521,12 +521,12 @@ mod tests { fn test_nested_lists() { let inner_element_dtype = Arc::new(DType::Primitive(PType::I32, Nullability::NonNullable)); let inner_list_dtype = Arc::new(DType::List( - inner_element_dtype.clone(), + Arc::clone(&inner_element_dtype), Nullability::NonNullable, )); let inner_list1 = Scalar::list( - inner_element_dtype.clone(), + Arc::clone(&inner_element_dtype), vec![ Scalar::primitive(1i32, Nullability::NonNullable), Scalar::primitive(2i32, Nullability::NonNullable), diff --git a/vortex-array/src/scalar_fn/fns/dynamic.rs b/vortex-array/src/scalar_fn/fns/dynamic.rs index c3e83f98d96..90125644172 100644 --- a/vortex-array/src/scalar_fn/fns/dynamic.rs +++ b/vortex-array/src/scalar_fn/fns/dynamic.rs @@ -131,7 +131,7 @@ impl ScalarFnVTable for DynamicComparison { CompareOperator::Gt => Some(DynamicComparison.new_expr( DynamicComparisonExpr { operator: CompareOperator::Lte, - rhs: dynamic.rhs.clone(), + rhs: Arc::clone(&dynamic.rhs), default: !dynamic.default, }, vec![lhs.stat_max(catalog)?], @@ -139,7 +139,7 @@ impl ScalarFnVTable for DynamicComparison { CompareOperator::Gte => Some(DynamicComparison.new_expr( DynamicComparisonExpr { operator: CompareOperator::Lt, - rhs: dynamic.rhs.clone(), + rhs: Arc::clone(&dynamic.rhs), default: !dynamic.default, }, vec![lhs.stat_max(catalog)?], @@ -147,7 +147,7 @@ impl ScalarFnVTable for DynamicComparison { CompareOperator::Lt => Some(DynamicComparison.new_expr( DynamicComparisonExpr { operator: CompareOperator::Gte, - rhs: dynamic.rhs.clone(), + rhs: Arc::clone(&dynamic.rhs), default: !dynamic.default, }, vec![lhs.stat_min(catalog)?], @@ -155,7 +155,7 @@ impl ScalarFnVTable for DynamicComparison { CompareOperator::Lte => Some(DynamicComparison.new_expr( DynamicComparisonExpr { operator: CompareOperator::Gt, - rhs: dynamic.rhs.clone(), + rhs: Arc::clone(&dynamic.rhs), default: !dynamic.default, }, vec![lhs.stat_min(catalog)?], @@ -393,7 +393,7 @@ mod tests { #[test] fn execute_value_flips() -> VortexResult<()> { let threshold = Arc::new(AtomicI32::new(5)); - let threshold_clone = threshold.clone(); + let threshold_clone = Arc::clone(&threshold); let expr = dynamic( CompareOperator::Lt, move || Some(threshold_clone.load(Ordering::SeqCst).into()), diff --git a/vortex-array/src/scalar_fn/fns/is_null.rs b/vortex-array/src/scalar_fn/fns/is_null.rs index 8eae1da2bd0..358bb8b90b9 100644 --- a/vortex-array/src/scalar_fn/fns/is_null.rs +++ b/vortex-array/src/scalar_fn/fns/is_null.rs @@ -25,6 +25,7 @@ use crate::scalar_fn::ExecutionArgs; use crate::scalar_fn::ScalarFnId; use crate::scalar_fn::ScalarFnVTable; use crate::validity::Validity; +use std::sync::Arc; /// Expression that checks for null values. #[derive(Clone)] @@ -163,7 +164,7 @@ mod tests { .into_array(); let expected = [false, true, false, true, false]; - let result = test_array.clone().apply(&is_null(root())).unwrap(); + let result = Arc::clone(&test_array).apply(&is_null(root())).unwrap(); assert_eq!(result.len(), test_array.len()); assert_eq!(result.dtype(), &DType::Bool(Nullability::NonNullable)); @@ -180,7 +181,7 @@ mod tests { fn evaluate_all_false() { let test_array = buffer![1, 2, 3, 4, 5].into_array(); - let result = test_array.clone().apply(&is_null(root())).unwrap(); + let result = Arc::clone(&test_array).apply(&is_null(root())).unwrap(); assert_eq!(result.len(), test_array.len()); // All values should be false (non-nullable input) @@ -198,7 +199,7 @@ mod tests { PrimitiveArray::from_option_iter(vec![None::, None, None, None, None]) .into_array(); - let result = test_array.clone().apply(&is_null(root())).unwrap(); + let result = Arc::clone(&test_array).apply(&is_null(root())).unwrap(); assert_eq!(result.len(), test_array.len()); // All values should be true (all nulls) diff --git a/vortex-array/src/scalar_fn/fns/list_contains/mod.rs b/vortex-array/src/scalar_fn/fns/list_contains/mod.rs index 3ed85bd7243..05a3534eb5b 100644 --- a/vortex-array/src/scalar_fn/fns/list_contains/mod.rs +++ b/vortex-array/src/scalar_fn/fns/list_contains/mod.rs @@ -283,7 +283,7 @@ fn list_contains_scalar( return Ok(ConstantArray::new(contains.scalar_at(0)?, array.len()).into_array()); } - let list_array = array.clone().execute::(ctx)?; + let list_array = Arc::clone(&array).execute::(ctx)?; let elems = list_array.elements(); if elems.is_empty() { @@ -295,7 +295,7 @@ fn list_contains_scalar( let matching_elements = Binary.try_new_array( elems.len(), Operator::Eq, - &[elems.clone(), rhs.clone().into_array()], + &[Arc::clone(&elems), rhs.clone().into_array()], )?; let matches = matching_elements.execute::(ctx)?; @@ -333,7 +333,7 @@ fn list_contains_scalar( .offsets() .clone() .execute::(ctx)?; - let sizes = list_array.sizes().clone().execute::(ctx)?; + let sizes = Arc::clone(&list_array.sizes()).execute::(ctx)?; // Process based on the offset and size types. let list_matches = match_each_integer_ptype!(offsets.ptype(), |O| { @@ -407,7 +407,7 @@ fn list_false_or_null( Validity::Array(validity_array) => { // Create a new bool array with false, and the provided nulls let buffer = BitBuffer::new_unset(list_array.len()); - Ok(BoolArray::new(buffer, Validity::Array(validity_array.clone())).into_array()) + Ok(BoolArray::new(buffer, Validity::Array(Arc::clone(&validity_array))).into_array()) } } } @@ -428,7 +428,7 @@ fn list_is_not_empty( .into_array()); } - let sizes = list_array.sizes().clone().execute::(ctx)?; + let sizes = Arc::clone(&list_array.sizes()).execute::(ctx)?; let buffer = match_each_integer_ptype!(sizes.ptype(), |S| { BitBuffer::from_iter(sizes.as_slice::().iter().map(|&size| size != S::zero())) }); diff --git a/vortex-array/src/scalar_fn/fns/merge.rs b/vortex-array/src/scalar_fn/fns/merge.rs index f0681a418b1..f80f0924a68 100644 --- a/vortex-array/src/scalar_fn/fns/merge.rs +++ b/vortex-array/src/scalar_fn/fns/merge.rs @@ -214,10 +214,10 @@ impl ScalarFnVTable for Merge { for name in child_dtype.names().iter() { if let Some(idx) = names.iter().position(|n| n == name) { duplicate_names.insert(name.clone()); - children[idx] = child.clone(); + children[idx] = Arc::clone(&child); } else { names.push(name.clone()); - children.push(child.clone()); + children.push(Arc::clone(&child)); } } @@ -316,9 +316,9 @@ mod tests { vortex_bail!("empty field path"); }; - let mut array = array.to_struct().unmasked_field_by_name(field)?.clone(); + let mut array = Arc::clone(&array.to_struct().unmasked_field_by_name(field)?); for field in field_path { - array = array.to_struct().unmasked_field_by_name(field)?.clone(); + array = Arc::clone(&array.to_struct().unmasked_field_by_name(field)?); } Ok(array.to_primitive()) } @@ -447,7 +447,7 @@ mod tests { let test_array = StructArray::from_fields(&[("a", buffer![0, 1, 2].into_array())]) .unwrap() .into_array(); - let actual_array = test_array.clone().apply(&expr).unwrap(); + let actual_array = Arc::clone(&test_array).apply(&expr).unwrap(); assert_eq!(actual_array.len(), test_array.len()); assert_eq!(actual_array.as_struct_typed().nfields(), 0); } @@ -490,7 +490,7 @@ mod tests { ]) .unwrap() .into_array(); - let actual_array = test_array.clone().apply(&expr).unwrap().to_struct(); + let actual_array = Arc::clone(&test_array).apply(&expr).unwrap().to_struct(); assert_eq!( actual_array @@ -531,7 +531,7 @@ mod tests { ]) .unwrap() .into_array(); - let actual_array = test_array.clone().apply(&expr).unwrap().to_struct(); + let actual_array = Arc::clone(&test_array).apply(&expr).unwrap().to_struct(); assert_eq!(actual_array.names(), ["a", "c", "b", "d"]); } diff --git a/vortex-array/src/scalar_fn/fns/pack.rs b/vortex-array/src/scalar_fn/fns/pack.rs index 37a00e61aeb..e99731234b9 100644 --- a/vortex-array/src/scalar_fn/fns/pack.rs +++ b/vortex-array/src/scalar_fn/fns/pack.rs @@ -28,6 +28,7 @@ use crate::scalar_fn::ExecutionArgs; use crate::scalar_fn::ScalarFnId; use crate::scalar_fn::ScalarFnVTable; use crate::validity::Validity; +use std::sync::Arc; /// Pack zero or more expressions into a structure with named fields. #[derive(Clone)] @@ -90,7 +91,7 @@ impl ScalarFnVTable for Pack { fn child_name(&self, instance: &Self::Options, child_idx: usize) -> ChildName { match instance.names.get(child_idx) { - Some(name) => ChildName::from(name.inner().clone()), + Some(name) => ChildName::from(Arc::clone(&name.inner())), None => unreachable!( "Invalid child index {} for Pack expression with {} fields", child_idx, @@ -194,9 +195,9 @@ mod tests { vortex_bail!("empty field path"); }; - let mut array = array.to_struct().unmasked_field_by_name(field)?.clone(); + let mut array = Arc::clone(&array.to_struct().unmasked_field_by_name(field)?); for field in field_path { - array = array.to_struct().unmasked_field_by_name(field)?.clone(); + array = Arc::clone(&array.to_struct().unmasked_field_by_name(field)?); } Ok(array.to_primitive()) } @@ -212,7 +213,7 @@ mod tests { ); let test_array = test_array(); - let actual_array = test_array.clone().apply(&expr).unwrap(); + let actual_array = Arc::clone(&test_array).apply(&expr).unwrap(); assert_eq!(actual_array.len(), test_array.len()); assert_eq!(actual_array.to_struct().struct_fields().nfields(), 0); } diff --git a/vortex-array/src/scalar_fn/fns/zip/mod.rs b/vortex-array/src/scalar_fn/fns/zip/mod.rs index e5f5f18d964..7cf9bf2fce9 100644 --- a/vortex-array/src/scalar_fn/fns/zip/mod.rs +++ b/vortex-array/src/scalar_fn/fns/zip/mod.rs @@ -31,6 +31,7 @@ use crate::scalar_fn::ScalarFnId; use crate::scalar_fn::ScalarFnVTable; use crate::scalar_fn::SimplifyCtx; use crate::scalar_fn::fns::literal::Literal; +use std::sync::Arc; /// An expression that conditionally selects between two arrays based on a boolean mask. /// @@ -290,7 +291,7 @@ mod tests { let if_false = PrimitiveArray::from_option_iter([Some(1), Some(2), Some(3), None]).into_array(); - let result = mask.into_array().zip(if_true, if_false.clone()).unwrap(); + let result = mask.into_array().zip(if_true, Arc::clone(&if_false)).unwrap(); let expected = PrimitiveArray::from_option_iter([Some(10), Some(20), Some(30), Some(40)]).into_array(); @@ -305,7 +306,7 @@ mod tests { PrimitiveArray::from_option_iter([Some(10), Some(20), Some(30), None]).into_array(); let if_false = buffer![1i32, 2, 3, 4].into_array(); - let result = mask.into_array().zip(if_true.clone(), if_false).unwrap(); + let result = mask.into_array().zip(Arc::clone(&if_true), if_false).unwrap(); let expected = PrimitiveArray::from_option_iter([Some(1), Some(2), Some(3), Some(4)]).into_array(); @@ -379,7 +380,7 @@ mod tests { let mut ctx = LEGACY_SESSION.create_execution_ctx(); let result = mask_array .clone() - .zip(const1.clone(), const2.clone())? + .zip(Arc::clone(&const1), Arc::clone(&const2))? .execute::(&mut ctx)? .into_array(); @@ -439,7 +440,7 @@ mod tests { let mut ctx = LEGACY_SESSION.create_execution_ctx(); let zipped = mask_array - .zip(if_true.clone(), if_false.clone()) + .zip(Arc::clone(&if_true), Arc::clone(&if_false)) .unwrap() .execute::(&mut ctx) .unwrap(); diff --git a/vortex-array/src/serde.rs b/vortex-array/src/serde.rs index c4f885f6c2a..145c79e36c2 100644 --- a/vortex-array/src/serde.rs +++ b/vortex-array/src/serde.rs @@ -273,7 +273,7 @@ pub trait ArrayChildren { impl ArrayChildren for &[ArrayRef] { fn get(&self, index: usize, dtype: &DType, len: usize) -> VortexResult { - let array = self[index].clone(); + let array = Arc::clone(&self[index]); assert_eq!(array.len(), len); assert_eq!(array.dtype(), dtype); Ok(array) diff --git a/vortex-array/src/validity.rs b/vortex-array/src/validity.rs index c25a7d6eb6b..50be90fd68f 100644 --- a/vortex-array/src/validity.rs +++ b/vortex-array/src/validity.rs @@ -32,6 +32,7 @@ use crate::patches::Patches; use crate::scalar::Scalar; use crate::scalar_fn::fns::binary::Binary; use crate::scalar_fn::fns::operators::Operator; +use std::sync::Arc; /// Validity information for an array #[derive(Clone)] @@ -78,7 +79,7 @@ impl Validity { match self { Self::NonNullable | Self::AllValid => ConstantArray::new(true, len).into_array(), Self::AllInvalid => ConstantArray::new(false, len).into_array(), - Self::Array(a) => a.clone(), + Self::Array(a) => Arc::clone(&a), } } @@ -218,7 +219,7 @@ impl Validity { ); // TODO(ngates): I'm not sure execution should take arrays by ownership. // If so we should fix call sites to clone and this function takes self. - arr.clone().execute::(ctx) + Arc::clone(&arr).execute::(ctx) } } } @@ -230,8 +231,8 @@ impl Validity { (Validity::AllValid, Validity::AllValid) => Ok(true), (Validity::AllInvalid, Validity::AllInvalid) => Ok(true), (Validity::Array(a), Validity::Array(b)) => { - let a = a.clone().execute::(ctx)?; - let b = b.clone().execute::(ctx)?; + let a = Arc::clone(&a).execute::(ctx)?; + let b = Arc::clone(&b).execute::(ctx)?; Ok(a == b) } _ => Ok(false), @@ -295,14 +296,14 @@ impl Validity { Validity::NonNullable => BoolArray::from(BitBuffer::new_set(len)), Validity::AllValid => BoolArray::from(BitBuffer::new_set(len)), Validity::AllInvalid => BoolArray::from(BitBuffer::new_unset(len)), - Validity::Array(a) => a.clone().execute::(ctx)?, + Validity::Array(a) => Arc::clone(&a).execute::(ctx)?, }; let patch_values = match patches { Validity::NonNullable => BoolArray::from(BitBuffer::new_set(indices.len())), Validity::AllValid => BoolArray::from(BitBuffer::new_set(indices.len())), Validity::AllInvalid => BoolArray::from(BitBuffer::new_unset(indices.len())), - Validity::Array(a) => a.clone().execute::(ctx)?, + Validity::Array(a) => Arc::clone(&a).execute::(ctx)?, }; let patches = Patches::new( diff --git a/vortex-array/src/vtable/mod.rs b/vortex-array/src/vtable/mod.rs index 514d4ac2add..5011a69dbf9 100644 --- a/vortex-array/src/vtable/mod.rs +++ b/vortex-array/src/vtable/mod.rs @@ -256,7 +256,7 @@ pub fn validity_to_child(validity: &Validity, len: usize) -> Option { match validity { Validity::NonNullable | Validity::AllValid => None, Validity::AllInvalid => Some(ConstantArray::new(false, len).into_array()), - Validity::Array(array) => Some(array.clone()), + Validity::Array(array) => Some(Arc::clone(&array)), } } @@ -278,7 +278,7 @@ pub fn child_to_validity(child: &Option, nullability: Nullability) -> Validity::AllInvalid }; } - Validity::Array(arr.clone()) + Validity::Array(Arc::clone(&arr)) } None => Validity::from(nullability), } @@ -303,8 +303,8 @@ pub fn patches_nchildren(patches: &Patches) -> usize { #[inline] pub fn patches_child(patches: &Patches, idx: usize) -> ArrayRef { match idx { - 0 => patches.indices().clone(), - 1 => patches.values().clone(), + 0 => Arc::clone(&patches.indices()), + 1 => Arc::clone(&patches.values()), 2 => patches .chunk_offsets() .as_ref() diff --git a/vortex-bench/src/datasets/feature_vectors.rs b/vortex-bench/src/datasets/feature_vectors.rs index 7e0bc61bccc..e5c1cd779e9 100644 --- a/vortex-bench/src/datasets/feature_vectors.rs +++ b/vortex-bench/src/datasets/feature_vectors.rs @@ -81,7 +81,7 @@ pub async fn feature_vectors_parquet() -> Result { ])); let file = File::create(&temp_path)?; - let mut writer = ArrowWriter::try_new(file, schema.clone(), None)?; + let mut writer = ArrowWriter::try_new(file, Arc::clone(&schema), None)?; let mut rng = StdRng::seed_from_u64(42); for batch_start in (0..ROW_COUNT).step_by(BATCH_SIZE) { @@ -101,7 +101,7 @@ pub async fn feature_vectors_parquet() -> Result { let embedding = list_builder.finish(); let batch = - RecordBatch::try_new(schema.clone(), vec![Arc::new(ids), Arc::new(embedding)])?; + RecordBatch::try_new(Arc::clone(&schema), vec![Arc::new(ids), Arc::new(embedding)])?; writer.write(&batch)?; } diff --git a/vortex-bench/src/datasets/nested_lists.rs b/vortex-bench/src/datasets/nested_lists.rs index b1461d66b42..a45f88ad97d 100644 --- a/vortex-bench/src/datasets/nested_lists.rs +++ b/vortex-bench/src/datasets/nested_lists.rs @@ -77,7 +77,7 @@ pub async fn nested_lists_parquet() -> Result { ])); let file = std::fs::File::create(&temp_path)?; - let mut writer = ArrowWriter::try_new(file, schema.clone(), None)?; + let mut writer = ArrowWriter::try_new(file, Arc::clone(&schema), None)?; let mut rng = StdRng::seed_from_u64(42); for batch_start in (0..ROW_COUNT).step_by(BATCH_SIZE) { @@ -98,7 +98,7 @@ pub async fn nested_lists_parquet() -> Result { let values = list_builder.finish(); let batch = - RecordBatch::try_new(schema.clone(), vec![Arc::new(ids), Arc::new(values)])?; + RecordBatch::try_new(Arc::clone(&schema), vec![Arc::new(ids), Arc::new(values)])?; writer.write(&batch)?; } diff --git a/vortex-bench/src/datasets/nested_structs.rs b/vortex-bench/src/datasets/nested_structs.rs index a7edff7e5dc..7c7ee0f79cc 100644 --- a/vortex-bench/src/datasets/nested_structs.rs +++ b/vortex-bench/src/datasets/nested_structs.rs @@ -92,7 +92,7 @@ pub async fn nested_structs_parquet() -> Result { ])); let file = std::fs::File::create(&temp_path)?; - let mut writer = ArrowWriter::try_new(file, schema.clone(), None)?; + let mut writer = ArrowWriter::try_new(file, Arc::clone(&schema), None)?; let mut rng = StdRng::seed_from_u64(42); for batch_start in (0..ROW_COUNT).step_by(BATCH_SIZE) { @@ -125,7 +125,7 @@ pub async fn nested_structs_parquet() -> Result { )?; let batch = - RecordBatch::try_new(schema.clone(), vec![Arc::new(ids), Arc::new(outer)])?; + RecordBatch::try_new(Arc::clone(&schema), vec![Arc::new(ids), Arc::new(outer)])?; writer.write(&batch)?; } diff --git a/vortex-bench/src/datasets/struct_list_of_ints.rs b/vortex-bench/src/datasets/struct_list_of_ints.rs index 650a04a0b20..20c7e585f8c 100644 --- a/vortex-bench/src/datasets/struct_list_of_ints.rs +++ b/vortex-bench/src/datasets/struct_list_of_ints.rs @@ -24,6 +24,7 @@ use vortex::dtype::FieldNames; use crate::IdempotentPath; use crate::datasets::Dataset; use crate::idempotent_async; +use std::sync::Arc; /// Creates a randomly generated struct array, where each field is a list of /// i64 of size one. @@ -121,7 +122,7 @@ impl Dataset for StructListOfInts { let mut writer: Option> = None; for chunk in chunked.iter_chunks() { - let converted = recursive_list_from_list_view(chunk.clone())?; + let converted = recursive_list_from_list_view(Arc::clone(&chunk))?; let batch = RecordBatch::try_from(converted.as_ref())?; if writer.is_none() { diff --git a/vortex-bench/src/polarsignals/data.rs b/vortex-bench/src/polarsignals/data.rs index ed00f938cb9..7c5fbe8a2b7 100644 --- a/vortex-bench/src/polarsignals/data.rs +++ b/vortex-bench/src/polarsignals/data.rs @@ -143,7 +143,7 @@ pub fn generate_polarsignals_parquet(n_rows: usize, output_path: &Path) -> Resul let props = WriterProperties::builder() .set_compression(Compression::SNAPPY) .build(); - let mut writer = ArrowWriter::try_new(file, schema.clone(), Some(props))?; + let mut writer = ArrowWriter::try_new(file, Arc::clone(&schema), Some(props))?; let batch_size = 10_000; let num_threads = std::thread::available_parallelism() @@ -159,11 +159,11 @@ pub fn generate_polarsignals_parquet(n_rows: usize, output_path: &Path) -> Resul chunk .iter() .map(|&(start, len)| { - let schema = schema.clone(); - let label_sets = label_sets.clone(); - let function_names = function_names.clone(); - let function_filenames = function_filenames.clone(); - let build_ids = build_ids.clone(); + let schema = Arc::clone(&schema); + let label_sets = Arc::clone(&label_sets); + let function_names = Arc::clone(&function_names); + let function_filenames = Arc::clone(&function_filenames); + let build_ids = Arc::clone(&build_ids); std::thread::spawn(move || { let mut rng = StdRng::seed_from_u64(42 + start as u64); build_batch( @@ -235,7 +235,7 @@ fn build_batch( } let batch = RecordBatch::try_new( - schema.clone(), + Arc::clone(&schema), vec![ Arc::new(labels_array), Arc::new(locations_array), diff --git a/vortex-bench/src/random_access/take.rs b/vortex-bench/src/random_access/take.rs index b23d6622876..661e820486f 100644 --- a/vortex-bench/src/random_access/take.rs +++ b/vortex-bench/src/random_access/take.rs @@ -30,6 +30,7 @@ use vortex::utils::aliases::hash_map::HashMap; use crate::Format; use crate::SESSION; use crate::random_access::RandomAccessor; +use std::sync::Arc; /// Random accessor for Vortex format files. /// @@ -168,7 +169,7 @@ impl RandomAccessor for ParquetRandomAccessor { .with_batch_size(10_000_000) .build()?; - let schema = reader.schema().clone(); + let schema = Arc::clone(&reader.schema()); let batches = reader .enumerate() diff --git a/vortex-bench/src/statpopgen/builder.rs b/vortex-bench/src/statpopgen/builder.rs index 25b6a2735b2..7c46d1ff2b8 100644 --- a/vortex-bench/src/statpopgen/builder.rs +++ b/vortex-bench/src/statpopgen/builder.rs @@ -437,7 +437,7 @@ impl<'a> GnomADBuilder<'a> { }); RecordBatch::try_new( - self.schema.clone(), + Arc::clone(&self.schema), variant_fields .into_iter() .chain(info_fields) diff --git a/vortex-bench/src/statpopgen/download_vcf.rs b/vortex-bench/src/statpopgen/download_vcf.rs index 503bf0b0e5f..b209a8cdaf3 100644 --- a/vortex-bench/src/statpopgen/download_vcf.rs +++ b/vortex-bench/src/statpopgen/download_vcf.rs @@ -19,6 +19,7 @@ use super::StatPopGenBenchmark; use crate::idempotent_async; use crate::statpopgen::builder::GnomADBuilder; use crate::statpopgen::schema::schema_from_vcf_header; +use std::sync::Arc; // DuckDB parallelizes parquet at row-group granularity. Each of our rows are quite big (~4000 // genotypes each with tens of bytes of data). @@ -74,14 +75,14 @@ impl StatPopGenBenchmark { ); let mut record = Record::default(); let schema = schema_from_vcf_header(&header); - let mut builder = GnomADBuilder::new(&header, schema.clone()); + let mut builder = GnomADBuilder::new(&header, Arc::clone(&schema)); let file = File::create(parquet_output_path).await?; - let mut writer = AsyncArrowWriter::try_new(file, schema.clone(), None) + let mut writer = AsyncArrowWriter::try_new(file, Arc::clone(&schema), None) .context("Failed to create parquet writer")?; for i in progress.wrap_iter(0..self.n_rows) { if i % ROW_GROUP_SIZE_IN_VARIANTS == 0 { let rb = builder.finish()?; - builder = GnomADBuilder::new(&header, schema.clone()); + builder = GnomADBuilder::new(&header, Arc::clone(&schema)); writer .write(&rb) .await diff --git a/vortex-bench/src/tpch/tpchgen.rs b/vortex-bench/src/tpch/tpchgen.rs index 75fe4db9e8f..495cf4e9a72 100644 --- a/vortex-bench/src/tpch/tpchgen.rs +++ b/vortex-bench/src/tpch/tpchgen.rs @@ -136,7 +136,7 @@ pub async fn generate_tpch_tables(options: TpchGenOptions) -> Result<()> { let (tx, rx) = mpsc::unbounded_channel(); for f in all_futures { - let limiter = limiter.clone(); + let limiter = Arc::clone(&limiter); let tx = tx.clone(); tokio::task::spawn(async move { let _guard = limiter.acquire().await?; @@ -232,7 +232,7 @@ fn generate_table_files( let iter = create_single_batch_iterator(generator, &options_clone, partition_idx)?; // Create generator and process batches in streaming fashion - let schema = iter.schema().clone(); + let schema = Arc::clone(&iter.schema()); // Create writer based on format let mut writer: Box = match write_format { diff --git a/vortex-btrblocks/src/schemes/decimal.rs b/vortex-btrblocks/src/schemes/decimal.rs index 8fd21aa75cd..72613eb32e5 100644 --- a/vortex-btrblocks/src/schemes/decimal.rs +++ b/vortex-btrblocks/src/schemes/decimal.rs @@ -18,6 +18,7 @@ use crate::CascadingCompressor; use crate::CompressorContext; use crate::Scheme; use crate::SchemeExt; +use std::sync::Arc; /// Compression scheme for decimal arrays via byte-part decomposition. /// @@ -58,7 +59,7 @@ impl Scheme for DecimalScheme { ) -> VortexResult { // TODO(joe): add support splitting i128/256 buffers into chunks of primitive values // for compression. 2 for i128 and 4 for i256. - let decimal = data.array().clone().to_decimal(); + let decimal = Arc::clone(&data.array()).to_decimal(); let decimal = narrowed_decimal(decimal); let validity = decimal.validity(); let prim = match decimal.values_type() { diff --git a/vortex-btrblocks/src/schemes/float.rs b/vortex-btrblocks/src/schemes/float.rs index 0f5622cea3f..d984e97dd73 100644 --- a/vortex-btrblocks/src/schemes/float.rs +++ b/vortex-btrblocks/src/schemes/float.rs @@ -26,6 +26,7 @@ use crate::Scheme; use crate::SchemeExt; use crate::compress_patches; use crate::estimate_compression_ratio_with_sampling; +use std::sync::Arc; /// ALP (Adaptive Lossless floating-Point) encoding. #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -220,7 +221,7 @@ impl Scheme for NullDominatedSparseScheme { SparseArray::try_new( compressed_indices, - sparse.patches().values().clone(), + Arc::clone(&sparse.patches().values()), sparse.len(), sparse.fill_scalar().clone(), ) diff --git a/vortex-btrblocks/src/schemes/integer.rs b/vortex-btrblocks/src/schemes/integer.rs index e3eb7b7649b..3c4b9582744 100644 --- a/vortex-btrblocks/src/schemes/integer.rs +++ b/vortex-btrblocks/src/schemes/integer.rs @@ -38,6 +38,7 @@ use crate::Scheme; use crate::SchemeExt; use crate::compress_patches; use crate::estimate_compression_ratio_with_sampling; +use std::sync::Arc; /// Frame of Reference encoding. #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -793,7 +794,7 @@ mod tests { let compressed = btr.compress(&array.into_array())?; assert!(compressed.is::()); - let decoded = compressed.clone(); + let decoded = Arc::clone(&compressed); let expected = PrimitiveArray::new(buffer![0u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46], validity).into_array(); assert_arrays_eq!(decoded.as_ref(), expected.as_ref()); diff --git a/vortex-btrblocks/src/schemes/patches.rs b/vortex-btrblocks/src/schemes/patches.rs index 38ec1cf9068..b88a1edee05 100644 --- a/vortex-btrblocks/src/schemes/patches.rs +++ b/vortex-btrblocks/src/schemes/patches.rs @@ -9,6 +9,7 @@ use vortex_array::arrays::ConstantArray; use vortex_array::patches::Patches; use vortex_error::VortexError; use vortex_error::VortexResult; +use std::sync::Arc; /// Compresses the given patches by downscaling integers and checking for constant values. pub fn compress_patches(patches: Patches) -> VortexResult { @@ -24,7 +25,7 @@ pub fn compress_patches(patches: Patches) -> VortexResult { { ConstantArray::new(values.scalar_at(0)?, values.len()).into_array() } else { - values.clone() + Arc::clone(&values) }; let chunk_offsets = patches .chunk_offsets() diff --git a/vortex-btrblocks/src/schemes/rle.rs b/vortex-btrblocks/src/schemes/rle.rs index 8a34f21e532..0c56a29e4b6 100644 --- a/vortex-btrblocks/src/schemes/rle.rs +++ b/vortex-btrblocks/src/schemes/rle.rs @@ -31,6 +31,7 @@ use crate::SchemeExt; use crate::estimate_compression_ratio_with_sampling; use crate::schemes::integer::IntDictScheme; use crate::schemes::integer::SparseScheme; +use std::sync::Arc; /// Threshold for the average run length in an array before we consider run-length encoding. pub const RUN_LENGTH_THRESHOLD: u32 = 4; @@ -212,7 +213,7 @@ impl Scheme for RLEScheme { ctx: CompressorContext, ) -> VortexResult { // RLE is only useful when we cascade it with another encoding. - let array = data.array().clone(); + let array = Arc::clone(&data.array()); let stats = data.get_or_insert_with::(|| C::generate_stats(&array)); // Don't compress all-null or empty arrays. @@ -235,7 +236,7 @@ impl Scheme for RLEScheme { data: &mut ArrayAndStats, ctx: CompressorContext, ) -> VortexResult { - let array = data.array().clone(); + let array = Arc::clone(&data.array()); let stats = data.get_or_insert_with::(|| C::generate_stats(&array)); let rle_array = RLEArray::encode(RLEStats::source(stats))?; diff --git a/vortex-btrblocks/src/schemes/string.rs b/vortex-btrblocks/src/schemes/string.rs index fbcb771e9b5..515caa33fc0 100644 --- a/vortex-btrblocks/src/schemes/string.rs +++ b/vortex-btrblocks/src/schemes/string.rs @@ -24,6 +24,7 @@ use crate::CascadingCompressor; use crate::CompressorContext; use crate::Scheme; use crate::SchemeExt; +use std::sync::Arc; /// FSST (Fast Static Symbol Table) compression. #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -183,7 +184,7 @@ impl Scheme for NullDominatedSparseScheme { SparseArray::try_new( compressed_indices, - sparse.patches().values().clone(), + Arc::clone(&sparse.patches().values()), sparse.len(), sparse.fill_scalar().clone(), ) diff --git a/vortex-btrblocks/src/schemes/temporal.rs b/vortex-btrblocks/src/schemes/temporal.rs index f1ecb158d96..34a94a443ad 100644 --- a/vortex-btrblocks/src/schemes/temporal.rs +++ b/vortex-btrblocks/src/schemes/temporal.rs @@ -23,6 +23,7 @@ use crate::CascadingCompressor; use crate::CompressorContext; use crate::Scheme; use crate::SchemeExt; +use std::sync::Arc; /// Compression scheme for temporal timestamp arrays via datetime-part decomposition. /// @@ -75,7 +76,7 @@ impl Scheme for TemporalScheme { data: &mut ArrayAndStats, ctx: CompressorContext, ) -> VortexResult { - let array = data.array().clone(); + let array = Arc::clone(&data.array()); let ext_array = array.to_extension(); let temporal_array = TemporalArray::try_from(ext_array.clone().into_array())?; diff --git a/vortex-compressor/src/compressor.rs b/vortex-compressor/src/compressor.rs index 5aff682fbad..f71e2ba5977 100644 --- a/vortex-compressor/src/compressor.rs +++ b/vortex-compressor/src/compressor.rs @@ -126,7 +126,7 @@ impl CascadingCompressor { child_index: usize, ) -> VortexResult { if parent_ctx.finished_cascading() { - return Ok(child.clone()); + return Ok(Arc::clone(&child)); } let canonical = child diff --git a/vortex-compressor/src/scheme.rs b/vortex-compressor/src/scheme.rs index aae8e4606db..906d86d7db1 100644 --- a/vortex-compressor/src/scheme.rs +++ b/vortex-compressor/src/scheme.rs @@ -19,6 +19,7 @@ use crate::sample::sample; use crate::sample::sample_count_approx_one_percent; use crate::stats::ArrayAndStats; use crate::stats::GenerateStatsOptions; +use std::sync::Arc; /// Unique identifier for a compression scheme. /// @@ -259,7 +260,7 @@ pub fn estimate_compression_ratio_with_sampling( ctx: CompressorContext, ) -> VortexResult { let sample_array = if ctx.is_sample() { - array.clone() + Arc::clone(&array) } else { let source_len = array.len(); let sample_count = sample_count_approx_one_percent(source_len); diff --git a/vortex-compressor/src/stats/cache.rs b/vortex-compressor/src/stats/cache.rs index c83bf044b03..1cb77d64678 100644 --- a/vortex-compressor/src/stats/cache.rs +++ b/vortex-compressor/src/stats/cache.rs @@ -15,6 +15,7 @@ use super::FloatStats; use super::GenerateStatsOptions; use super::IntegerStats; use super::StringStats; +use std::sync::Arc; /// Cache for compression statistics, keyed by concrete type. struct StatsCache { @@ -99,7 +100,7 @@ impl ArrayAndStats { /// Returns bool stats, generating them lazily on first access. pub fn bool_stats(&mut self) -> &BoolStats { - let array = self.array.clone(); + let array = Arc::clone(&self.array); self.cache.get_or_insert_with::(|| { BoolStats::generate(&array.to_bool()).vortex_expect("BoolStats shouldn't fail") @@ -108,7 +109,7 @@ impl ArrayAndStats { /// Returns integer stats, generating them lazily on first access. pub fn integer_stats(&mut self) -> &IntegerStats { - let array = self.array.clone(); + let array = Arc::clone(&self.array); let opts = self.opts; self.cache.get_or_insert_with::(|| { @@ -118,7 +119,7 @@ impl ArrayAndStats { /// Returns float stats, generating them lazily on first access. pub fn float_stats(&mut self) -> &FloatStats { - let array = self.array.clone(); + let array = Arc::clone(&self.array); let opts = self.opts; self.cache.get_or_insert_with::(|| { @@ -128,7 +129,7 @@ impl ArrayAndStats { /// Returns string stats, generating them lazily on first access. pub fn string_stats(&mut self) -> &StringStats { - let array = self.array.clone(); + let array = Arc::clone(&self.array); let opts = self.opts; self.cache.get_or_insert_with::(|| { diff --git a/vortex-cuda/src/arrow/canonical.rs b/vortex-cuda/src/arrow/canonical.rs index a9e33f3958f..53b2047252b 100644 --- a/vortex-cuda/src/arrow/canonical.rs +++ b/vortex-cuda/src/arrow/canonical.rs @@ -29,6 +29,7 @@ use crate::arrow::check_validity_empty; use crate::arrow::varbinview::BinaryParts; use crate::arrow::varbinview::copy_varbinview_to_varbin; use crate::executor::CudaArrayExt; +use std::sync::Arc; /// An implementation of `ExportDeviceArray` that exports Vortex arrays to `ArrowDeviceArray` by /// first decoding the array on the GPU and then converting the canonical type to the nearest @@ -192,7 +193,7 @@ async fn export_struct( let mut children = Vec::with_capacity(fields.len()); for field in fields.iter() { - let cuda_field = field.clone().execute_cuda(ctx).await?; + let cuda_field = Arc::clone(&field).execute_cuda(ctx).await?; let (arrow_field, _) = export_canonical(cuda_field, ctx).await?; children.push(arrow_field); } diff --git a/vortex-cuda/src/device_buffer.rs b/vortex-cuda/src/device_buffer.rs index c8d2841f10a..3257318cde4 100644 --- a/vortex-cuda/src/device_buffer.rs +++ b/vortex-cuda/src/device_buffer.rs @@ -330,7 +330,7 @@ impl DeviceBuffer for CudaDeviceBuffer { let effective_ptr = self.device_ptr + self.offset as u64; if effective_ptr.is_multiple_of(*alignment as u64) { Ok(Arc::new(CudaDeviceBuffer { - allocation: self.allocation.clone(), + allocation: Arc::clone(&self.allocation), offset: self.offset, len: self.len, device_ptr: self.device_ptr, diff --git a/vortex-cuda/src/dynamic_dispatch/plan_builder.rs b/vortex-cuda/src/dynamic_dispatch/plan_builder.rs index 920fe4ea6bc..0ca29d826fd 100644 --- a/vortex-cuda/src/dynamic_dispatch/plan_builder.rs +++ b/vortex-cuda/src/dynamic_dispatch/plan_builder.rs @@ -33,6 +33,7 @@ use super::ScalarOp; use super::SourceOp; use crate::CudaBufferExt; use crate::CudaExecutionCtx; +use std::sync::Arc; /// A plan whose source buffers have been copied to the device, ready for kernel launch. pub struct MaterializedPlan { @@ -236,7 +237,7 @@ impl FusedPlan { }; let len = array.len() as u32; - let output = plan.walk(array.clone(), &mut pending_subtrees)?; + let output = plan.walk(Arc::clone(&array), &mut pending_subtrees)?; plan.stages.push((output, plan.smem_cursor, len)); Ok((plan, pending_subtrees)) @@ -391,7 +392,7 @@ impl FusedPlan { pending_subtrees: &mut Vec, ) -> VortexResult { let slice_arr = array.as_::(); - let child = slice_arr.child().clone(); + let child = Arc::clone(&slice_arr.child()); if let Some(reduced) = child.vtable().reduce_parent(&child, &array, 0)? { return self.walk(reduced, pending_subtrees); @@ -436,7 +437,7 @@ impl FusedPlan { .as_primitive() .pvalue() .ok_or_else(|| vortex_err!("FoR reference scalar is null"))?; - let encoded = for_arr.encoded().clone(); + let encoded = Arc::clone(&for_arr.encoded()); let mut pipeline = self.walk(encoded, pending_subtrees)?; let ref_u64 = ref_pvalue @@ -452,7 +453,7 @@ impl FusedPlan { pending_subtrees: &mut Vec, ) -> VortexResult { let zz = array.as_::(); - let encoded = zz.encoded().clone(); + let encoded = Arc::clone(&zz.encoded()); let mut pipeline = self.walk(encoded, pending_subtrees)?; pipeline.scalar_ops.push(ScalarOp::zigzag()); @@ -481,7 +482,7 @@ impl FusedPlan { let exponents = alp.exponents(); let alp_f = ::F10[exponents.f as usize]; let alp_e = ::IF10[exponents.e as usize]; - let encoded = alp.encoded().clone(); + let encoded = Arc::clone(&alp.encoded()); let mut pipeline = self.walk(encoded, pending_subtrees)?; pipeline.scalar_ops.push(ScalarOp::alp(alp_f, alp_e)); @@ -494,8 +495,8 @@ impl FusedPlan { pending_subtrees: &mut Vec, ) -> VortexResult { let dict = array.as_::(); - let values = dict.values().clone(); - let codes = dict.codes().clone(); + let values = Arc::clone(&dict.values()); + let codes = Arc::clone(&dict.codes()); let values_len = values.len() as u32; let values_spec = self.walk(values, pending_subtrees)?; @@ -522,8 +523,8 @@ impl FusedPlan { ) -> VortexResult { let re = array.as_::(); let offset = re.offset() as u64; - let ends = re.ends().clone(); - let values = re.values().clone(); + let ends = Arc::clone(&re.ends()); + let values = Arc::clone(&re.values()); let num_runs = ends.len() as u32; let num_values = values.len() as u32; diff --git a/vortex-cuda/src/executor.rs b/vortex-cuda/src/executor.rs index 5f8e81fc226..6aff87cca96 100644 --- a/vortex-cuda/src/executor.rs +++ b/vortex-cuda/src/executor.rs @@ -370,7 +370,7 @@ impl CudaArrayExt for ArrayRef { let mut cuda_fields = Vec::with_capacity(fields.len()); for field in fields.iter() { - cuda_fields.push(field.clone().execute_cuda(ctx).await?.into_array()); + cuda_fields.push(Arc::clone(&field).execute_cuda(ctx).await?.into_array()); } return Ok(Canonical::Struct(StructArray::new( diff --git a/vortex-cuda/src/hybrid_dispatch/mod.rs b/vortex-cuda/src/hybrid_dispatch/mod.rs index 36a04e6402f..f9b4e26629a 100644 --- a/vortex-cuda/src/hybrid_dispatch/mod.rs +++ b/vortex-cuda/src/hybrid_dispatch/mod.rs @@ -52,6 +52,7 @@ use vortex::error::vortex_err; use crate::dynamic_dispatch::plan_builder::DispatchPlan; use crate::executor::CudaArrayExt; use crate::executor::CudaExecutionCtx; +use std::sync::Arc; /// Try to execute `array` on the GPU, attempting three strategies in order: /// @@ -87,7 +88,7 @@ pub async fn try_gpu_dispatch( // TODO(0ax1): execute subtrees concurrently using separate CUDA streams. for subtree in &pending_subtrees { - let canonical = subtree.clone().execute_cuda(ctx).await?; + let canonical = Arc::clone(&subtree).execute_cuda(ctx).await?; subtree_buffers.push(canonical.into_primitive().into_parts().buffer); } @@ -104,7 +105,7 @@ pub async fn try_gpu_dispatch( .ok_or_else(|| { vortex_err!("No CUDA kernel for encoding {:?}", array.encoding_id()) })? - .execute(array.clone(), ctx) + .execute(Arc::clone(&array), ctx) .await } } diff --git a/vortex-cuda/src/kernel/encodings/alp.rs b/vortex-cuda/src/kernel/encodings/alp.rs index 8eb3d405a51..2bcd1da5372 100644 --- a/vortex-cuda/src/kernel/encodings/alp.rs +++ b/vortex-cuda/src/kernel/encodings/alp.rs @@ -65,7 +65,7 @@ where let e: A = A::IF10[exponents.e as usize]; // Execute child and copy to device - let canonical = array.encoded().clone().execute_cuda(ctx).await?; + let canonical = Arc::clone(&array.encoded()).execute_cuda(ctx).await?; let primitive = canonical.into_primitive(); let PrimitiveArrayParts { buffer, validity, .. diff --git a/vortex-cuda/src/kernel/encodings/date_time_parts.rs b/vortex-cuda/src/kernel/encodings/date_time_parts.rs index 50a74630160..9062d56986c 100644 --- a/vortex-cuda/src/kernel/encodings/date_time_parts.rs +++ b/vortex-cuda/src/kernel/encodings/date_time_parts.rs @@ -95,9 +95,9 @@ impl CudaExecute for DateTimePartsExecutor { TimeUnit::Days => vortex_bail!("Cannot decode DateTimeParts with TimeUnit::Days"), }; - let days_canonical = array.days().clone().execute_cuda(ctx).await?; - let seconds_canonical = array.seconds().clone().execute_cuda(ctx).await?; - let subseconds_canonical = array.subseconds().clone().execute_cuda(ctx).await?; + let days_canonical = Arc::clone(&array.days()).execute_cuda(ctx).await?; + let seconds_canonical = Arc::clone(&array.seconds()).execute_cuda(ctx).await?; + let subseconds_canonical = Arc::clone(&array.subseconds()).execute_cuda(ctx).await?; let days_prim = days_canonical.into_primitive(); diff --git a/vortex-cuda/src/kernel/encodings/for_.rs b/vortex-cuda/src/kernel/encodings/for_.rs index 29e00f4ec92..9fa70c88afe 100644 --- a/vortex-cuda/src/kernel/encodings/for_.rs +++ b/vortex-cuda/src/kernel/encodings/for_.rs @@ -29,6 +29,7 @@ use crate::executor::CudaArrayExt; use crate::executor::CudaExecute; use crate::executor::CudaExecutionCtx; use crate::kernel::encodings::bitpacked::decode_bitpacked; +use std::sync::Arc; /// CUDA decoder for frame-of-reference. #[derive(Debug)] @@ -90,7 +91,7 @@ where .vortex_expect("Cannot have a null reference"); // Execute child and copy to device - let canonical = array.encoded().clone().execute_cuda(ctx).await?; + let canonical = Arc::clone(&array.encoded()).execute_cuda(ctx).await?; let primitive = canonical.into_primitive(); let PrimitiveArrayParts { buffer, validity, .. diff --git a/vortex-cuda/src/kernel/encodings/zigzag.rs b/vortex-cuda/src/kernel/encodings/zigzag.rs index 7e470299ac7..0888ce882b1 100644 --- a/vortex-cuda/src/kernel/encodings/zigzag.rs +++ b/vortex-cuda/src/kernel/encodings/zigzag.rs @@ -24,6 +24,7 @@ use crate::CudaBufferExt; use crate::executor::CudaArrayExt; use crate::executor::CudaExecute; use crate::executor::CudaExecutionCtx; +use std::sync::Arc; /// CUDA decoder for ZigZag decoding. #[derive(Debug)] @@ -68,7 +69,7 @@ where vortex_ensure!(array_len > 0, "ZigZag array must not be empty"); // Execute child and copy to device - let canonical = array.encoded().clone().execute_cuda(ctx).await?; + let canonical = Arc::clone(&array.encoded()).execute_cuda(ctx).await?; let primitive = canonical.into_primitive(); let PrimitiveArrayParts { buffer, validity, .. diff --git a/vortex-cuda/src/kernel/encodings/zstd.rs b/vortex-cuda/src/kernel/encodings/zstd.rs index 06ff9094691..b4bc83199e9 100644 --- a/vortex-cuda/src/kernel/encodings/zstd.rs +++ b/vortex-cuda/src/kernel/encodings/zstd.rs @@ -446,7 +446,7 @@ mod tests { let cpu_result = sliced_zstd.to_canonical()?; let gpu_result = ZstdExecutor - .execute(sliced_zstd.clone(), &mut cuda_ctx) + .execute(Arc::clone(&sliced_zstd), &mut cuda_ctx) .await?; assert_arrays_eq!(cpu_result.into_array(), gpu_result.into_array()); diff --git a/vortex-cuda/src/kernel/patches/mod.rs b/vortex-cuda/src/kernel/patches/mod.rs index dd107e87154..657bf1f488c 100644 --- a/vortex-cuda/src/kernel/patches/mod.rs +++ b/vortex-cuda/src/kernel/patches/mod.rs @@ -34,8 +34,8 @@ pub(crate) async fn execute_patches< target: CudaDeviceBuffer, ctx: &mut CudaExecutionCtx, ) -> VortexResult { - let indices = patches.indices().clone(); - let values = patches.values().clone(); + let indices = Arc::clone(&patches.indices()); + let values = Arc::clone(&patches.values()); drop(patches); let indices = indices.execute_cuda(ctx).await?.into_primitive(); diff --git a/vortex-cuda/src/layout.rs b/vortex-cuda/src/layout.rs index e598db6a5b2..94bac5854b7 100644 --- a/vortex-cuda/src/layout.rs +++ b/vortex-cuda/src/layout.rs @@ -248,7 +248,7 @@ impl CudaFlatReader { let session = self.session.clone(); let dtype = self.layout.dtype.clone(); let array_tree = self.layout.array_tree.clone(); - let host_buffers = self.layout.host_buffers.clone(); + let host_buffers = Arc::clone(&self.layout.host_buffers); async move { let segment = segment_fut.await?; @@ -310,7 +310,7 @@ impl LayoutReader for CudaFlatReader { .vortex_expect("Row range begin must fit within CudaFlatLayout size") ..usize::try_from(row_range.end) .vortex_expect("Row range end must fit within CudaFlatLayout size"); - let name = self.name.clone(); + let name = Arc::clone(&self.name); let array = self.array_future(); let expr = expr.clone(); let session = self.session.clone(); @@ -358,7 +358,7 @@ impl LayoutReader for CudaFlatReader { .vortex_expect("Row range begin must fit within CudaFlatLayout size") ..usize::try_from(row_range.end) .vortex_expect("Row range end must fit within CudaFlatLayout size"); - let name = self.name.clone(); + let name = Arc::clone(&self.name); let array = self.array_future(); let expr = expr.clone(); diff --git a/vortex-cuda/src/pinned.rs b/vortex-cuda/src/pinned.rs index c48cf98624b..4363d4dd965 100644 --- a/vortex-cuda/src/pinned.rs +++ b/vortex-cuda/src/pinned.rs @@ -143,7 +143,7 @@ impl PinnedByteBufferPool { /// Unlike `get`, this will never call `cuMemAllocHost`. pub fn try_get(self: &Arc, len: usize) -> VortexResult> { match self.try_get_inner(len)? { - Some(inner) => Ok(Some(PooledPinnedBuffer::new(inner, self.clone()))), + Some(inner) => Ok(Some(PooledPinnedBuffer::new(inner, Arc::clone(&self)))), None => Ok(None), } } @@ -153,7 +153,7 @@ impl PinnedByteBufferPool { /// The buffer is returned to the pool when the [`PooledPinnedBuffer`] is dropped. pub(crate) fn get(self: &Arc, len: usize) -> VortexResult { let inner = self.get_inner(len)?; - Ok(PooledPinnedBuffer::new(inner, self.clone())) + Ok(PooledPinnedBuffer::new(inner, Arc::clone(&self))) } /// Defer returning a pinned buffer to the pool until the CUDA event completes. diff --git a/vortex-cuda/src/stream.rs b/vortex-cuda/src/stream.rs index ce2c3fe9bd2..1b7c99c54a9 100644 --- a/vortex-cuda/src/stream.rs +++ b/vortex-cuda/src/stream.rs @@ -78,7 +78,7 @@ impl VortexCudaStream { .map_err(|e| vortex_err!("Failed to schedule H2D copy: {}", e))?; let cuda_buf = CudaDeviceBuffer::new(cuda_slice); - let stream = self.0.clone(); + let stream = Arc::clone(&self.0); Ok(Box::pin(async move { await_stream_callback(&stream).await?; diff --git a/vortex-datafusion/src/convert/exprs.rs b/vortex-datafusion/src/convert/exprs.rs index 79fec6e1e3e..654b82f2cab 100644 --- a/vortex-datafusion/src/convert/exprs.rs +++ b/vortex-datafusion/src/convert/exprs.rs @@ -952,7 +952,7 @@ mod tests { // WHEN value > 10 THEN 100 let when1 = Arc::new(df_expr::BinaryExpr::new( - col_value.clone(), + Arc::clone(&col_value), DFOperator::Gt, lit_10, )) as Arc; diff --git a/vortex-datafusion/src/lib.rs b/vortex-datafusion/src/lib.rs index 8e7fc57dbf5..2dab59dd2b0 100644 --- a/vortex-datafusion/src/lib.rs +++ b/vortex-datafusion/src/lib.rs @@ -106,7 +106,7 @@ mod common_tests { factory.get_ext().to_uppercase(), Arc::new(DefaultTableFactory::new()), ) - .with_object_store(&Url::try_from("file://").unwrap(), store.clone()); + .with_object_store(&Url::try_from("file://").unwrap(), Arc::clone(&store)); if let Some(file_formats) = session_state_builder.file_formats() { file_formats.push(factory as _); @@ -124,7 +124,7 @@ mod common_tests { P: Into, { let array = ArrayRef::from_arrow(batch, false)?; - let mut write = ObjectStoreWrite::new(self.store.clone(), &path.into()).await?; + let mut write = ObjectStoreWrite::new(Arc::clone(&self.store), &path.into()).await?; VX_SESSION .write_options() .write(&mut write, array.to_array_stream()) diff --git a/vortex-datafusion/src/persistent/format.rs b/vortex-datafusion/src/persistent/format.rs index 0be2086c885..b15c6e00e60 100644 --- a/vortex-datafusion/src/persistent/format.rs +++ b/vortex-datafusion/src/persistent/format.rs @@ -246,10 +246,10 @@ impl FileFormat for VortexFormat { let mut file_schemas = stream::iter(objects.iter().cloned()) .map(|object| { - let store = store.clone(); + let store = Arc::clone(&store); let session = self.session.clone(); let opts = self.opts.clone(); - let cache = file_metadata_cache.clone(); + let cache = Arc::clone(&file_metadata_cache); SpawnedTask::spawn(async move { // Check if we have entry metadata for this file @@ -309,7 +309,7 @@ impl FileFormat for VortexFormat { object: &ObjectMeta, ) -> DFResult { let object = object.clone(); - let store = store.clone(); + let store = Arc::clone(&store); let session = self.session.clone(); let opts = self.opts.clone(); let file_metadata_cache = state.runtime_env().cache_manager.get_file_metadata_cache(); @@ -516,7 +516,7 @@ impl FileFormat for VortexFormat { return not_impl_err!("Overwrites are not implemented yet for Vortex"); } - let schema = conf.output_schema().clone(); + let schema = Arc::clone(&conf.output_schema()); let sink = Arc::new(VortexSink::new(conf, schema, self.session.clone())); Ok(Arc::new(DataSinkExec::new(input, sink, order_requirements)) as _) diff --git a/vortex-datafusion/src/persistent/mod.rs b/vortex-datafusion/src/persistent/mod.rs index 558032ebd01..7093fb71134 100644 --- a/vortex-datafusion/src/persistent/mod.rs +++ b/vortex-datafusion/src/persistent/mod.rs @@ -65,7 +65,7 @@ mod tests { Validity::NonNullable, )?; - let mut writer = ObjectStoreWrite::new(ctx.store.clone(), &"test.vortex".into()).await?; + let mut writer = ObjectStoreWrite::new(Arc::clone(&ctx.store), &"test.vortex".into()).await?; let summary = session .write_options() diff --git a/vortex-datafusion/src/persistent/opener.rs b/vortex-datafusion/src/persistent/opener.rs index 8636a4e04e2..311d84e145a 100644 --- a/vortex-datafusion/src/persistent/opener.rs +++ b/vortex-datafusion/src/persistent/opener.rs @@ -101,7 +101,7 @@ pub(crate) struct VortexOpener { impl FileOpener for VortexOpener { fn open(&self, file: PartitionedFile) -> DFResult { let session = self.session.clone(); - let metrics_registry = self.metrics_registry.clone(); + let metrics_registry = Arc::clone(&self.metrics_registry); let labels = vec![ Label::new(PATH_LABEL, file.path().to_string()), Label::new(PARTITION_LABEL, self.partition.to_string()), @@ -116,17 +116,17 @@ impl FileOpener for VortexOpener { InstrumentedReadAt::new_with_labels(reader, metrics_registry.as_ref(), labels.clone()); let file_pruning_predicate = self.file_pruning_predicate.clone(); - let expr_adapter_factory = self.expr_adapter_factory.clone(); + let expr_adapter_factory = Arc::clone(&self.expr_adapter_factory); let file_metadata_cache = self.file_metadata_cache.clone(); - let unified_file_schema = self.table_schema.file_schema().clone(); + let unified_file_schema = Arc::clone(&self.table_schema.file_schema()); let batch_size = self.batch_size; let limit = self.limit; - let layout_reader = self.layout_readers.clone(); + let layout_reader = Arc::clone(&self.layout_readers); let has_output_ordering = self.has_output_ordering; let scan_concurrency = self.scan_concurrency; - let expr_convertor = self.expression_convertor.clone(); + let expr_convertor = Arc::clone(&self.expression_convertor); let projection_pushdown = self.projection_pushdown; // Replace column access for partition columns with literals @@ -163,7 +163,7 @@ impl FileOpener for VortexOpener { }) .and_then(|predicate| { FilePruner::try_new( - predicate.clone(), + Arc::clone(&predicate), &unified_file_schema, &file, Count::default(), @@ -181,7 +181,7 @@ impl FileOpener for VortexOpener { let mut open_opts = session .open_options() .with_file_size(file.object_meta.size) - .with_metrics_registry(metrics_registry.clone()) + .with_metrics_registry(Arc::clone(&metrics_registry)) .with_labels(labels); if let Some(file_metadata_cache) = file_metadata_cache @@ -590,14 +590,14 @@ mod tests { let file_path = "part=1/file.vortex"; let batch = record_batch!(("a", Int32, vec![Some(1), Some(2), Some(3)])).unwrap(); let data_size = - write_arrow_to_vortex(object_store.clone(), file_path, batch.clone()).await?; + write_arrow_to_vortex(Arc::clone(&object_store), file_path, batch.clone()).await?; let file_schema = batch.schema(); let mut file = PartitionedFile::new(file_path.to_string(), data_size); file.partition_values = vec![ScalarValue::Int32(Some(1))]; let table_schema = TableSchema::new( - file_schema.clone(), + Arc::clone(&file_schema), vec![Arc::new(Field::new("part", DataType::Int32, false))], ); @@ -605,7 +605,7 @@ mod tests { let filter = col("part").eq(lit(1)); let filter = logical2physical(&filter, table_schema.table_schema()); - let opener = make_opener(object_store.clone(), table_schema.clone(), Some(filter)); + let opener = make_opener(Arc::clone(&object_store), table_schema.clone(), Some(filter)); let stream = opener.open(file.clone()).unwrap().await.unwrap(); let data = stream.try_collect::>().await?; @@ -618,7 +618,7 @@ mod tests { let filter = col("part").eq(lit(2)); let filter = logical2physical(&filter, table_schema.table_schema()); - let opener = make_opener(object_store.clone(), table_schema.clone(), Some(filter)); + let opener = make_opener(Arc::clone(&object_store), table_schema.clone(), Some(filter)); let stream = opener.open(file.clone()).unwrap().await.unwrap(); let data = stream.try_collect::>().await?; @@ -637,7 +637,7 @@ mod tests { let data_batch = record_batch!(("a", Int32, Vec::::new())).unwrap(); let file_path = "part=1/empty.vortex"; let file_size = - write_arrow_to_vortex(object_store.clone(), file_path, data_batch.clone()).await?; + write_arrow_to_vortex(Arc::clone(&object_store), file_path, data_batch.clone()).await?; let file_schema = data_batch.schema(); // Parallel scans may attach a byte range even for empty files; the @@ -645,7 +645,7 @@ mod tests { let file = PartitionedFile::new_with_range(file_path.to_string(), file_size, 0, file_size as i64); - let table_schema = TableSchema::from_file_schema(file_schema.clone()); + let table_schema = TableSchema::from_file_schema(Arc::clone(&file_schema)); let opener = make_opener(object_store, table_schema, None); let stream = opener.open(file)?.await?; @@ -665,7 +665,7 @@ mod tests { let file1_path = "/path/file1.vortex"; let batch1 = record_batch!(("a", Int32, vec![Some(1), Some(2), Some(3)])).unwrap(); let data_size1 = - write_arrow_to_vortex(object_store.clone(), file1_path, batch1).await?; + write_arrow_to_vortex(Arc::clone(&object_store), file1_path, batch1).await?; PartitionedFile::new(file1_path.to_string(), data_size1) }; @@ -673,7 +673,7 @@ mod tests { let file2_path = "/path/file2.vortex"; let batch2 = record_batch!(("a", Int16, vec![Some(-1), Some(-2), Some(-3)])).unwrap(); let data_size2 = - write_arrow_to_vortex(object_store.clone(), file2_path, batch2).await?; + write_arrow_to_vortex(Arc::clone(&object_store), file2_path, batch2).await?; PartitionedFile::new(file2_path.to_string(), data_size2) }; @@ -687,7 +687,7 @@ mod tests { let make_opener = |filter| VortexOpener { partition: 1, session: SESSION.clone(), - vortex_reader_factory: Arc::new(DefaultVortexReaderFactory::new(object_store.clone())), + vortex_reader_factory: Arc::new(DefaultVortexReaderFactory::new(Arc::clone(&object_store))), projection: ProjectionExprs::from_indices(&[0], table_schema.file_schema()), filter: Some(filter), file_pruning_predicate: None, @@ -707,7 +707,7 @@ mod tests { let filter = col("a").lt(lit(100_i32)); let filter = logical2physical(&filter, table_schema.table_schema()); - let opener1 = make_opener(filter.clone()); + let opener1 = make_opener(Arc::clone(&filter)); let stream = opener1.open(file1)?.await?; let format_opts = FormatOptions::new().with_types_info(true); @@ -724,7 +724,7 @@ mod tests { +-------+ "); - let opener2 = make_opener(filter.clone()); + let opener2 = make_opener(Arc::clone(&filter)); let stream = opener2.open(file2)?.await?; let data = stream.try_collect::>().await?; @@ -760,7 +760,7 @@ mod tests { ("a", Int32, vec![Some(100), Some(101), Some(102)]) ) .unwrap(); - let data_size = write_arrow_to_vortex(object_store.clone(), file_path, batch).await?; + let data_size = write_arrow_to_vortex(Arc::clone(&object_store), file_path, batch).await?; let file = PartitionedFile::new(file_path.to_string(), data_size); // Table schema has columns in different order: a, b, c @@ -778,7 +778,7 @@ mod tests { filter: None, file_pruning_predicate: None, expr_adapter_factory: Arc::new(DefaultPhysicalExprAdapterFactory), - table_schema: TableSchema::from_file_schema(table_schema.clone()), + table_schema: TableSchema::from_file_schema(Arc::clone(&table_schema)), batch_size: 100, limit: None, metrics_registry: Arc::new(DefaultMetricsRegistry::default()), @@ -838,7 +838,7 @@ mod tests { )])), vec![Arc::new(struct_array)], )?; - let data_size = write_arrow_to_vortex(object_store.clone(), file_path, batch).await?; + let data_size = write_arrow_to_vortex(Arc::clone(&object_store), file_path, batch).await?; // Table schema has an extra utf8 field. let table_schema = TableSchema::from_file_schema(Arc::new(Schema::new(vec![Field::new( @@ -860,7 +860,7 @@ mod tests { )]))); let opener = make_opener( - object_store.clone(), + Arc::clone(&object_store), table_schema.clone(), // expression references my_struct column which has different fields in each // field. @@ -899,7 +899,7 @@ mod tests { ("c", Int32, vec![Some(2)]) ) .unwrap(); - let data_size = write_arrow_to_vortex(object_store.clone(), file_path, batch).await?; + let data_size = write_arrow_to_vortex(Arc::clone(&object_store), file_path, batch).await?; // Table schema has columns in DIFFERENT order: c, a, b // and different types that require casting (Utf8 -> Dictionary) @@ -924,7 +924,7 @@ mod tests { let opener = VortexOpener { partition: 1, session: SESSION.clone(), - vortex_reader_factory: Arc::new(DefaultVortexReaderFactory::new(object_store.clone())), + vortex_reader_factory: Arc::new(DefaultVortexReaderFactory::new(Arc::clone(&object_store))), projection: ProjectionExprs::from_indices( projection.as_ref(), table_schema.file_schema(), @@ -1016,7 +1016,7 @@ mod tests { let batch = make_test_batch_with_10_rows(); let data_size = - write_arrow_to_vortex(object_store.clone(), file_path, batch.clone()).await?; + write_arrow_to_vortex(Arc::clone(&object_store), file_path, batch.clone()).await?; let schema = batch.schema(); let mut file = PartitionedFile::new(file_path.to_string(), data_size); @@ -1025,8 +1025,8 @@ mod tests { ))); let opener = make_test_opener( - object_store.clone(), - schema.clone(), + Arc::clone(&object_store), + Arc::clone(&schema), ProjectionExprs::from_indices(&[0, 1], &schema), ); @@ -1057,7 +1057,7 @@ mod tests { let batch = make_test_batch_with_10_rows(); let data_size = - write_arrow_to_vortex(object_store.clone(), file_path, batch.clone()).await?; + write_arrow_to_vortex(Arc::clone(&object_store), file_path, batch.clone()).await?; let schema = batch.schema(); let mut file = PartitionedFile::new(file_path.to_string(), data_size); @@ -1066,8 +1066,8 @@ mod tests { ))); let opener = make_test_opener( - object_store.clone(), - schema.clone(), + Arc::clone(&object_store), + Arc::clone(&schema), ProjectionExprs::from_indices(&[0, 1], &schema), ); @@ -1101,7 +1101,7 @@ mod tests { let batch = make_test_batch_with_10_rows(); let data_size = - write_arrow_to_vortex(object_store.clone(), file_path, batch.clone()).await?; + write_arrow_to_vortex(Arc::clone(&object_store), file_path, batch.clone()).await?; let schema = batch.schema(); let mut file = PartitionedFile::new(file_path.to_string(), data_size); @@ -1110,8 +1110,8 @@ mod tests { )); let opener = make_test_opener( - object_store.clone(), - schema.clone(), + Arc::clone(&object_store), + Arc::clone(&schema), ProjectionExprs::from_indices(&[0], &schema), ); @@ -1132,15 +1132,15 @@ mod tests { let batch = make_test_batch_with_10_rows(); let data_size = - write_arrow_to_vortex(object_store.clone(), file_path, batch.clone()).await?; + write_arrow_to_vortex(Arc::clone(&object_store), file_path, batch.clone()).await?; let schema = batch.schema(); let file = PartitionedFile::new(file_path.to_string(), data_size); // file.extensions is None by default let opener = make_test_opener( - object_store.clone(), - schema.clone(), + Arc::clone(&object_store), + Arc::clone(&schema), ProjectionExprs::from_indices(&[0], &schema), ); @@ -1164,10 +1164,10 @@ mod tests { ) .unwrap(); let data_size = - write_arrow_to_vortex(object_store.clone(), file_path, batch.clone()).await?; + write_arrow_to_vortex(Arc::clone(&object_store), file_path, batch.clone()).await?; let file_schema = batch.schema(); - let table_schema = TableSchema::from_file_schema(file_schema.clone()); + let table_schema = TableSchema::from_file_schema(Arc::clone(&file_schema)); // Create a projection that includes an arithmetic expression: a + b * 2 let col_a = df_expr::col("a", &file_schema)?; @@ -1187,7 +1187,7 @@ mod tests { let opener = VortexOpener { partition: 1, session: SESSION.clone(), - vortex_reader_factory: Arc::new(DefaultVortexReaderFactory::new(object_store.clone())), + vortex_reader_factory: Arc::new(DefaultVortexReaderFactory::new(Arc::clone(&object_store))), projection, filter: None, file_pruning_predicate: None, @@ -1250,14 +1250,14 @@ mod tests { DataType::Struct(struct_fields.clone()), false, )])); - let batch = RecordBatch::try_new(schema.clone(), vec![Arc::new(struct_array)])?; + let batch = RecordBatch::try_new(Arc::clone(&schema), vec![Arc::new(struct_array)])?; let file_path = "/test.vortex"; - let data_size = write_arrow_to_vortex(object_store.clone(), file_path, batch).await?; + let data_size = write_arrow_to_vortex(Arc::clone(&object_store), file_path, batch).await?; let opener = make_test_opener( - object_store.clone(), - schema.clone(), + Arc::clone(&object_store), + Arc::clone(&schema), ProjectionExprs::from_indices(&[0], &schema), ); let data: Vec<_> = opener diff --git a/vortex-datafusion/src/persistent/reader.rs b/vortex-datafusion/src/persistent/reader.rs index 4e480ca374f..fad6ef37eaf 100644 --- a/vortex-datafusion/src/persistent/reader.rs +++ b/vortex-datafusion/src/persistent/reader.rs @@ -46,7 +46,7 @@ impl VortexReaderFactory for DefaultVortexReaderFactory { session: &VortexSession, ) -> DFResult> { Ok(Arc::new(ObjectStoreReadAt::new( - self.object_store.clone(), + Arc::clone(&self.object_store), file.path().as_ref().into(), session.handle(), )) as _) diff --git a/vortex-datafusion/src/persistent/sink.rs b/vortex-datafusion/src/persistent/sink.rs index 60cf1a8d0f4..263579a8cd5 100644 --- a/vortex-datafusion/src/persistent/sink.rs +++ b/vortex-datafusion/src/persistent/sink.rs @@ -113,7 +113,7 @@ impl FileSink for VortexSink { // 1. We can probably be better at signaling how much memory we're consuming (potentially when reading too), see ParquetSink::spawn_writer_tasks_and_join. while let Some((path, rx)) = file_stream_rx.recv().await { let session = self.session.clone(); - let object_store = object_store.clone(); + let object_store = Arc::clone(&object_store); let writer_schema = get_writer_schema(&self.config); let dtype = DType::from_arrow(writer_schema); @@ -267,7 +267,7 @@ mod tests { let logical_plan = LogicalPlanBuilder::insert_into( LogicalPlan::Values(values.clone()), "my_tbl", - Arc::new(DefaultTableSource::new(tbl_provider.clone())), + Arc::new(DefaultTableSource::new(Arc::clone(&tbl_provider))), datafusion::logical_expr::dml::InsertOp::Append, )? .build()?; diff --git a/vortex-datafusion/src/persistent/source.rs b/vortex-datafusion/src/persistent/source.rs index bac7fe2b39a..537e6162d0b 100644 --- a/vortex-datafusion/src/persistent/source.rs +++ b/vortex-datafusion/src/persistent/source.rs @@ -186,8 +186,8 @@ impl FileSource for VortexSource { table_schema: self.table_schema.clone(), batch_size, limit: base_config.limit.map(|l| l as u64), - metrics_registry: self.vx_metrics_registry.clone(), - layout_readers: self.layout_readers.clone(), + metrics_registry: Arc::clone(&self.vx_metrics_registry), + layout_readers: Arc::clone(&self.layout_readers), has_output_ordering: !base_config.output_ordering.is_empty(), expression_convertor: Arc::new(DefaultExpressionConvertor::default()), file_metadata_cache: self.file_metadata_cache.clone(), diff --git a/vortex-datafusion/src/tests/schema_evolution.rs b/vortex-datafusion/src/tests/schema_evolution.rs index 02254ef6afd..a46d3940f2c 100644 --- a/vortex-datafusion/src/tests/schema_evolution.rs +++ b/vortex-datafusion/src/tests/schema_evolution.rs @@ -236,7 +236,7 @@ async fn test_filter_schema_evolution_struct_fields( let read_schema = host02.schema(); let provider = ctx - .table_provider("tbl", "/files/", read_schema.clone()) + .table_provider("tbl", "/files/", Arc::clone(&read_schema)) .await?; let table = ctx.session.read_table(provider)?; @@ -359,7 +359,7 @@ async fn test_schema_evolution_struct_of_dict( let read_schema = batch.schema(); let provider = ctx - .table_provider("tbl", "/files/", read_schema.clone()) + .table_provider("tbl", "/files/", Arc::clone(&read_schema)) .await?; let table = ctx.session.read_table(provider)?; @@ -582,7 +582,7 @@ async fn test_dictionary_column_type_preservation( // Create table with explicit schema that expects Dictionary types let table_schema = batch.schema(); let provider = ctx - .table_provider("tbl", "/files/", table_schema.clone()) + .table_provider("tbl", "/files/", Arc::clone(&table_schema)) .await?; let table = ctx.session.read_table(provider)?; @@ -652,13 +652,13 @@ async fn test_nested_struct_dictionary_type_preservation( ])); let batch = RecordBatch::try_new( - schema.clone(), + Arc::clone(&schema), vec![Arc::new(labels_struct), value_array, producer_array], )?; ctx.write_arrow_batch("files/data.vortex", &batch).await?; - let provider = ctx.table_provider("tbl", "/files/", schema.clone()).await?; + let provider = ctx.table_provider("tbl", "/files/", Arc::clone(&schema)).await?; let table = ctx.session.read_table(provider)?; // Query that projects a nested struct field (like in polarsignals Q0) @@ -740,7 +740,7 @@ async fn test_polarsignals_like_schema( ])); let batch = RecordBatch::try_new( - schema.clone(), + Arc::clone(&schema), vec![ Arc::new(labels_struct), value_array, @@ -754,7 +754,7 @@ async fn test_polarsignals_like_schema( ctx.write_arrow_batch("files/data.vortex", &batch).await?; - let provider = ctx.table_provider("tbl", "/files/", schema.clone()).await?; + let provider = ctx.table_provider("tbl", "/files/", Arc::clone(&schema)).await?; let table = ctx.session.read_table(provider)?; // Query like polarsignals Q0: filter on multiple dictionary columns, project value and labels.comm @@ -815,7 +815,7 @@ async fn test_external_table_dictionary_columns( ])); let batch = RecordBatch::try_new( - schema.clone(), + Arc::clone(&schema), vec![producer_array, sample_type_array, value_array], )?; @@ -901,7 +901,7 @@ async fn test_sql_struct_field_dictionary_type( ])); let batch = RecordBatch::try_new( - schema.clone(), + Arc::clone(&schema), vec![ Arc::new(labels_struct), value_array, diff --git a/vortex-datafusion/src/v2/source.rs b/vortex-datafusion/src/v2/source.rs index 3f3adb478d4..47516ca5543 100644 --- a/vortex-datafusion/src/v2/source.rs +++ b/vortex-datafusion/src/v2/source.rs @@ -162,11 +162,11 @@ impl VortexDataSourceBuilder { Ok(VortexDataSource { data_source: self.data_source, session: self.session, - initial_schema: arrow_schema.clone(), + initial_schema: Arc::clone(&arrow_schema), initial_projection: projection.clone(), initial_statistics: statistics.clone(), projected_projection: projection.clone(), - projected_schema: arrow_schema.clone(), + projected_schema: Arc::clone(&arrow_schema), projected_statistics: statistics.clone(), leftover_projection: None, leftover_schema: arrow_schema, @@ -285,8 +285,8 @@ impl DataSource for VortexDataSource { ..Default::default() }; - let data_source = self.data_source.clone(); - let projected_schema = self.projected_schema.clone(); + let data_source = Arc::clone(&self.data_source); + let projected_schema = Arc::clone(&self.projected_schema); let session = self.session.clone(); let num_partitions = self.num_partitions; @@ -318,7 +318,7 @@ impl DataSource for VortexDataSource { .try_flatten_unordered(Some(num_partitions.get() * 2)) .map(move |result| { let session = session.clone(); - let schema = projected_schema.clone(); + let schema = Arc::clone(&projected_schema); handle.spawn_cpu(move || { let mut ctx = session.create_execution_ctx(); result.and_then(|chunk| chunk.execute_record_batch(&schema, &mut ctx)) @@ -343,7 +343,7 @@ impl DataSource for VortexDataSource { .try_flatten(); Ok(Box::pin(RecordBatchStreamAdapter::new( - self.leftover_schema.clone(), + Arc::clone(&self.leftover_schema), stream, ))) } @@ -386,7 +386,7 @@ impl DataSource for VortexDataSource { } fn eq_properties(&self) -> EquivalenceProperties { - EquivalenceProperties::new(self.leftover_schema.clone()) + EquivalenceProperties::new(Arc::clone(&self.leftover_schema)) } fn partition_statistics(&self, _partition: Option) -> DFResult { @@ -467,11 +467,11 @@ impl DataSource for VortexDataSource { let mut this = self.clone(); this.projected_projection = scan_projection; - this.projected_schema = scan_output_schema.clone(); + this.projected_schema = Arc::clone(&scan_output_schema); this.projected_statistics = vec![ColumnStatistics::new_unknown(); scan_output_schema.fields().len()]; this.leftover_projection = Some(leftover_projection); - this.leftover_schema = final_schema.clone(); + this.leftover_schema = Arc::clone(&final_schema); this.leftover_statistics = vec![ColumnStatistics::new_unknown(); final_schema.fields().len()]; @@ -517,7 +517,7 @@ impl DataSource for VortexDataSource { .iter() .zip(pushdown_results.iter()) .filter_map(|(expr, pushed)| match pushed { - PushedDown::Yes => Some(expr.clone()), + PushedDown::Yes => Some(Arc::clone(&expr)), PushedDown::No => None, }) .collect(); diff --git a/vortex-datafusion/src/v2/table.rs b/vortex-datafusion/src/v2/table.rs index 410162b639a..ccf654577bb 100644 --- a/vortex-datafusion/src/v2/table.rs +++ b/vortex-datafusion/src/v2/table.rs @@ -66,7 +66,7 @@ impl TableProvider for VortexTable { } fn schema(&self) -> SchemaRef { - self.arrow_schema.clone() + Arc::clone(&self.arrow_schema) } fn table_type(&self) -> TableType { @@ -81,8 +81,8 @@ impl TableProvider for VortexTable { _limit: Option, ) -> DFResult> { // Construct the physical node representing this table. - let data_source = VortexDataSource::builder(self.data_source.clone(), self.session.clone()) - .with_arrow_schema(self.arrow_schema.clone()) + let data_source = VortexDataSource::builder(Arc::clone(&self.data_source), self.session.clone()) + .with_arrow_schema(Arc::clone(&self.arrow_schema)) // We push down the projection now since it can make building the physical plan a lot // cheaper, e.g. by only computing stats for the projected columns. .with_some_projection(projection.cloned()) diff --git a/vortex-duckdb/src/datasource.rs b/vortex-duckdb/src/datasource.rs index d28211f7e91..aa6aa4c4cee 100644 --- a/vortex-duckdb/src/datasource.rs +++ b/vortex-duckdb/src/datasource.rs @@ -110,7 +110,7 @@ pub struct DataSourceBindData { impl Clone for DataSourceBindData { fn clone(&self) -> Self { Self { - data_source: self.data_source.clone(), + data_source: Arc::clone(&self.data_source), // filter_exprs are consumed once in `init_global`. filter_exprs: vec![], column_names: self.column_names.clone(), @@ -264,7 +264,7 @@ impl TableFunction for T { } }; while let Some(item) = stream.next().await { - if tx.send(item.map(|a| (a, cache.clone()))).await.is_err() { + if tx.send(item.map(|a| (a, Arc::clone(&cache)))).await.is_err() { // Exit early if the receiver has been dropped, which happens when the // scan is complete or if an error has occurred in another partition. return; diff --git a/vortex-duckdb/src/duckdb/file_system.rs b/vortex-duckdb/src/duckdb/file_system.rs index a052ecb8ff7..a3c76af633d 100644 --- a/vortex-duckdb/src/duckdb/file_system.rs +++ b/vortex-duckdb/src/duckdb/file_system.rs @@ -114,7 +114,7 @@ impl VortexWrite for DuckDbFsWriter { async fn write_all(&mut self, buffer: B) -> std::io::Result { let len = buffer.bytes_init(); let offset = self.pos; - let handle = self.handle.clone(); + let handle = Arc::clone(&self.handle); let runtime = RUNTIME.handle(); let buffer = runtime @@ -145,7 +145,7 @@ impl VortexWrite for DuckDbFsWriter { } async fn flush(&mut self) -> std::io::Result<()> { - let handle = self.handle.clone(); + let handle = Arc::clone(&self.handle); let runtime = RUNTIME.handle(); runtime diff --git a/vortex-duckdb/src/exporter/dict.rs b/vortex-duckdb/src/exporter/dict.rs index 4e63ad59de2..6a156c49f22 100644 --- a/vortex-duckdb/src/exporter/dict.rs +++ b/vortex-duckdb/src/exporter/dict.rs @@ -66,7 +66,7 @@ pub(crate) fn new_exporter_with_flatten( } let values_key = Arc::as_ptr(values).addr(); - let codes = array.codes().clone().execute::(ctx)?; + let codes = Arc::clone(&array.codes()).execute::(ctx)?; let reusable_dict = if flatten { let canonical = cache @@ -79,12 +79,12 @@ pub(crate) fn new_exporter_with_flatten( let canonical = values.to_canonical()?; cache .canonical_cache - .insert(values_key, (values.clone(), canonical.clone())); + .insert(values_key, (Arc::clone(&values), canonical.clone())); canonical } }; return new_array_exporter( - DictArray::new(array.codes().clone(), canonical.into_array()) + DictArray::new(Arc::clone(&array.codes()), canonical.into_array()) .into_array() .execute::(ctx)? .into_array(), @@ -103,7 +103,7 @@ pub(crate) fn new_exporter_with_flatten( None => { // Create a new reusable dictionary for the values. let mut reusable_dict = ReusableDict::new(values.dtype().try_into()?, values.len()); - new_array_exporter(values.clone(), cache, ctx)?.export( + new_array_exporter(Arc::clone(&values), cache, ctx)?.export( 0, values.len(), reusable_dict.vector(), @@ -112,7 +112,7 @@ pub(crate) fn new_exporter_with_flatten( cache .dict_cache - .insert(values_key, (values.clone(), reusable_dict.clone())); + .insert(values_key, (Arc::clone(&values), reusable_dict.clone())); reusable_dict } diff --git a/vortex-duckdb/src/exporter/list.rs b/vortex-duckdb/src/exporter/list.rs index 9020bcf1659..3d6427577a8 100644 --- a/vortex-duckdb/src/exporter/list.rs +++ b/vortex-duckdb/src/exporter/list.rs @@ -65,7 +65,7 @@ pub(crate) fn new_exporter( let cached_elements = cache .values_cache .get(&values_key) - .map(|entry| entry.value().1.clone()); + .map(|entry| Arc::clone(&entry.value().1)); let shared_elements = match cached_elements { Some(elements) => elements, @@ -74,7 +74,7 @@ pub(crate) fn new_exporter( let elements_type: LogicalType = elements.dtype().try_into()?; let mut duckdb_elements = Vector::with_capacity(&elements_type, num_elements); let elements_exporter = - new_array_exporter_with_flatten(elements.clone(), cache, ctx, true)?; + new_array_exporter_with_flatten(Arc::clone(&elements), cache, ctx, true)?; if num_elements != 0 { elements_exporter.export(0, num_elements, &mut duckdb_elements, ctx)?; @@ -83,7 +83,7 @@ pub(crate) fn new_exporter( let shared_elements = Arc::new(Mutex::new(duckdb_elements)); cache .values_cache - .insert(values_key, (elements, shared_elements.clone())); + .insert(values_key, (elements, Arc::clone(&shared_elements))); shared_elements } diff --git a/vortex-duckdb/src/exporter/list_view.rs b/vortex-duckdb/src/exporter/list_view.rs index 2db8229f764..e4bdf7e061e 100644 --- a/vortex-duckdb/src/exporter/list_view.rs +++ b/vortex-duckdb/src/exporter/list_view.rs @@ -70,7 +70,7 @@ pub(crate) fn new_exporter( let cached_elements = cache .values_cache .get(&values_key) - .map(|entry| entry.value().1.clone()); + .map(|entry| Arc::clone(&entry.value().1)); let shared_elements = match cached_elements { Some(elements) => elements, @@ -79,7 +79,7 @@ pub(crate) fn new_exporter( let elements_type: LogicalType = elements_dtype.as_ref().try_into()?; let mut duckdb_elements = Vector::with_capacity(&elements_type, elements.len()); let elements_exporter = - new_array_exporter_with_flatten(elements.clone(), cache, ctx, true)?; + new_array_exporter_with_flatten(Arc::clone(&elements), cache, ctx, true)?; if !elements.is_empty() { elements_exporter.export(0, elements.len(), &mut duckdb_elements, ctx)?; @@ -88,14 +88,14 @@ pub(crate) fn new_exporter( let shared_elements = Arc::new(Mutex::new(duckdb_elements)); cache .values_cache - .insert(values_key, (elements.clone(), shared_elements.clone())); + .insert(values_key, (Arc::clone(&elements), Arc::clone(&shared_elements))); shared_elements } }; let offsets = offsets.execute::(ctx)?; - let sizes = sizes.clone().execute::(ctx)?; + let sizes = Arc::clone(&sizes).execute::(ctx)?; let boxed = match_each_integer_ptype!(offsets.ptype(), |O| { match_each_integer_ptype!(sizes.ptype(), |S| { diff --git a/vortex-duckdb/src/exporter/mod.rs b/vortex-duckdb/src/exporter/mod.rs index 97fd0edf861..430ea783d54 100644 --- a/vortex-duckdb/src/exporter/mod.rs +++ b/vortex-duckdb/src/exporter/mod.rs @@ -40,6 +40,7 @@ use crate::duckdb::DataChunkRef; use crate::duckdb::LogicalType; use crate::duckdb::VectorRef; use crate::duckdb::duckdb_vector_size; +use std::sync::Arc; pub struct ArrayExporter { ctx: ExecutionCtx, @@ -61,7 +62,7 @@ impl ArrayExporter { let fields = array .iter_unmasked_fields() - .map(|field| new_array_exporter(field.clone(), cache, &mut ctx)) + .map(|field| new_array_exporter(Arc::clone(&field), cache, &mut ctx)) .collect::>>()?; Ok(Self { diff --git a/vortex-duckdb/src/exporter/run_end.rs b/vortex-duckdb/src/exporter/run_end.rs index 2a27af64940..3fb9ffb0313 100644 --- a/vortex-duckdb/src/exporter/run_end.rs +++ b/vortex-duckdb/src/exporter/run_end.rs @@ -21,6 +21,7 @@ use crate::duckdb::VectorRef; use crate::exporter::ColumnExporter; use crate::exporter::cache::ConversionCache; use crate::exporter::new_array_exporter; +use std::sync::Arc; /// We export run-end arrays to a DuckDB dictionary vector, using a selection vector to /// repeat the values in the run-end array. @@ -40,7 +41,7 @@ pub(crate) fn new_exporter( let offset = array.offset(); let RunEndArrayParts { ends, values } = array.into_parts(); let ends = ends.execute::(ctx)?; - let values_exporter = new_array_exporter(values.clone(), cache, ctx)?; + let values_exporter = new_array_exporter(Arc::clone(&values), cache, ctx)?; match_each_integer_ptype!(ends.ptype(), |E| { Ok(Box::new(RunEndExporter { diff --git a/vortex-duckdb/src/exporter/struct_.rs b/vortex-duckdb/src/exporter/struct_.rs index 3da11caff64..3bebe2cd83e 100644 --- a/vortex-duckdb/src/exporter/struct_.rs +++ b/vortex-duckdb/src/exporter/struct_.rs @@ -16,6 +16,7 @@ use crate::exporter::ConversionCache; use crate::exporter::all_invalid; use crate::exporter::new_array_exporter; use crate::exporter::validity; +use std::sync::Arc; struct StructExporter { children: Vec>, @@ -46,12 +47,12 @@ pub(crate) fn new_exporter( if validity.to_bit_buffer().true_count() != validity.len() { // TODO(joe): use new mask. new_array_exporter( - child.clone().mask(validity.clone().into_array())?, + Arc::clone(&child).mask(validity.clone().into_array())?, cache, ctx, ) } else { - new_array_exporter(child.clone().into_array(), cache, ctx) + new_array_exporter(Arc::clone(&child).into_array(), cache, ctx) } }) .collect::>>()?; diff --git a/vortex-duckdb/src/filesystem.rs b/vortex-duckdb/src/filesystem.rs index 5e11c341114..e6d5c7c9750 100644 --- a/vortex-duckdb/src/filesystem.rs +++ b/vortex-duckdb/src/filesystem.rs @@ -261,8 +261,8 @@ impl VortexReadAt for DuckDbFsReader { } fn size(&self) -> BoxFuture<'static, VortexResult> { - let handle = self.handle.clone(); - let size_cell = self.size.clone(); + let handle = Arc::clone(&self.handle); + let size_cell = Arc::clone(&self.size); async move { if let Some(size) = size_cell.get() { @@ -296,7 +296,7 @@ impl VortexReadAt for DuckDbFsReader { length: usize, alignment: Alignment, ) -> BoxFuture<'static, VortexResult> { - let handle = self.handle.clone(); + let handle = Arc::clone(&self.handle); async move { let runtime = RUNTIME.handle(); diff --git a/vortex-ffi/src/array.rs b/vortex-ffi/src/array.rs index 32e9099f8a6..d708e5a7061 100644 --- a/vortex-ffi/src/array.rs +++ b/vortex-ffi/src/array.rs @@ -132,7 +132,7 @@ impl From<&vx_validity> for Validity { vx_validity_type::VX_VALIDITY_ALL_VALID => Validity::AllValid, vx_validity_type::VX_VALIDITY_ALL_INVALID => Validity::AllInvalid, vx_validity_type::VX_VALIDITY_ARRAY => { - Validity::Array(vx_array::as_ref(validity.array).clone()) + Validity::Array(Arc::clone(&vx_array::as_ref(validity.array))) } } } diff --git a/vortex-ffi/src/dtype.rs b/vortex-ffi/src/dtype.rs index 42291d47743..d11fca43115 100644 --- a/vortex-ffi/src/dtype.rs +++ b/vortex-ffi/src/dtype.rs @@ -318,7 +318,7 @@ pub unsafe extern "C-unwind" fn vx_dtype_time_zone(dtype: *const DType) -> *cons }; match opts.tz.as_ref() { - Some(zone) => vx_string::new(zone.clone()), + Some(zone) => vx_string::new(Arc::clone(&zone)), None => ptr::null(), } } diff --git a/vortex-ffi/src/sink.rs b/vortex-ffi/src/sink.rs index 619d1c760c3..ad3dbefc80d 100644 --- a/vortex-ffi/src/sink.rs +++ b/vortex-ffi/src/sink.rs @@ -94,7 +94,7 @@ pub unsafe extern "C-unwind" fn vx_array_sink_push( let array = vx_array::as_ref(array); let sink = unsafe { &mut *sink }; RUNTIME - .block_on(sink.sink.send(Ok(array.clone()))) + .block_on(sink.sink.send(Ok(Arc::clone(&array)))) .map_err(|e| vortex_err!("Send error: {e}")) }) } diff --git a/vortex-file/src/counting.rs b/vortex-file/src/counting.rs index 6eaa8f07d16..78f8a8741a9 100644 --- a/vortex-file/src/counting.rs +++ b/vortex-file/src/counting.rs @@ -24,7 +24,7 @@ impl CountingVortexWrite { } pub fn counter(&self) -> Arc { - self.bytes_written.clone() + Arc::clone(&self.bytes_written) } } diff --git a/vortex-file/src/file.rs b/vortex-file/src/file.rs index b4a1865b014..7257676b05c 100644 --- a/vortex-file/src/file.rs +++ b/vortex-file/src/file.rs @@ -78,7 +78,7 @@ impl VortexFile { /// This may spawn a background I/O driver that will exit when the returned segment source /// is dropped. pub fn segment_source(&self) -> Arc { - self.segment_source.clone() + Arc::clone(&self.segment_source) } /// Create a new layout reader for the file. diff --git a/vortex-file/src/footer/serializer.rs b/vortex-file/src/footer/serializer.rs index 493d10871a8..5fd973b6b4a 100644 --- a/vortex-file/src/footer/serializer.rs +++ b/vortex-file/src/footer/serializer.rs @@ -20,6 +20,7 @@ use crate::VERSION; use crate::footer::file_layout::FooterFlatBufferWriter; use crate::footer::postscript::Postscript; use crate::footer::postscript::PostscriptSegment; +use std::sync::Arc; pub struct FooterSerializer { footer: Footer, @@ -97,7 +98,7 @@ impl FooterSerializer { &FooterFlatBufferWriter { ctx: self.footer.array_read_ctx.clone(), layout_ctx: ReadContext::new(layout_ctx.to_ids()), - segment_specs: self.footer.segments.clone(), + segment_specs: Arc::clone(&self.footer.segments), }, )?; buffers.push(buffer); diff --git a/vortex-file/src/multi/mod.rs b/vortex-file/src/multi/mod.rs index d701bda5e27..2e0c3735499 100644 --- a/vortex-file/src/multi/mod.rs +++ b/vortex-file/src/multi/mod.rs @@ -127,10 +127,10 @@ impl MultiFileDataSource { .iter() .map(|f| { Arc::new(VortexFileReaderFactory { - fs: fs.clone(), + fs: Arc::clone(&fs), file: f.clone(), session: self.session.clone(), - open_options_fn: self.open_options_fn.clone(), + open_options_fn: Arc::clone(&self.open_options_fn), }) as Arc }) .collect(); diff --git a/vortex-file/src/open.rs b/vortex-file/src/open.rs index ac8fdd83097..74e65f9f087 100644 --- a/vortex-file/src/open.rs +++ b/vortex-file/src/open.rs @@ -184,7 +184,7 @@ impl VortexOpenOptions { let segment_source = Arc::new(BufferSegmentSource::new( buffer, - footer.segment_map().clone(), + Arc::clone(&footer.segment_map()), )); Ok(VortexFile { @@ -225,7 +225,7 @@ impl VortexOpenOptions { // Create a segment source backed by the VortexRead implementation. let segment_source = Arc::new(SharedSegmentSource::new(FileSegmentSource::open( - footer.segment_map().clone(), + Arc::clone(&footer.segment_map()), reader, self.session.handle(), metrics, @@ -330,7 +330,7 @@ impl VortexOpenOptions { let handle = self.session.handle(); let source = Arc::new(ObjectStoreReadAt::new( - object_store.clone(), + Arc::clone(&object_store), path.into(), handle, )); @@ -429,8 +429,8 @@ mod tests { let first_read_len = Arc::new(AtomicUsize::new(0)); let reader = CountingRead { inner: buffer, - total_read: total_read.clone(), - first_read_len: first_read_len.clone(), + total_read: Arc::clone(&total_read), + first_read_len: Arc::clone(&first_read_len), }; // Open the file diff --git a/vortex-file/src/read/request.rs b/vortex-file/src/read/request.rs index cdd71670070..7caaa08d3d8 100644 --- a/vortex-file/src/read/request.rs +++ b/vortex-file/src/read/request.rs @@ -140,7 +140,7 @@ impl CoalescedRequest { Err(e) => { let e = Arc::new(e); for req in self.requests.into_iter() { - req.resolve(Err(VortexError::from(e.clone()))); + req.resolve(Err(VortexError::from(Arc::clone(&e)))); } return; } @@ -163,7 +163,7 @@ impl CoalescedRequest { Err(e) => { let e = Arc::new(e); for req in self.requests.into_iter() { - req.resolve(Err(VortexError::from(e.clone()))); + req.resolve(Err(VortexError::from(Arc::clone(&e)))); } } } diff --git a/vortex-file/src/strategy.rs b/vortex-file/src/strategy.rs index efd693c5ca1..67d1baf9de1 100644 --- a/vortex-file/src/strategy.rs +++ b/vortex-file/src/strategy.rs @@ -251,12 +251,12 @@ impl WriteStrategyBuilder { }; // 7. for each chunk create a flat layout - let chunked = ChunkedLayoutStrategy::new(flat.clone()); + let chunked = ChunkedLayoutStrategy::new(Arc::clone(&flat)); // 6. buffer chunks so they end up with closer segment ids physically let buffered = BufferedStrategy::new(chunked, 2 * ONE_MEG); // 2MB // 5. compress each chunk let compressing = if let Some(ref compressor) = self.compressor { - CompressingStrategy::new_opaque(buffered, compressor.clone()) + CompressingStrategy::new_opaque(buffered, Arc::clone(&compressor)) } else { CompressingStrategy::new_btrblocks(buffered, true) }; @@ -280,7 +280,7 @@ impl WriteStrategyBuilder { // 2.1. | 3.1. compress stats tables and dict values. let compress_then_flat = if let Some(ref compressor) = self.compressor { - CompressingStrategy::new_opaque(flat, compressor.clone()) + CompressingStrategy::new_opaque(flat, Arc::clone(&compressor)) } else { CompressingStrategy::new_btrblocks(flat, false) }; diff --git a/vortex-file/src/tests.rs b/vortex-file/src/tests.rs index 5a7d93ec99c..cebcd34afb2 100644 --- a/vortex-file/src/tests.rs +++ b/vortex-file/src/tests.rs @@ -304,7 +304,7 @@ async fn test_read_projection() { ) ); - let actual = array.to_struct().unmasked_field(0).clone(); + let actual = Arc::clone(&array.to_struct().unmasked_field(0)); let expected = VarBinArray::from(strings_expected.to_vec()).into_array(); assert_arrays_eq!(actual.as_ref(), expected.as_ref()); @@ -326,7 +326,7 @@ async fn test_read_projection() { ) ); - let actual = array.to_struct().unmasked_field(0).clone(); + let actual = Arc::clone(&array.to_struct().unmasked_field(0)); let expected = Buffer::copy_from(numbers_expected).into_array(); assert_arrays_eq!(actual.as_ref(), expected.as_ref()); } @@ -538,13 +538,13 @@ async fn filter_string() { .unwrap(); assert_eq!(result.len(), 1); - let names_actual = result[0].to_struct().unmasked_field(0).clone(); + let names_actual = Arc::clone(&result[0].to_struct().unmasked_field(0)); let names_expected = VarBinArray::from_iter(vec![Some("Joseph")], DType::Utf8(Nullability::Nullable)) .into_array(); assert_arrays_eq!(names_actual.as_ref(), names_expected.as_ref()); - let ages_actual = result[0].to_struct().unmasked_field(1).clone(); + let ages_actual = Arc::clone(&result[0].to_struct().unmasked_field(1)); let ages_expected = PrimitiveArray::from_option_iter([Some(25i32)]).into_array(); assert_arrays_eq!(ages_actual.as_ref(), ages_expected.as_ref()); } @@ -593,7 +593,7 @@ async fn filter_or() { .unwrap(); assert_eq!(result.len(), 1); - let names_actual = result[0].to_struct().unmasked_field(0).clone(); + let names_actual = Arc::clone(&result[0].to_struct().unmasked_field(0)); let names_expected = VarBinArray::from_iter( vec![Some("Joseph"), Some("Angela")], DType::Utf8(Nullability::Nullable), @@ -601,7 +601,7 @@ async fn filter_or() { .into_array(); assert_arrays_eq!(names_actual.as_ref(), names_expected.as_ref()); - let ages_actual = result[0].to_struct().unmasked_field(1).clone(); + let ages_actual = Arc::clone(&result[0].to_struct().unmasked_field(1)); let ages_expected = PrimitiveArray::from_option_iter([Some(25i32), None]).into_array(); assert_arrays_eq!(ages_actual.as_ref(), ages_expected.as_ref()); } @@ -647,7 +647,7 @@ async fn filter_and() { .unwrap(); assert_eq!(result.len(), 1); - let names_actual = result[0].to_struct().unmasked_field(0).clone(); + let names_actual = Arc::clone(&result[0].to_struct().unmasked_field(0)); let names_expected = VarBinArray::from_iter( vec![Some("Joseph"), None], DType::Utf8(Nullability::Nullable), @@ -655,7 +655,7 @@ async fn filter_and() { .into_array(); assert_arrays_eq!(names_actual.as_ref(), names_expected.as_ref()); - let ages_actual = result[0].to_struct().unmasked_field(1).clone(); + let ages_actual = Arc::clone(&result[0].to_struct().unmasked_field(1)); let ages_expected = PrimitiveArray::from_option_iter([Some(25i32), Some(31i32)]).into_array(); assert_arrays_eq!(ages_actual.as_ref(), ages_expected.as_ref()); } @@ -733,7 +733,7 @@ async fn test_with_indices_simple() { .await .unwrap() .to_struct(); - let actual_numbers_array = actual_array.unmasked_field(0).clone(); + let actual_numbers_array = Arc::clone(&actual_array.unmasked_field(0)); let expected_array = Buffer::copy_from(&expected_numbers).into_array(); assert_arrays_eq!(actual_numbers_array.as_ref(), expected_array.as_ref()); } @@ -778,7 +778,7 @@ async fn test_with_indices_on_two_columns() { .to_struct() .to_struct(); - let strings_actual = array.unmasked_field(0).clone(); + let strings_actual = Arc::clone(&array.unmasked_field(0)); let strings_expected_vec: Vec<&str> = kept_indices .iter() .map(|&x| strings_expected[x as usize]) @@ -786,7 +786,7 @@ async fn test_with_indices_on_two_columns() { let strings_expected_array = VarBinArray::from(strings_expected_vec).into_array(); assert_arrays_eq!(strings_actual.as_ref(), strings_expected_array.as_ref()); - let numbers_actual = array.unmasked_field(1).clone(); + let numbers_actual = Arc::clone(&array.unmasked_field(1)); let numbers_expected_vec: Vec = kept_indices .iter() .map(|&x| numbers_expected[x as usize]) @@ -873,7 +873,7 @@ async fn test_with_indices_and_with_row_filter_simple() { .unwrap() .to_struct(); - let actual_numbers_array = actual_array.unmasked_field(0).clone(); + let actual_numbers_array = Arc::clone(&actual_array.unmasked_field(0)); let expected_filtered: Buffer = expected_numbers .iter() .filter(|&&x| x > 50) @@ -936,13 +936,13 @@ async fn filter_string_chunked() { .to_struct(); assert_eq!(actual_array.len(), 1); - let names_actual = actual_array.unmasked_field(0).clone(); + let names_actual = Arc::clone(&actual_array.unmasked_field(0)); let names_expected = VarBinArray::from_iter(vec![Some("Joseph")], DType::Utf8(Nullability::Nullable)) .into_array(); assert_arrays_eq!(names_actual.as_ref(), names_expected.as_ref()); - let ages_actual = actual_array.unmasked_field(1).clone(); + let ages_actual = Arc::clone(&actual_array.unmasked_field(1)); let ages_expected = PrimitiveArray::from_option_iter([Some(25i32)]).into_array(); assert_arrays_eq!(ages_actual.as_ref(), ages_expected.as_ref()); } @@ -1027,7 +1027,7 @@ async fn test_pruning_with_or() { .to_struct(); assert_eq!(actual_array.len(), 10); - let letters_actual = actual_array.unmasked_field(0).clone(); + let letters_actual = Arc::clone(&actual_array.unmasked_field(0)); let letters_expected = VarBinViewArray::from_iter_nullable_str([ Some("A".to_owned()), Some("B".to_owned()), @@ -1043,7 +1043,7 @@ async fn test_pruning_with_or() { .into_array(); assert_arrays_eq!(letters_actual.as_ref(), letters_expected.as_ref()); - let numbers_actual = actual_array.unmasked_field(1).clone(); + let numbers_actual = Arc::clone(&actual_array.unmasked_field(1)); let numbers_expected = PrimitiveArray::from_option_iter([ Some(25_i32), Some(31), @@ -1068,11 +1068,11 @@ async fn test_repeated_projection() { ]) .into_array(); - let single_column_array = StructArray::from_fields(&[("strings", strings.clone())]) + let single_column_array = StructArray::from_fields(&[("strings", Arc::clone(&strings))]) .unwrap() .into_array(); - let expected = StructArray::from_fields(&[("strings", strings.clone()), ("strings", strings)]) + let expected = StructArray::from_fields(&[("strings", Arc::clone(&strings)), ("strings", strings)]) .unwrap() .into_array(); @@ -1341,7 +1341,7 @@ async fn test_writer_basic_push() -> VortexResult<()> { let mut buf = ByteBufferMut::empty(); let mut writer = SESSION.write_options().writer(&mut buf, dtype.clone()); - writer.push(st.clone()).await?; + writer.push(Arc::clone(&st)).await?; let summary = writer.finish().await?; assert_eq!(summary.row_count(), 4); @@ -1435,7 +1435,7 @@ async fn test_writer_bytes_written() -> VortexResult<()> { assert_eq!(writer.bytes_written(), 0); - writer.push(array.clone()).await?; + writer.push(Arc::clone(&array)).await?; writer.push(array).await?; let bytes_after_push = writer.bytes_written(); @@ -1467,7 +1467,7 @@ async fn test_writer_empty_chunks() -> VortexResult<()> { let mut buf = ByteBufferMut::empty(); let mut writer = SESSION.write_options().writer(&mut buf, dtype.clone()); - writer.push(empty.clone()).await?; + writer.push(Arc::clone(&empty)).await?; writer.push(non_empty).await?; writer.push(empty).await?; @@ -1499,7 +1499,7 @@ async fn test_writer_mixed_push_and_stream() -> VortexResult<()> { let dtype = chunk1.dtype().clone(); - let stream = futures::stream::iter(vec![Ok(chunk2.clone())]); + let stream = futures::stream::iter(vec![Ok(Arc::clone(&chunk2))]); let sendable_stream = ArrayStreamExt::boxed(ArrayStreamAdapter::new(dtype.clone(), stream)); let mut buf = ByteBufferMut::empty(); diff --git a/vortex-file/src/v2/file_stats_reader.rs b/vortex-file/src/v2/file_stats_reader.rs index f8de172fea9..f8b721d2e9c 100644 --- a/vortex-file/src/v2/file_stats_reader.rs +++ b/vortex-file/src/v2/file_stats_reader.rs @@ -265,7 +265,7 @@ mod tests { let layout = strategy .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), struct_array.into_array().to_array_stream().sequenced(ptr), eof, handle, @@ -303,7 +303,7 @@ mod tests { let layout = strategy .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), struct_array.into_array().to_array_stream().sequenced(ptr), eof, handle, diff --git a/vortex-file/src/writer.rs b/vortex-file/src/writer.rs index ef91dc701c0..0172eacd7a3 100644 --- a/vortex-file/src/writer.rs +++ b/vortex-file/src/writer.rs @@ -182,7 +182,7 @@ impl VortexWriteOptions { let layout_fut = self.session.handle().spawn_nested(|h| async move { let layout = self .strategy - .write_stream(ctx2, segments.clone(), stream, eof, h) + .write_stream(ctx2, Arc::clone(&segments), stream, eof, h) .await?; Ok::<_, VortexError>((layout, segments.segment_specs())) }); @@ -202,7 +202,7 @@ impl VortexWriteOptions { // Assemble the Footer object now that we have all the segments. let mut footer = Footer::new( - layout.clone(), + Arc::clone(&layout), segment_specs, if self.file_statistics.is_empty() { None @@ -250,7 +250,7 @@ impl VortexWriteOptions { let write = CountingVortexWrite::new(write); let bytes_written = write.counter(); - let strategy = self.strategy.clone(); + let strategy = Arc::clone(&self.strategy); let future = self.write(write, arrays).boxed_local().fuse(); Writer { diff --git a/vortex-file/tests/test_write_table.rs b/vortex-file/tests/test_write_table.rs index 5b27f6e9026..dee7b3d93f0 100644 --- a/vortex-file/tests/test_write_table.rs +++ b/vortex-file/tests/test_write_table.rs @@ -49,7 +49,7 @@ async fn test_file_roundtrip() { let a_array = StructArray::new( FieldNames::from(["raw", "compressed"]), - vec![nums.clone(), nums.clone()], + vec![Arc::clone(&nums), Arc::clone(&nums)], 16_384, Validity::NonNullable, ) diff --git a/vortex-io/src/object_store/filesystem.rs b/vortex-io/src/object_store/filesystem.rs index 4a328725a40..6fdbc23caa3 100644 --- a/vortex-io/src/object_store/filesystem.rs +++ b/vortex-io/src/object_store/filesystem.rs @@ -76,7 +76,7 @@ impl FileSystem for ObjectStoreFileSystem { async fn open_read(&self, path: &str) -> VortexResult> { Ok(Arc::new(ObjectStoreReadAt::new( - self.store.clone(), + Arc::clone(&self.store), path.into(), self.handle.clone(), ))) diff --git a/vortex-io/src/object_store/read_at.rs b/vortex-io/src/object_store/read_at.rs index a4957199565..727b792571b 100644 --- a/vortex-io/src/object_store/read_at.rs +++ b/vortex-io/src/object_store/read_at.rs @@ -80,7 +80,7 @@ impl VortexReadAt for ObjectStoreReadAt { } fn size(&self) -> BoxFuture<'static, VortexResult> { - let store = self.store.clone(); + let store = Arc::clone(&self.store); let path = self.path.clone(); async move { store @@ -98,7 +98,7 @@ impl VortexReadAt for ObjectStoreReadAt { length: usize, alignment: Alignment, ) -> BoxFuture<'static, VortexResult> { - let store = self.store.clone(); + let store = Arc::clone(&self.store); let path = self.path.clone(); let handle = self.handle.clone(); let range = offset..(offset + length as u64); diff --git a/vortex-io/src/object_store/write.rs b/vortex-io/src/object_store/write.rs index 988fd1473ac..3cb73cec331 100644 --- a/vortex-io/src/object_store/write.rs +++ b/vortex-io/src/object_store/write.rs @@ -129,7 +129,7 @@ mod tests { let location = Path::from("test.bin"); for test_store in [memory_store, local_store] { - let mut writer = ObjectStoreWrite::new(test_store.clone(), &location).await?; + let mut writer = ObjectStoreWrite::new(Arc::clone(&test_store), &location).await?; #[expect(clippy::cast_possible_truncation)] let data = (0..3) diff --git a/vortex-io/src/runtime/current.rs b/vortex-io/src/runtime/current.rs index 1d2eda71487..f46fc2059a2 100644 --- a/vortex-io/src/runtime/current.rs +++ b/vortex-io/src/runtime/current.rs @@ -45,7 +45,7 @@ impl CurrentThreadRuntime { /// By default, the pool has no worker threads; the caller must set the desired number of /// worker threads using the `set_workers` method on the returned pool. pub fn new_pool(&self) -> CurrentThreadWorkerPool { - CurrentThreadWorkerPool::new(self.executor.clone()) + CurrentThreadWorkerPool::new(Arc::clone(&self.executor)) } /// Returns an iterator wrapper around a stream, blocking the current thread for each item. @@ -81,7 +81,7 @@ impl CurrentThreadRuntime { .detach(); ThreadSafeIterator { - executor: self.executor.clone(), + executor: Arc::clone(&self.executor), results: result_rx, } } @@ -91,7 +91,7 @@ impl BlockingRuntime for CurrentThreadRuntime { type BlockingIterator<'a, R: 'a> = CurrentThreadIterator<'a, R>; fn handle(&self) -> Handle { - let executor: Arc = self.executor.clone(); + let executor: Arc = Arc::clone(&self.executor); Handle::new(Arc::downgrade(&executor)) } @@ -108,7 +108,7 @@ impl BlockingRuntime for CurrentThreadRuntime { R: Send + 'a, { CurrentThreadIterator { - executor: self.executor.clone(), + executor: Arc::clone(&self.executor), stream: stream.boxed(), } } @@ -138,7 +138,7 @@ pub struct ThreadSafeIterator { impl Clone for ThreadSafeIterator { fn clone(&self) -> Self { Self { - executor: self.executor.clone(), + executor: Arc::clone(&self.executor), results: self.results.clone(), } } @@ -174,7 +174,7 @@ mod tests { // We spawn a future that sets a value on a separate thread. let value = Arc::new(AtomicUsize::new(0)); - let value2 = value.clone(); + let value2 = Arc::clone(&value); runtime .handle() .spawn(async move { @@ -229,9 +229,9 @@ mod tests { let threads: Vec<_> = (0..num_threads) .map(|_| { let mut iter = iter.clone(); - let counter = counter.clone(); - let barrier = barrier.clone(); - let results = results.clone(); + let counter = Arc::clone(&counter); + let barrier = Arc::clone(&barrier); + let results = Arc::clone(&results); thread::spawn(move || { barrier.wait(); @@ -290,8 +290,8 @@ mod tests { let threads: Vec<_> = (0..num_threads) .map(|thread_id| { let iter = iter.clone(); - let collected = collected.clone(); - let barrier = barrier.clone(); + let collected = Arc::clone(&collected); + let barrier = Arc::clone(&barrier); thread::spawn(move || { barrier.wait(); @@ -346,11 +346,11 @@ mod tests { #[test] fn test_block_on_stream_drop_receivers_early() { let counter = Arc::new(AtomicUsize::new(0)); - let c = counter.clone(); + let c = Arc::clone(&counter); let mut iter = CurrentThreadRuntime::new().block_on_stream({ stream::unfold(0, move |state| { - let c = c.clone(); + let c = Arc::clone(&c); async move { (state < 100).then(|| { c.fetch_add(1, Ordering::SeqCst); @@ -382,7 +382,7 @@ mod tests { let iter1 = iter.clone(); let iter2 = iter; - let barrier1 = barrier.clone(); + let barrier1 = Arc::clone(&barrier); let barrier2 = barrier; let thread1 = thread::spawn(move || { @@ -441,8 +441,8 @@ mod tests { let threads: Vec<_> = (0..num_threads) .map(|_| { let iter = iter.clone(); - let received = received.clone(); - let barrier = barrier.clone(); + let received = Arc::clone(&received); + let barrier = Arc::clone(&barrier); thread::spawn(move || { barrier.wait(); diff --git a/vortex-io/src/runtime/handle.rs b/vortex-io/src/runtime/handle.rs index 4893c2e57e5..f04b897b29e 100644 --- a/vortex-io/src/runtime/handle.rs +++ b/vortex-io/src/runtime/handle.rs @@ -88,7 +88,7 @@ impl Handle { Fut: Future + Send + 'static, R: Send + 'static, { - self.spawn(f(Handle::new(self.runtime.clone()))) + self.spawn(f(Handle::new(Weak::clone(&self.runtime)))) } /// Spawn a CPU-bound task for execution on the runtime. diff --git a/vortex-io/src/runtime/pool.rs b/vortex-io/src/runtime/pool.rs index 962407551ec..a8d1f67a149 100644 --- a/vortex-io/src/runtime/pool.rs +++ b/vortex-io/src/runtime/pool.rs @@ -44,8 +44,8 @@ impl CurrentThreadWorkerPool { // Spawn new workers for _ in current..n { let shutdown = Arc::new(AtomicBool::new(false)); - let executor = self.executor.clone(); - let shutdown_clone = shutdown.clone(); + let executor = Arc::clone(&self.executor); + let shutdown_clone = Arc::clone(&shutdown); std::thread::Builder::new() .name("vortex-current-thread-worker".to_string()) diff --git a/vortex-io/src/runtime/single.rs b/vortex-io/src/runtime/single.rs index ea6a68f2f24..abd9af68423 100644 --- a/vortex-io/src/runtime/single.rs +++ b/vortex-io/src/runtime/single.rs @@ -18,6 +18,7 @@ use crate::runtime::BlockingRuntime; use crate::runtime::Executor; use crate::runtime::Handle; use crate::runtime::smol::SmolAbortHandle; +use std::sync::Weak; /// A runtime that drives all work on the current thread. /// @@ -53,7 +54,7 @@ impl Sender { let weak_local = Rc::downgrade(local); // Drive scheduling tasks. - let weak_local2 = weak_local.clone(); + let weak_local2 = Weak::clone(&weak_local); local .spawn(async move { while let Ok(spawn) = scheduling_recv.as_async().recv().await { @@ -70,7 +71,7 @@ impl Sender { .detach(); // Drive CPU tasks. - let weak_local2 = weak_local.clone(); + let weak_local2 = Weak::clone(&weak_local); local .spawn(async move { while let Ok(spawn) = cpu_recv.as_async().recv().await { @@ -86,7 +87,7 @@ impl Sender { .detach(); // Drive blocking tasks. - let weak_local2 = weak_local.clone(); + let weak_local2 = Weak::clone(&weak_local); local .spawn(async move { while let Ok(spawn) = blocking_recv.as_async().recv().await { @@ -158,7 +159,7 @@ impl BlockingRuntime for SingleThreadRuntime { type BlockingIterator<'a, R: 'a> = SingleThreadIterator<'a, R>; fn handle(&self) -> Handle { - let executor: Arc = self.sender.clone(); + let executor: Arc = Arc::clone(&self.sender); Handle::new(Arc::downgrade(&executor)) } @@ -175,7 +176,7 @@ impl BlockingRuntime for SingleThreadRuntime { R: Send + 'a, { SingleThreadIterator { - executor: self.executor.clone(), + executor: Rc::clone(&self.executor), stream: stream.boxed_local(), } } @@ -277,7 +278,7 @@ mod tests { #[test] fn test_spawn_cpu_task() { let counter = Arc::new(AtomicUsize::new(0)); - let c = counter.clone(); + let c = Arc::clone(&counter); block_on(|handle| async move { handle diff --git a/vortex-io/src/runtime/tests.rs b/vortex-io/src/runtime/tests.rs index 12b685b820e..8b342f4242d 100644 --- a/vortex-io/src/runtime/tests.rs +++ b/vortex-io/src/runtime/tests.rs @@ -213,7 +213,7 @@ fn test_handle_spawn_future() { async fn test_handle_spawn_cpu() { let handle = TokioRuntime::current(); let counter = Arc::new(AtomicUsize::new(0)); - let c = counter.clone(); + let c = Arc::clone(&counter); let task = handle.spawn_cpu(move || { c.fetch_add(1, Ordering::SeqCst); @@ -278,7 +278,7 @@ async fn test_custom_vortex_read() { let read_at: Arc = Arc::new(CountingReadAt { data: ByteBuffer::from(TEST_DATA.to_vec()), - read_count: read_count.clone(), + read_count: Arc::clone(&read_count), }); // Perform several reads @@ -315,7 +315,7 @@ async fn test_read_out_of_bounds() { async fn test_task_detach() { let handle = TokioRuntime::current(); let counter = Arc::new(AtomicUsize::new(0)); - let c = counter.clone(); + let c = Arc::clone(&counter); let (tx, rx) = oneshot::channel::<()>(); let task = handle.spawn(async move { diff --git a/vortex-io/src/runtime/tokio.rs b/vortex-io/src/runtime/tokio.rs index 4e386718b83..ad8dba60a01 100644 --- a/vortex-io/src/runtime/tokio.rs +++ b/vortex-io/src/runtime/tokio.rs @@ -118,7 +118,7 @@ impl BlockingRuntime for TokioRuntime { type BlockingIterator<'a, R: 'a> = TokioBlockingIterator<'a, R>; fn handle(&self) -> Handle { - let executor: Arc = self.0.clone(); + let executor: Arc = Arc::clone(&self.0); Handle::new(Arc::downgrade(&executor)) } @@ -130,7 +130,7 @@ impl BlockingRuntime for TokioRuntime { if tokio::runtime::Handle::try_current().is_ok() { vortex_error::vortex_panic!("block_on cannot be called from within a Tokio runtime"); } - let handle = self.0.clone(); + let handle = Arc::clone(&self.0); tokio::task::block_in_place(move || handle.block_on(fut)) } @@ -145,7 +145,7 @@ impl BlockingRuntime for TokioRuntime { "block_on_stream cannot be called from within a Tokio runtime" ); } - let handle = self.0.clone(); + let handle = Arc::clone(&self.0); let stream = Box::pin(stream); TokioBlockingIterator { handle, stream } } @@ -197,7 +197,7 @@ mod tests { let runtime = TokioRuntime::from(tokio_rt.handle()); let counter = Arc::new(AtomicUsize::new(0)); - let c = counter.clone(); + let c = Arc::clone(&counter); // Create a channel to ensure the future doesn't complete immediately let (send, recv) = tokio::sync::oneshot::channel::<()>(); diff --git a/vortex-io/src/std_file/read_at.rs b/vortex-io/src/std_file/read_at.rs index 13d3b3f5501..2ae60ee5d28 100644 --- a/vortex-io/src/std_file/read_at.rs +++ b/vortex-io/src/std_file/read_at.rs @@ -91,7 +91,7 @@ impl VortexReadAt for FileReadAt { } fn size(&self) -> BoxFuture<'static, VortexResult> { - let file = self.file.clone(); + let file = Arc::clone(&self.file); async move { let metadata = file.metadata()?; Ok(metadata.len()) @@ -105,7 +105,7 @@ impl VortexReadAt for FileReadAt { length: usize, alignment: Alignment, ) -> BoxFuture<'static, VortexResult> { - let file = self.file.clone(); + let file = Arc::clone(&self.file); let handle = self.handle.clone(); async move { handle diff --git a/vortex-jni/src/array.rs b/vortex-jni/src/array.rs index a727683b661..b94f1b377c2 100644 --- a/vortex-jni/src/array.rs +++ b/vortex-jni/src/array.rs @@ -39,6 +39,7 @@ use vortex::scalar::DecimalValue; use crate::errors::JNIError; use crate::errors::try_or_throw; +use std::sync::Arc; pub struct NativeArray { inner: ArrayRef, @@ -109,7 +110,7 @@ pub extern "system" fn Java_dev_vortex_jni_NativeArrayMethods_exportToArrow<'loc let preferred_arrow_type = array_ref.inner.dtype().to_arrow_dtype()?; let viewless_arrow_type = data_type_no_views(preferred_arrow_type); - let arrow_array = array_ref.inner.clone().into_arrow(&viewless_arrow_type)?; + let arrow_array = Arc::clone(&array_ref.inner).into_arrow(&viewless_arrow_type)?; let (ffi_array, ffi_schema) = arrow_array::ffi::to_ffi(&arrow_array.to_data()).map_err(VortexError::from)?; @@ -148,7 +149,7 @@ fn data_type_no_views(data_type: DataType) -> DataType { let viewless_fields: Vec = fields .iter() .map(|field_ref| { - let field = (*field_ref.clone()).clone(); + let field = (*Arc::clone(&field_ref)).clone(); let data_type = field.data_type().clone(); let field = field.with_data_type(data_type_no_views(data_type)); FieldRef::new(field) @@ -232,7 +233,7 @@ pub extern "system" fn Java_dev_vortex_jni_NativeArrayMethods_getField( if idx >= struct_array.struct_fields().nfields() { return Err(vortex_err!("Field index out of bounds").into()); } - let field = struct_array.unmasked_field(idx).clone(); + let field = Arc::clone(&struct_array.unmasked_field(idx)); Ok(NativeArray::new(field).into_raw()) }) } diff --git a/vortex-jni/src/object_store.rs b/vortex-jni/src/object_store.rs index 141e00c211f..b9f7534a509 100644 --- a/vortex-jni/src/object_store.rs +++ b/vortex-jni/src/object_store.rs @@ -40,7 +40,7 @@ pub(crate) fn make_object_store( { if let Some(cached) = OBJECT_STORES.lock().get(&cache_key) { - return Ok((cached.clone(), scheme)); + return Ok((Arc::clone(&cached), scheme)); } // guard dropped at close of scope } @@ -129,7 +129,7 @@ pub(crate) fn make_object_store( }; { - OBJECT_STORES.lock().insert(cache_key, store.clone()); + OBJECT_STORES.lock().insert(cache_key, Arc::clone(&store)); // Guard dropped at close of scope. } diff --git a/vortex-layout/src/children.rs b/vortex-layout/src/children.rs index 7871e5bf151..8560b54297b 100644 --- a/vortex-layout/src/children.rs +++ b/vortex-layout/src/children.rs @@ -43,7 +43,7 @@ impl Debug for dyn LayoutChildren { impl LayoutChildren for Arc { fn to_arc(&self) -> Arc { - self.clone() + Arc::clone(&self) } fn child(&self, idx: usize, dtype: &DType) -> VortexResult { @@ -84,7 +84,7 @@ impl LayoutChildren for OwnedLayoutChildren { if child.dtype() != dtype { vortex_bail!("Child dtype mismatch: {} != {}", child.dtype(), dtype); } - Ok(child.clone()) + Ok(Arc::clone(&child)) } fn child_row_count(&self, idx: usize) -> u64 { diff --git a/vortex-layout/src/display.rs b/vortex-layout/src/display.rs index 75d1b61d55e..4adca93565f 100644 --- a/vortex-layout/src/display.rs +++ b/vortex-layout/src/display.rs @@ -32,7 +32,7 @@ pub(super) async fn display_tree_with_segment_sizes( // Fetch segments in parallel and parse buffer info let fetch_futures = segments_to_fetch.iter().map(|&segment_id| { - let segment_source = segment_source.clone(); + let segment_source = Arc::clone(&segment_source); async move { let buffer = segment_source.request(segment_id).await?; let parts = ArrayParts::try_from(buffer)?; @@ -202,7 +202,7 @@ impl DisplayLayoutTree { impl std::fmt::Display for DisplayLayoutTree { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self.make_tree(self.layout.clone()) { + match self.make_tree(Arc::clone(&self.layout)) { Ok(tree) => write!(f, "{}", tree), Err(e) => write!(f, "Error building layout tree: {}", e), } @@ -264,7 +264,7 @@ mod tests { let layout1 = FlatLayoutStrategy::default() .write_stream( ctx.clone(), - segments.clone(), + Arc::clone(&segments), array1.to_array_stream().sequenced(ptr1), eof1, handle.clone(), @@ -287,7 +287,7 @@ mod tests { let layout2 = FlatLayoutStrategy::default() .write_stream( ctx.clone(), - segments.clone(), + Arc::clone(&segments), builder.finish().to_array_stream().sequenced(ptr2), eof2, handle.clone(), @@ -347,7 +347,7 @@ vortex.struct, dtype: {numbers=i64?, strings=utf8}, children: 2, rows: 5 let layout1 = FlatLayoutStrategy::default() .write_stream( ctx.clone(), - segments.clone(), + Arc::clone(&segments), array1.to_array_stream().sequenced(ptr1), eof1, handle.clone(), @@ -361,7 +361,7 @@ vortex.struct, dtype: {numbers=i64?, strings=utf8}, children: 2, rows: 5 let layout2 = FlatLayoutStrategy::default() .write_stream( ctx.clone(), - segments.clone(), + Arc::clone(&segments), array2.to_array_stream().sequenced(ptr2), eof2, handle.clone(), @@ -406,7 +406,7 @@ vortex.chunked, dtype: i32, children: 2, rows: 10 FlatLayoutStrategy::default() .write_stream( ctx.clone(), - segments.clone(), + Arc::clone(&segments), array.to_array_stream().sequenced(ptr), eof, handle, @@ -448,7 +448,7 @@ vortex.flat, dtype: i32?, segment 0, buffers=[20B], total=20B FlatLayoutStrategy::default() .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), array.to_array_stream().sequenced(ptr), eof, handle, diff --git a/vortex-layout/src/layout.rs b/vortex-layout/src/layout.rs index a4f9e6e0830..4f06df0ef3f 100644 --- a/vortex-layout/src/layout.rs +++ b/vortex-layout/src/layout.rs @@ -96,8 +96,8 @@ impl LayoutChildType { pub fn name(&self) -> Arc { match self { LayoutChildType::Chunk((idx, _offset)) => format!("[{idx}]").into(), - LayoutChildType::Auxiliary(name) => name.clone(), - LayoutChildType::Transparent(name) => name.clone(), + LayoutChildType::Auxiliary(name) => Arc::clone(&name), + LayoutChildType::Transparent(name) => Arc::clone(&name), LayoutChildType::Field(name) => name.clone().into(), } } @@ -463,7 +463,7 @@ mod tests { ]; for field_name in special_fields { - let field = LayoutChildType::Field(field_name.clone().into()); + let field = LayoutChildType::Field(Arc::clone(&field_name).into()); assert_eq!(field.name(), field_name); assert_eq!(field.row_offset(), Some(0)); } @@ -511,7 +511,7 @@ mod tests { ); // Create dict layout (column "name") - let dict_layout = DictLayout::new(dict_values.clone(), dict_codes.clone()).into_layout(); + let dict_layout = DictLayout::new(Arc::clone(&dict_values), Arc::clone(&dict_codes)).into_layout(); // Test dict layout display (no direct segments) assert_eq!(format!("{}", dict_layout), "vortex.dict(utf8, rows=10)"); @@ -537,7 +537,7 @@ mod tests { let chunked_layout = ChunkedLayout::new( 10, DType::Primitive(PType::I64, NonNullable), - crate::OwnedLayoutChildren::layout_children(vec![chunk1.clone(), chunk2.clone()]), + crate::OwnedLayoutChildren::layout_children(vec![Arc::clone(&chunk1), Arc::clone(&chunk2)]), ) .into_layout(); diff --git a/vortex-layout/src/layouts/buffered.rs b/vortex-layout/src/layouts/buffered.rs index dd1c432d697..6a8001fd397 100644 --- a/vortex-layout/src/layouts/buffered.rs +++ b/vortex-layout/src/layouts/buffered.rs @@ -52,7 +52,7 @@ impl LayoutStrategy for BufferedStrategy { let dtype = stream.dtype().clone(); let buffer_size = self.buffer_size; - let buffered_bytes_counter = self.buffered_bytes.clone(); + let buffered_bytes_counter = Arc::clone(&self.buffered_bytes); let buffered_stream = try_stream! { let stream = stream.peekable(); pin_mut!(stream); diff --git a/vortex-layout/src/layouts/chunked/reader.rs b/vortex-layout/src/layouts/chunked/reader.rs index 6a0c63b6eb5..01d3cd3f587 100644 --- a/vortex-layout/src/layouts/chunked/reader.rs +++ b/vortex-layout/src/layouts/chunked/reader.rs @@ -60,7 +60,7 @@ impl ChunkedReader { .map(|idx| Arc::from(format!("{name}.[{idx}]"))) .collect(); let lazy_children = LazyReaderChildren::new( - layout.children.clone(), + Arc::clone(&layout.children), dtypes, names, segment_source, @@ -227,7 +227,7 @@ impl LayoutReader for ChunkedReader { chunk_evals.push(chunk_eval); } - let name = self.name.clone(); + let name = Arc::clone(&self.name); Ok(MaskFuture::new(mask.len(), async move { tracing::debug!( "Chunked pruning evaluation {} (mask = {})", @@ -270,7 +270,7 @@ impl LayoutReader for ChunkedReader { chunk_evals.push(chunk_eval); } - let name = self.name.clone(); + let name = Arc::clone(&self.name); Ok(MaskFuture::new(mask.len(), async move { tracing::debug!("Chunked mask evaluation {}", name); @@ -366,7 +366,7 @@ mod test { let layout = block_on(|handle| { strategy.write_stream( ctx, - segments.clone(), + Arc::clone(&segments), SequentialStreamAdapter::new( DType::Primitive(PType::I32, NonNullable), stream::iter([ diff --git a/vortex-layout/src/layouts/chunked/writer.rs b/vortex-layout/src/layouts/chunked/writer.rs index 67970af124e..621159a2025 100644 --- a/vortex-layout/src/layouts/chunked/writer.rs +++ b/vortex-layout/src/layouts/chunked/writer.rs @@ -50,7 +50,7 @@ impl LayoutStrategy for ChunkedLayoutStrategy { ) -> VortexResult { let dtype = stream.dtype().clone(); let dtype2 = dtype.clone(); - let chunk_strategy = self.chunk_strategy.clone(); + let chunk_strategy = Arc::clone(&self.chunk_strategy); // We spawn each child to allow parallelism when processing chunks. let stream = stream! { @@ -58,9 +58,9 @@ impl LayoutStrategy for ChunkedLayoutStrategy { while let Some(chunk) = stream.next().await { let chunk_eof = eof.split_off(); - let chunk_strategy = chunk_strategy.clone(); + let chunk_strategy = Arc::clone(&chunk_strategy); let ctx = ctx.clone(); - let segment_sink = segment_sink.clone(); + let segment_sink = Arc::clone(&segment_sink); let dtype = dtype2.clone(); yield handle.spawn_nested(move |handle| async move { diff --git a/vortex-layout/src/layouts/compressed.rs b/vortex-layout/src/layouts/compressed.rs index 603b2360e0d..8196865e255 100644 --- a/vortex-layout/src/layouts/compressed.rs +++ b/vortex-layout/src/layouts/compressed.rs @@ -110,12 +110,12 @@ impl LayoutStrategy for CompressingStrategy { handle: Handle, ) -> VortexResult { let dtype = stream.dtype().clone(); - let compressor = self.compressor.clone(); + let compressor = Arc::clone(&self.compressor); let handle2 = handle.clone(); let stream = stream .map(move |chunk| { - let compressor = compressor.clone(); + let compressor = Arc::clone(&compressor); handle2.spawn_cpu(move || { let (sequence_id, chunk) = chunk?; // Compute the stats for the chunk prior to compression diff --git a/vortex-layout/src/layouts/dict/mod.rs b/vortex-layout/src/layouts/dict/mod.rs index 1a7dac17efe..866cf6587e9 100644 --- a/vortex-layout/src/layouts/dict/mod.rs +++ b/vortex-layout/src/layouts/dict/mod.rs @@ -73,8 +73,8 @@ impl VTable for Dict { fn child(layout: &Self::Layout, idx: usize) -> VortexResult { match idx { - 0 => Ok(layout.values.clone()), - 1 => Ok(layout.codes.clone()), + 0 => Ok(Arc::clone(&layout.values)), + 1 => Ok(Arc::clone(&layout.codes)), _ => vortex_bail!("Unreachable child index: {}", idx), } } diff --git a/vortex-layout/src/layouts/dict/reader.rs b/vortex-layout/src/layouts/dict/reader.rs index ded15f6ace0..c1d6b46fe5c 100644 --- a/vortex-layout/src/layouts/dict/reader.rs +++ b/vortex-layout/src/layouts/dict/reader.rs @@ -62,7 +62,7 @@ impl DictReader { let values_len = usize::try_from(layout.values.row_count())?; let values = layout.values.new_reader( format!("{name}.values").into(), - segment_source.clone(), + Arc::clone(&segment_source), &session, )?; let codes = @@ -318,14 +318,14 @@ mod tests { DType::Utf8(Nullability::Nullable), ) .into_array(); - let array_to_write = array.clone(); + let array_to_write = Arc::clone(&array); let ctx = ArrayContext::empty(); let segments = Arc::new(TestSegments::default()); let (ptr, eof) = SequenceId::root().split(); let layout: LayoutRef = strategy .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), SequentialStreamAdapter::new( DType::Utf8(Nullability::Nullable), array_to_write.to_array_stream().sequenced(ptr), @@ -361,7 +361,7 @@ mod tests { vec![ StructArray::try_new( FieldNames::from([FieldName::from("one"), FieldName::from("two")]), - vec![array.clone(), array], + vec![Arc::clone(&array), array], 9, Validity::NonNullable, ) @@ -409,7 +409,7 @@ mod tests { let layout: LayoutRef = strategy .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), SequentialStreamAdapter::new( DType::Utf8(Nullability::Nullable), array.to_array_stream().sequenced(ptr), @@ -465,7 +465,7 @@ mod tests { DType::Utf8(Nullability::Nullable), ) .into_array(); - let array_to_write = array.clone(); + let array_to_write = Arc::clone(&array); let ctx = ArrayContext::empty(); let segments = Arc::new(TestSegments::default()); @@ -473,7 +473,7 @@ mod tests { let layout: LayoutRef = strategy .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), SequentialStreamAdapter::new( DType::Utf8(Nullability::Nullable), array_to_write.to_array_stream().sequenced(ptr), diff --git a/vortex-layout/src/layouts/dict/writer.rs b/vortex-layout/src/layouts/dict/writer.rs index 959037d7783..6c8d897b2db 100644 --- a/vortex-layout/src/layouts/dict/writer.rs +++ b/vortex-layout/src/layouts/dict/writer.rs @@ -177,10 +177,10 @@ impl LayoutStrategy for DictStrategy { pin_mut!(runs); while let Some((codes_stream, values_fut)) = runs.next().await { - let codes = self.codes.clone(); + let codes = Arc::clone(&self.codes); let codes_eof = eof.split_off(); let ctx2 = ctx.clone(); - let segment_sink2 = segment_sink.clone(); + let segment_sink2 = Arc::clone(&segment_sink); let codes_fut = handle.spawn_nested(move |h| async move { codes.write_stream( ctx2, @@ -191,10 +191,10 @@ impl LayoutStrategy for DictStrategy { ).await }); - let values = self.values.clone(); + let values = Arc::clone(&self.values); let values_eof = eof.split_off(); let ctx2 = ctx.clone(); - let segment_sink2 = segment_sink.clone(); + let segment_sink2 = Arc::clone(&segment_sink); let dtype2 = dtype2.clone(); let values_layout = handle.spawn_nested(move |h| async move { values.write_stream( @@ -505,7 +505,7 @@ async fn peek_first_chunk( None => Ok((stream.boxed(), None)), Some(Err(e)) => Err(e), Some(Ok((sequence_id, chunk))) => { - let chunk_clone = chunk.clone(); + let chunk_clone = Arc::clone(&chunk); let reconstructed_stream = once(async move { Ok((sequence_id, chunk_clone)) }).chain(stream); Ok((reconstructed_stream.boxed(), Some(chunk))) diff --git a/vortex-layout/src/layouts/flat/reader.rs b/vortex-layout/src/layouts/flat/reader.rs index 727566d3db8..2a0e6d625e3 100644 --- a/vortex-layout/src/layouts/flat/reader.rs +++ b/vortex-layout/src/layouts/flat/reader.rs @@ -129,7 +129,7 @@ impl LayoutReader for FlatReader { .vortex_expect("Row range begin must fit within FlatLayout size") ..usize::try_from(row_range.end) .vortex_expect("Row range end must fit within FlatLayout size"); - let name = self.name.clone(); + let name = Arc::clone(&self.name); let array = self.array_future(); let expr = expr.clone(); let session = self.session.clone(); @@ -187,7 +187,7 @@ impl LayoutReader for FlatReader { .vortex_expect("Row range begin must fit within FlatLayout size") ..usize::try_from(row_range.end) .vortex_expect("Row range end must fit within FlatLayout size"); - let name = self.name.clone(); + let name = Arc::clone(&self.name); let array = self.array_future(); let expr = expr.clone(); @@ -255,7 +255,7 @@ mod test { let layout = FlatLayoutStrategy::default() .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), array.to_array_stream().sequenced(ptr), eof, handle, @@ -294,7 +294,7 @@ mod test { let layout = FlatLayoutStrategy::default() .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), array.to_array_stream().sequenced(ptr), eof, handle, @@ -331,7 +331,7 @@ mod test { let layout = FlatLayoutStrategy::default() .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), array.to_array_stream().sequenced(ptr), eof, handle, diff --git a/vortex-layout/src/layouts/flat/writer.rs b/vortex-layout/src/layouts/flat/writer.rs index 8f01669638e..a613d4259d9 100644 --- a/vortex-layout/src/layouts/flat/writer.rs +++ b/vortex-layout/src/layouts/flat/writer.rs @@ -249,7 +249,7 @@ mod tests { let layout = FlatLayoutStrategy::default() .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), array.to_array_stream().sequenced(ptr), eof, handle, @@ -298,7 +298,7 @@ mod tests { let layout = FlatLayoutStrategy::default() .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), array.to_array_stream().sequenced(ptr), eof, handle, @@ -365,7 +365,7 @@ mod tests { let layout = FlatLayoutStrategy::default() .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), array.to_array_stream().sequenced(ptr), eof, handle, @@ -433,7 +433,7 @@ mod tests { .with_allow_encodings(allowed) .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), filter.to_array_stream().sequenced(ptr), eof, handle, @@ -475,7 +475,7 @@ mod tests { .with_allow_encodings(allowed) .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), dict.to_array_stream().sequenced(ptr), eof, handle, diff --git a/vortex-layout/src/layouts/repartition.rs b/vortex-layout/src/layouts/repartition.rs index a022abd27cb..6acd8120b1c 100644 --- a/vortex-layout/src/layouts/repartition.rs +++ b/vortex-layout/src/layouts/repartition.rs @@ -387,7 +387,7 @@ mod tests { let stream = fsl.into_array().to_array_stream().sequenced(ptr); let layout = - block_on(|handle| strategy.write_stream(ctx, segments.clone(), stream, eof, handle))?; + block_on(|handle| strategy.write_stream(ctx, Arc::clone(&segments), stream, eof, handle))?; // The layout should be a ChunkedLayout with multiple children. // With 1000 rows and effective block_len = 132: @@ -442,7 +442,7 @@ mod tests { let stream = elements.into_array().to_array_stream().sequenced(ptr); let layout = - block_on(|handle| strategy.write_stream(ctx, segments.clone(), stream, eof, handle))?; + block_on(|handle| strategy.write_stream(ctx, Arc::clone(&segments), stream, eof, handle))?; assert_eq!(layout.row_count(), num_elements as u64); assert_eq!(layout.nchildren(), 2); diff --git a/vortex-layout/src/layouts/row_idx/mod.rs b/vortex-layout/src/layouts/row_idx/mod.rs index 8ce4a2f5f4b..4c517a78b29 100644 --- a/vortex-layout/src/layouts/row_idx/mod.rs +++ b/vortex-layout/src/layouts/row_idx/mod.rs @@ -55,7 +55,7 @@ pub struct RowIdxLayoutReader { impl RowIdxLayoutReader { pub fn new(row_offset: u64, child: Arc, session: VortexSession) -> Self { Self { - name: child.name().clone(), + name: Arc::clone(&child.name()), row_offset, child, partition_cache: DashMap::with_hasher(Default::default()), @@ -205,7 +205,7 @@ impl LayoutReader for RowIdxLayoutReader { // during the filter evaluation. Partitioning::RowIdx(_) => Ok(mask), Partitioning::Child(expr) => self.child.filter_evaluation(row_range, expr, mask), - Partitioning::Partitioned(p) => p.clone().into_mask_future( + Partitioning::Partitioned(p) => Arc::clone(&p).into_mask_future( mask, |annotation, expr, mask| match annotation { Partition::RowIdx => Ok(row_idx_mask_future( @@ -240,7 +240,7 @@ impl LayoutReader for RowIdxLayoutReader { } Partitioning::Child(expr) => self.child.projection_evaluation(row_range, expr, mask), Partitioning::Partitioned(p) => { - p.clone() + Arc::clone(&p) .into_array_future(mask, |annotation, expr, mask| match annotation { Partition::RowIdx => { Ok(row_idx_array_future(self.row_offset, row_range, expr, mask)) @@ -337,7 +337,7 @@ mod tests { let layout = FlatLayoutStrategy::default() .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), array.to_array_stream().sequenced(ptr), eof, handle, @@ -377,7 +377,7 @@ mod tests { let layout = FlatLayoutStrategy::default() .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), array.to_array_stream().sequenced(ptr), eof, handle, @@ -417,7 +417,7 @@ mod tests { let layout = FlatLayoutStrategy::default() .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), array.to_array_stream().sequenced(ptr), eof, handle, diff --git a/vortex-layout/src/layouts/struct_/reader.rs b/vortex-layout/src/layouts/struct_/reader.rs index 1b6fc51b44b..1dc30589f83 100644 --- a/vortex-layout/src/layouts/struct_/reader.rs +++ b/vortex-layout/src/layouts/struct_/reader.rs @@ -83,7 +83,7 @@ impl StructReader { let mut names: Vec> = struct_dt .names() .iter() - .map(|x| x.inner().clone()) + .map(|x| Arc::clone(&x.inner())) .collect(); if layout.dtype.is_nullable() { @@ -92,10 +92,10 @@ impl StructReader { } let lazy_children = LazyReaderChildren::new( - layout.children.clone(), + Arc::clone(&layout.children), dtypes, names, - segment_source.clone(), + Arc::clone(&segment_source), session.clone(), ); @@ -293,7 +293,7 @@ impl LayoutReader for StructReader { .map_err(|err| { err.with_context(format!("While evaluating filter partition {name}")) }), - Partitioned::Multi(partitioned) => partitioned.clone().into_mask_future( + Partitioned::Multi(partitioned) => Arc::clone(&partitioned).into_mask_future( mask, |name, expr, mask| { self.field_reader(name)? @@ -363,7 +363,7 @@ impl LayoutReader for StructReader { let struct_array = array.to_struct(); let masked_fields: Vec = struct_array .iter_unmasked_fields() - .map(|a| a.clone().mask(validity.clone())) + .map(|a| Arc::clone(&a).mask(Arc::clone(&validity))) .try_collect()?; Ok(StructArray::try_new( @@ -445,7 +445,7 @@ mod tests { let layout = block_on(|handle| { strategy.write_stream( ctx, - segments.clone(), + Arc::clone(&segments), StructArray::try_new( Vec::::new().into(), vec![], @@ -478,7 +478,7 @@ mod tests { let layout = block_on(|handle| { strategy.write_stream( ctx, - segments.clone(), + Arc::clone(&segments), StructArray::from_fields( [ ("a", buffer![7, 2, 3].into_array()), @@ -514,7 +514,7 @@ mod tests { let layout = block_on(|handle| { strategy.write_stream( ctx, - segments.clone(), + Arc::clone(&segments), StructArray::try_from_iter_with_validity( [ ("a", buffer![7, 2, 3].into_array()), @@ -555,7 +555,7 @@ mod tests { let layout = block_on(|handle| { strategy.write_stream( ctx, - segments.clone(), + Arc::clone(&segments), StructArray::try_from_iter_with_validity( [( "a", diff --git a/vortex-layout/src/layouts/table.rs b/vortex-layout/src/layouts/table.rs index 15e3737624e..a5576d78008 100644 --- a/vortex-layout/src/layouts/table.rs +++ b/vortex-layout/src/layouts/table.rs @@ -153,14 +153,14 @@ impl TableStrategy { if field_path.starts_with_field(field) && let Some(subpath) = field_path.clone().step_into() { - new_writers.insert(subpath, strategy.clone()); + new_writers.insert(subpath, Arc::clone(&strategy)); } } Self { leaf_writers: new_writers, - validity: self.validity.clone(), - fallback: self.fallback.clone(), + validity: Arc::clone(&self.validity), + fallback: Arc::clone(&self.fallback), } } @@ -271,7 +271,7 @@ impl LayoutStrategy for TableStrategy { Err(e) => { let e: Arc = Arc::new(e); for tx in column_streams_tx.iter() { - let _ = tx.send(Err(VortexError::from(e.clone()))).await; + let _ = tx.send(Err(VortexError::from(Arc::clone(&e)))).await; } break; } @@ -309,7 +309,7 @@ impl LayoutStrategy for TableStrategy { let child_eof = eof.split_off(); let field = Field::Name(name.clone()); handle.spawn_nested(|h| { - let validity = self.validity.clone(); + let validity = Arc::clone(&self.validity); // descend further and try with new fields let writer = self .leaf_writers @@ -321,11 +321,11 @@ impl LayoutStrategy for TableStrategy { Arc::new(self.descend(&field)) } else { // Use fallback for leaf columns - self.fallback.clone() + Arc::clone(&self.fallback) } }); let ctx = ctx.clone(); - let segment_sink = segment_sink.clone(); + let segment_sink = Arc::clone(&segment_sink); async move { // If we have a matching writer, we use it. @@ -372,8 +372,8 @@ mod tests { let flat = Arc::new(FlatLayoutStrategy::default()); // Success - let path = TableStrategy::new(flat.clone(), flat.clone()) - .with_field_writer(field_path!(a.b.c), flat.clone()); + let path = TableStrategy::new(Arc::clone(&flat), Arc::clone(&flat)) + .with_field_writer(field_path!(a.b.c), Arc::clone(&flat)); // Should panic right here. let _path = path.with_field_writer(field_path!(a.b), flat); @@ -385,7 +385,7 @@ mod tests { )] fn test_root_override() { let flat = Arc::new(FlatLayoutStrategy::default()); - let _strategy = TableStrategy::new(flat.clone(), flat.clone()) + let _strategy = TableStrategy::new(Arc::clone(&flat), Arc::clone(&flat)) .with_field_writer(FieldPath::root(), flat); } } diff --git a/vortex-layout/src/layouts/zoned/mod.rs b/vortex-layout/src/layouts/zoned/mod.rs index bcd4cf6699b..5167025ff3a 100644 --- a/vortex-layout/src/layouts/zoned/mod.rs +++ b/vortex-layout/src/layouts/zoned/mod.rs @@ -64,7 +64,7 @@ impl VTable for Zoned { fn metadata(layout: &Self::Layout) -> Self::Metadata { ZonedMetadata { zone_len: u32::try_from(layout.zone_len).vortex_expect("Invalid zone length"), - present_stats: layout.present_stats.clone(), + present_stats: Arc::clone(&layout.present_stats), } } @@ -122,7 +122,7 @@ impl VTable for Zoned { dtype: dtype.clone(), children: children.to_arc(), zone_len: metadata.zone_len as usize, - present_stats: metadata.present_stats.clone(), + present_stats: Arc::clone(&metadata.present_stats), }) } diff --git a/vortex-layout/src/layouts/zoned/reader.rs b/vortex-layout/src/layouts/zoned/reader.rs index b4c30610467..61b68859059 100644 --- a/vortex-layout/src/layouts/zoned/reader.rs +++ b/vortex-layout/src/layouts/zoned/reader.rs @@ -73,12 +73,12 @@ impl ZonedReader { layout.dtype.clone(), ZoneMap::dtype_for_stats_table(layout.dtype(), layout.present_stats()), ]; - let names = vec![name.clone(), format!("{}.zones", name).into()]; + let names = vec![Arc::clone(&name), format!("{}.zones", name).into()]; let lazy_children = LazyReaderChildren::new( - layout.children.clone(), + Arc::clone(&layout.children), dtypes, names, - segment_source.clone(), + Arc::clone(&segment_source), session.clone(), ); @@ -122,7 +122,7 @@ impl ZonedReader { self.zone_map .get_or_init(move || { let nzones = self.layout.nzones(); - let present_stats = self.layout.present_stats.clone(); + let present_stats = Arc::clone(&self.layout.present_stats); let zones_eval = self .lazy_children @@ -271,7 +271,7 @@ impl LayoutReader for ZonedReader { }) .try_collect()?; - let name = self.name.clone(); + let name = Arc::clone(&self.name); let expr = expr.clone(); Ok(MaskFuture::new(mask.len(), async move { @@ -444,7 +444,7 @@ mod test { .to_array_stream() .sequenced(ptr); let layout = block_on(|handle| { - strategy.write_stream(ctx, segments.clone(), array_stream, eof, handle) + strategy.write_stream(ctx, Arc::clone(&segments), array_stream, eof, handle) }) .unwrap(); (segments, layout) diff --git a/vortex-layout/src/layouts/zoned/writer.rs b/vortex-layout/src/layouts/zoned/writer.rs index 1800532b1ee..5fdc6f9646c 100644 --- a/vortex-layout/src/layouts/zoned/writer.rs +++ b/vortex-layout/src/layouts/zoned/writer.rs @@ -78,7 +78,7 @@ impl LayoutStrategy for ZonedStrategy { mut eof: SequencePointer, handle: Handle, ) -> VortexResult { - let stats = self.options.stats.clone(); + let stats = Arc::clone(&self.options.stats); let handle2 = handle.clone(); let stats_accumulator = Arc::new(Mutex::new(StatsAccumulator::new( @@ -92,7 +92,7 @@ impl LayoutStrategy for ZonedStrategy { stream.dtype().clone(), stream .map(move |chunk| { - let stats = stats.clone(); + let stats = Arc::clone(&stats); handle2.spawn_cpu(move || { let (sequence_id, chunk) = chunk?; chunk.statistics().compute_all(&stats)?; @@ -105,7 +105,7 @@ impl LayoutStrategy for ZonedStrategy { // Now we accumulate the stats we computed above, this time we cannot spawn because we // need to feed the accumulator an ordered stream. - let stats_accumulator2 = stats_accumulator.clone(); + let stats_accumulator2 = Arc::clone(&stats_accumulator); let stream = SequentialStreamAdapter::new( stream.dtype().clone(), stream.map(move |item| { @@ -127,7 +127,7 @@ impl LayoutStrategy for ZonedStrategy { .child .write_stream( ctx.clone(), - segment_sink.clone(), + Arc::clone(&segment_sink), stream, data_eof, handle.clone(), @@ -148,14 +148,14 @@ impl LayoutStrategy for ZonedStrategy { .sequenced(eof.split_off()); let zones_layout = self .stats - .write_stream(ctx, segment_sink.clone(), stats_stream, eof, handle) + .write_stream(ctx, Arc::clone(&segment_sink), stats_stream, eof, handle) .await?; Ok(ZonedLayout::new( data_layout, zones_layout, block_size, - stats_table.present_stats().clone(), + Arc::clone(&stats_table.present_stats()), ) .into_layout()) } diff --git a/vortex-layout/src/reader.rs b/vortex-layout/src/reader.rs index 9ccd695c572..e103c163efe 100644 --- a/vortex-layout/src/reader.rs +++ b/vortex-layout/src/reader.rs @@ -145,7 +145,7 @@ impl LazyReaderChildren { let child = self.children.child(idx, dtype)?; child.new_reader( Arc::clone(&self.names[idx]), - self.segment_source.clone(), + Arc::clone(&self.segment_source), &self.session, ) }) diff --git a/vortex-layout/src/scan/arrow.rs b/vortex-layout/src/scan/arrow.rs index 2a17a81e6f8..bc716e798d0 100644 --- a/vortex-layout/src/scan/arrow.rs +++ b/vortex-layout/src/scan/arrow.rs @@ -104,7 +104,7 @@ where { #[inline] fn schema(&self) -> SchemaRef { - self.schema.clone() + Arc::clone(&self.schema) } } @@ -195,14 +195,14 @@ mod tests { fn test_record_batch_iterator_adapter() -> VortexResult<()> { let schema = create_arrow_schema(); let batch1 = RecordBatch::try_new( - schema.clone(), + Arc::clone(&schema), vec![ Arc::new(Int32Array::from(vec![Some(1), Some(2)])) as ArrowArrayRef, Arc::new(StringArray::from(vec![Some("Alice"), Some("Bob")])) as ArrowArrayRef, ], )?; let batch2 = RecordBatch::try_new( - schema.clone(), + Arc::clone(&schema), vec![ Arc::new(Int32Array::from(vec![None, Some(4)])) as ArrowArrayRef, Arc::new(StringArray::from(vec![Some("Charlie"), None])) as ArrowArrayRef, @@ -212,7 +212,7 @@ mod tests { let iter = vec![Ok(batch1), Ok(batch2)].into_iter(); let mut adapter = RecordBatchIteratorAdapter { iter, - schema: schema.clone(), + schema: Arc::clone(&schema), }; // Test RecordBatchReader trait @@ -238,7 +238,7 @@ mod tests { let iter = vec![Err(error)].into_iter(); let mut adapter = RecordBatchIteratorAdapter { iter, - schema: schema.clone(), + schema: Arc::clone(&schema), }; // Test that error is propagated @@ -251,7 +251,7 @@ mod tests { fn test_mixed_success_and_error() { let schema = create_arrow_schema(); let batch = RecordBatch::try_new( - schema.clone(), + Arc::clone(&schema), vec![ Arc::new(Int32Array::from(vec![Some(1)])) as ArrowArrayRef, Arc::new(StringArray::from(vec![Some("Test")])) as ArrowArrayRef, diff --git a/vortex-layout/src/scan/layout.rs b/vortex-layout/src/scan/layout.rs index ab26a534f99..4ffdadab2e6 100644 --- a/vortex-layout/src/scan/layout.rs +++ b/vortex-layout/src/scan/layout.rs @@ -158,7 +158,7 @@ impl DataSource for LayoutReaderDataSource { } Ok(Box::new(LayoutReaderScan { - reader: self.reader.clone(), + reader: Arc::clone(&self.reader), session: self.session.clone(), dtype, projection: scan_request.projection, @@ -246,7 +246,7 @@ impl Stream for LayoutReaderScan { } let split = Box::new(LayoutReaderSplit { - reader: this.reader.clone(), + reader: Arc::clone(&this.reader), session: this.session.clone(), projection: this.projection.clone(), filter: this.filter.clone(), diff --git a/vortex-layout/src/scan/multi.rs b/vortex-layout/src/scan/multi.rs index e7fc803c38b..992d6409529 100644 --- a/vortex-layout/src/scan/multi.rs +++ b/vortex-layout/src/scan/multi.rs @@ -204,8 +204,8 @@ impl DataSource for MultiLayoutDataSource { for child in &self.children { match child { - MultiLayoutChild::Opened(reader) => ready.push_back(reader.clone()), - MultiLayoutChild::Deferred(factory) => deferred.push_back(factory.clone()), + MultiLayoutChild::Opened(reader) => ready.push_back(Arc::clone(&reader)), + MultiLayoutChild::Deferred(factory) => deferred.push_back(Arc::clone(&factory)), } } diff --git a/vortex-layout/src/scan/repeated_scan.rs b/vortex-layout/src/scan/repeated_scan.rs index ec050ba520a..1d5caaa66cf 100644 --- a/vortex-layout/src/scan/repeated_scan.rs +++ b/vortex-layout/src/scan/repeated_scan.rs @@ -124,9 +124,9 @@ impl RepeatedScan { let ctx = Arc::new(TaskContext { selection: self.selection.clone(), filter: self.filter.clone().map(|f| Arc::new(FilterExpr::new(f))), - reader: self.layout_reader.clone(), + reader: Arc::clone(&self.layout_reader), projection: self.projection.clone(), - mapper: self.map_fn.clone(), + mapper: Arc::clone(&self.map_fn), }); let row_range = intersect_ranges(self.row_range.as_ref(), row_range); @@ -176,7 +176,7 @@ impl RepeatedScan { break; } - tasks.push(split_exec(ctx.clone(), range, limit.as_mut())?); + tasks.push(split_exec(Arc::clone(&ctx), range, limit.as_mut())?); } Ok(tasks) diff --git a/vortex-layout/src/scan/scan_builder.rs b/vortex-layout/src/scan/scan_builder.rs index af179bc670d..9bb2d5355d8 100644 --- a/vortex-layout/src/scan/scan_builder.rs +++ b/vortex-layout/src/scan/scan_builder.rs @@ -559,7 +559,7 @@ mod test { #[test] fn into_stream_is_lazy() { let calls = Arc::new(AtomicUsize::new(0)); - let reader = Arc::new(CountingLayoutReader::new(calls.clone())); + let reader = Arc::new(CountingLayoutReader::new(Arc::clone(&calls))); let session = crate::scan::test::SCAN_SESSION.clone(); @@ -654,7 +654,7 @@ mod test { #[test] fn into_stream_executes_after_prepare() -> VortexResult<()> { let calls = Arc::new(AtomicUsize::new(0)); - let reader = Arc::new(SplittingLayoutReader::new(calls.clone())); + let reader = Arc::new(SplittingLayoutReader::new(Arc::clone(&calls))); let runtime = SingleThreadRuntime::default(); let session = crate::scan::test::session_with_handle(runtime.handle()); @@ -755,7 +755,7 @@ mod test { let guard = gate.lock(); let calls = Arc::new(AtomicUsize::new(0)); - let reader = Arc::new(BlockingSplitsLayoutReader::new(gate.clone(), calls.clone())); + let reader = Arc::new(BlockingSplitsLayoutReader::new(Arc::clone(&gate), Arc::clone(&calls))); let runtime = SingleThreadRuntime::default(); let session = crate::scan::test::session_with_handle(runtime.handle()); diff --git a/vortex-layout/src/scan/split_by.rs b/vortex-layout/src/scan/split_by.rs index 712f9e5bb4f..825ae24e0f3 100644 --- a/vortex-layout/src/scan/split_by.rs +++ b/vortex-layout/src/scan/split_by.rs @@ -78,7 +78,7 @@ mod test { FlatLayoutStrategy::default() .write_stream( ctx, - segments.clone(), + Arc::clone(&segments), buffer![1_i32; 10] .into_array() .to_array_stream() diff --git a/vortex-layout/src/scan/tasks.rs b/vortex-layout/src/scan/tasks.rs index 056d8451882..4b623166bb7 100644 --- a/vortex-layout/src/scan/tasks.rs +++ b/vortex-layout/src/scan/tasks.rs @@ -71,8 +71,8 @@ pub fn split_exec( // NOTE: it's very important that the pruning and filter evaluations are built OUTSIDE // the future. Registering these row ranges eagerly is a hint to the IO system that // we want to start prefetching the IO for this split. - let reader = ctx.reader.clone(); - let filter = filter.clone(); + let reader = Arc::clone(&ctx.reader); + let filter = Arc::clone(&filter); let row_range = row_range.clone(); MaskFuture::new(row_mask.len(), async move { @@ -141,7 +141,7 @@ pub fn split_exec( ctx.reader .projection_evaluation(&row_range, &ctx.projection, filter_mask.clone())?; - let mapper = ctx.mapper.clone(); + let mapper = Arc::clone(&ctx.mapper); let array_fut = async move { let mask = filter_mask.await?; if mask.all_false() { diff --git a/vortex-layout/src/segments/cache.rs b/vortex-layout/src/segments/cache.rs index 174c6b1e637..37675c19d2a 100644 --- a/vortex-layout/src/segments/cache.rs +++ b/vortex-layout/src/segments/cache.rs @@ -137,7 +137,7 @@ impl SegmentCacheSourceAdapter { impl SegmentSource for SegmentCacheSourceAdapter { fn request(&self, id: SegmentId) -> SegmentFuture { - let cache = self.cache.clone(); + let cache = Arc::clone(&self.cache); let delegate = self.source.request(id); async move { diff --git a/vortex-layout/src/sequence.rs b/vortex-layout/src/sequence.rs index 5aa6353674f..5e9fe3a1c49 100644 --- a/vortex-layout/src/sequence.rs +++ b/vortex-layout/src/sequence.rs @@ -102,7 +102,7 @@ impl SequenceId { pub fn descend(self) -> SequencePointer { let mut id = self.id.clone(); id.push(0); - SequencePointer(SequenceId::new(id, self.universe.clone())) + SequencePointer(SequenceId::new(id, Arc::clone(&self.universe))) } /// Waits until all SequenceIds with IDs lexicographically smaller than this one are dropped. @@ -188,7 +188,7 @@ impl SequencePointer { let last = next_id.last_mut(); let last = last.vortex_expect("must have at least one element"); *last += 1; - let next_sibling = SequenceId::new(next_id, self.0.universe.clone()); + let next_sibling = SequenceId::new(next_id, Arc::clone(&self.0.universe)); std::mem::replace(&mut self.0, next_sibling) } diff --git a/vortex-python/src/arrays/builtins/chunked.rs b/vortex-python/src/arrays/builtins/chunked.rs index 293932c21c2..0e5ec8199ef 100644 --- a/vortex-python/src/arrays/builtins/chunked.rs +++ b/vortex-python/src/arrays/builtins/chunked.rs @@ -10,6 +10,7 @@ use crate::arrays::PyArrayRef; use crate::arrays::native::AsArrayRef; use crate::arrays::native::EncodingSubclass; use crate::arrays::native::PyNativeArray; +use std::sync::Arc; /// Concrete class for arrays with `vortex.chunked` encoding. #[pyclass(name = "ChunkedArray", module = "vortex", extends=PyNativeArray, frozen)] @@ -25,7 +26,7 @@ impl PyChunkedArray { self_ .as_array_ref() .iter_chunks() - .map(|chunk| PyArrayRef::from(chunk.clone())) + .map(|chunk| PyArrayRef::from(Arc::clone(&chunk))) .collect() } } diff --git a/vortex-python/src/arrays/builtins/struct_.rs b/vortex-python/src/arrays/builtins/struct_.rs index 0fe52aa0402..4bf21e7fd49 100644 --- a/vortex-python/src/arrays/builtins/struct_.rs +++ b/vortex-python/src/arrays/builtins/struct_.rs @@ -13,6 +13,7 @@ use crate::arrays::native::AsArrayRef; use crate::arrays::native::EncodingSubclass; use crate::arrays::native::PyNativeArray; use crate::error::PyVortexResult; +use std::sync::Arc; /// Concrete class for arrays with `vortex.struct` encoding. #[pyclass(name = "StructArray", module = "vortex", extends=PyNativeArray, frozen)] @@ -26,7 +27,7 @@ impl EncodingSubclass for PyStructArray { impl PyStructArray { /// Returns the given field of the struct array. pub fn field(self_: PyRef<'_, Self>, name: &str) -> PyVortexResult { - let field = self_.as_array_ref().unmasked_field_by_name(name)?.clone(); + let field = Arc::clone(&self_.as_array_ref().unmasked_field_by_name(name)?); Ok(PyArrayRef::from(field)) } diff --git a/vortex-python/src/arrays/compressed.rs b/vortex-python/src/arrays/compressed.rs index 96abfa4f1a1..d18091049d2 100644 --- a/vortex-python/src/arrays/compressed.rs +++ b/vortex-python/src/arrays/compressed.rs @@ -20,6 +20,7 @@ use crate::arrays::PyArrayRef; use crate::arrays::native::EncodingSubclass; use crate::arrays::native::PyNativeArray; use crate::error::PyVortexResult; +use std::sync::Arc; /// Concrete class for arrays with `vortex.alp` encoding. #[pyclass(name = "AlpArray", module = "vortex", extends=PyNativeArray, frozen)] @@ -90,7 +91,7 @@ impl PyZigZagArray { #[staticmethod] pub fn encode(array: PyArrayRef) -> PyVortexResult { Ok(PyVortex( - zigzag_encode(array.inner().clone().to_primitive())?.into_array(), + zigzag_encode(Arc::clone(&array.inner()).to_primitive())?.into_array(), )) } } diff --git a/vortex-python/src/arrays/mod.rs b/vortex-python/src/arrays/mod.rs index 205f18d248f..0e0ef13d5dc 100644 --- a/vortex-python/src/arrays/mod.rs +++ b/vortex-python/src/arrays/mod.rs @@ -50,6 +50,7 @@ use crate::install_module; use crate::python_repr::PythonRepr; use crate::scalar::PyScalar; use crate::serde::context::PyArrayContext; +use std::sync::Arc; pub(crate) fn init(py: Python, parent: &Bound) -> PyResult<()> { let m = PyModule::new(py, "arrays")?; @@ -104,7 +105,7 @@ impl<'py> FromPyObject<'_, 'py> for PyArrayRef { fn extract(ob: Borrowed<'_, 'py, PyAny>) -> Result { // If it's already native, then we're done. if let Ok(native) = ob.cast::() { - return Ok(Self(native.get().inner().clone())); + return Ok(Self(Arc::clone(&native.get().inner()))); } // Otherwise, if it's a subclass of `PyArray`, then we can extract the inner array. @@ -124,7 +125,7 @@ impl<'py> IntoPyObject<'py> for PyArrayRef { } // Otherwise, wrap the ArrayRef in a PyNativeArray. - Ok(PyNativeArray::init(py, self.0.clone())?.into_any()) + Ok(PyNativeArray::init(py, Arc::clone(&self.0))?.into_any()) } } @@ -332,7 +333,7 @@ impl PyArray { let chunks = chunked_array .iter_chunks() - .map(|chunk| -> PyVortexResult<_> { Ok(chunk.clone().into_arrow(&arrow_dtype)?) }) + .map(|chunk| -> PyVortexResult<_> { Ok(Arc::clone(&chunk).into_arrow(&arrow_dtype)?) }) .collect::, _>>()?; let pa_data_type = arrow_dtype.clone().to_pyarrow(py)?; diff --git a/vortex-python/src/dataset.rs b/vortex-python/src/dataset.rs index 1985f0b3141..dccb103037d 100644 --- a/vortex-python/src/dataset.rs +++ b/vortex-python/src/dataset.rs @@ -131,7 +131,7 @@ impl PyVortexDataset { #[pymethods] impl PyVortexDataset { fn schema(self_: PyRef) -> PyResult> { - self_.schema.clone().to_pyarrow(self_.py()) + Arc::clone(&self_.schema).to_pyarrow(self_.py()) } #[pyo3(signature = (*, columns = None, row_filter = None, indices = None, row_range = None))] diff --git a/vortex-python/src/scalar/factory.rs b/vortex-python/src/scalar/factory.rs index d4a0e000cf1..486950732bc 100644 --- a/vortex-python/src/scalar/factory.rs +++ b/vortex-python/src/scalar/factory.rs @@ -183,7 +183,7 @@ fn scalar_helper_inner(value: &Bound<'_, PyAny>, dtype: Option<&DType>) -> PyRes .iter() .map(|e| scalar_helper_inner(&e, Some(element_dtype))) .try_collect()?; - Scalar::list(element_dtype.clone(), elements, Nullability::NonNullable); + Scalar::list(Arc::clone(&element_dtype), elements, Nullability::NonNullable); } else { // If no dtype was provided, we need to infer the element dtype from the list contents. // We do this in a greedy way taking the first element dtype we find. diff --git a/vortex-tensor/src/scalar_fns/cosine_similarity.rs b/vortex-tensor/src/scalar_fns/cosine_similarity.rs index deef6fbdec3..c110133b61c 100644 --- a/vortex-tensor/src/scalar_fns/cosine_similarity.rs +++ b/vortex-tensor/src/scalar_fns/cosine_similarity.rs @@ -32,6 +32,7 @@ use crate::utils::extension_element_ptype; use crate::utils::extension_list_size; use crate::utils::extension_storage; use crate::utils::extract_flat_elements; +use std::sync::Arc; /// Cosine similarity between two columns. /// @@ -295,7 +296,7 @@ mod tests { 0.0, 0.0, 0.0, 7.0, // tensor 4 ], )?; - let rhs = lhs.clone(); + let rhs = Arc::clone(&lhs); assert_close( &eval_cosine_similarity(lhs, rhs, 5)?, diff --git a/vortex-tensor/src/utils.rs b/vortex-tensor/src/utils.rs index 82e2d1f5b45..f7df6f9944e 100644 --- a/vortex-tensor/src/utils.rs +++ b/vortex-tensor/src/utils.rs @@ -17,6 +17,7 @@ use vortex::error::VortexResult; use vortex::error::vortex_bail; use vortex::error::vortex_ensure; use vortex::error::vortex_err; +use std::sync::Arc; /// Extracts the list size from a tensor-like extension dtype. /// @@ -60,7 +61,7 @@ pub fn extension_storage(array: &ArrayRef) -> VortexResult { .as_opt::() .ok_or_else(|| vortex_err!("scalar_fn input must be an extension array"))?; - Ok(ext.storage_array().clone()) + Ok(Arc::clone(&ext.storage_array())) } /// The flat primitive elements of a tensor storage array, with typed row access. @@ -103,7 +104,7 @@ pub fn extract_flat_elements( // amount of data. let single = ConstantArray::new(constant.scalar().clone(), 1).into_array(); let fsl: FixedSizeListArray = single.execute(ctx)?; - let elems: PrimitiveArray = fsl.elements().clone().execute(ctx)?; + let elems: PrimitiveArray = Arc::clone(&fsl.elements()).execute(ctx)?; return Ok(FlatElements { elems, stride: 0, @@ -112,8 +113,8 @@ pub fn extract_flat_elements( } // Otherwise we have to fully expand all of the data. - let fsl: FixedSizeListArray = storage.clone().execute(ctx)?; - let elems: PrimitiveArray = fsl.elements().clone().execute(ctx)?; + let fsl: FixedSizeListArray = Arc::clone(&storage).execute(ctx)?; + let elems: PrimitiveArray = Arc::clone(&fsl.elements()).execute(ctx)?; Ok(FlatElements { elems, stride: list_size, diff --git a/vortex-test/compat-gen/src/adapter.rs b/vortex-test/compat-gen/src/adapter.rs index 1ff1b11ccf1..b64329ca3be 100644 --- a/vortex-test/compat-gen/src/adapter.rs +++ b/vortex-test/compat-gen/src/adapter.rs @@ -123,7 +123,7 @@ pub fn read_layout_tree(bytes: ByteBuffer) -> VortexResult<()> { runtime()?.block_on(async { let session = VortexSession::default().with_tokio(); let file = session.open_options().open_buffer(bytes)?; - let root_layout = file.footer().layout().clone(); + let root_layout = Arc::clone(&file.footer().layout()); let segment_source = file.segment_source(); for layout_result in root_layout.depth_first_traversal() { @@ -135,7 +135,7 @@ pub fn read_layout_tree(bytes: ByteBuffer) -> VortexResult<()> { if row_count == 0 { continue; } - let reader = layout.new_reader("".into(), segment_source.clone(), &session)?; + let reader = layout.new_reader("".into(), Arc::clone(&segment_source), &session)?; let len = usize::try_from(row_count).map_err(|e| vortex_err!("row count overflow: {e}"))?; reader diff --git a/vortex-test/compat-gen/src/fixtures/arrays/datasets/clickbench.rs b/vortex-test/compat-gen/src/fixtures/arrays/datasets/clickbench.rs index 7959f475c6b..e9ecdd60f98 100644 --- a/vortex-test/compat-gen/src/fixtures/arrays/datasets/clickbench.rs +++ b/vortex-test/compat-gen/src/fixtures/arrays/datasets/clickbench.rs @@ -15,6 +15,7 @@ use vortex_error::VortexResult; use vortex_error::vortex_err; use crate::fixtures::DatasetFixture; +use std::sync::Arc; // TODO: Upload the pre-sampled 5k parquet to R2 and download it in a build.rs instead of // downloading the full ~112MB partition 0 at runtime. @@ -95,7 +96,7 @@ fn sample_and_write(source_bytes: &[u8], dest: &std::path::Path) -> VortexResult let source_bytes = Bytes::copy_from_slice(source_bytes); let builder = ParquetRecordBatchReaderBuilder::try_new(source_bytes.clone()) .map_err(|e| vortex_err!("failed to open source parquet: {e}"))?; - let metadata = builder.metadata().clone(); + let metadata = Arc::clone(&builder.metadata()); let total_rows: usize = metadata .row_groups() diff --git a/vortex-test/compat-gen/src/fixtures/arrays/datasets/mod.rs b/vortex-test/compat-gen/src/fixtures/arrays/datasets/mod.rs index 8a727f0b8f8..619b5161640 100644 --- a/vortex-test/compat-gen/src/fixtures/arrays/datasets/mod.rs +++ b/vortex-test/compat-gen/src/fixtures/arrays/datasets/mod.rs @@ -6,6 +6,7 @@ mod clickbench; mod tpch; use crate::fixtures::DatasetFixture; +use std::sync::Arc; /// All dataset-derived fixtures. pub fn fixtures() -> Vec> { @@ -34,7 +35,7 @@ mod tests { { let array = dataset.build().unwrap(); let regular_bytes = adapter::write_compressed_to_bytes( - array.clone(), + Arc::clone(&array), WriteStrategyBuilder::default().build(), ) .unwrap(); diff --git a/vortex-test/compat-gen/src/fixtures/arrays/synthetic/mod.rs b/vortex-test/compat-gen/src/fixtures/arrays/synthetic/mod.rs index 3c3ffcb80d6..fca4ebfe5de 100644 --- a/vortex-test/compat-gen/src/fixtures/arrays/synthetic/mod.rs +++ b/vortex-test/compat-gen/src/fixtures/arrays/synthetic/mod.rs @@ -6,6 +6,7 @@ mod arrays; mod encodings; use crate::fixtures::FlatLayoutFixture; +use std::sync::Arc; /// All synthetic fixtures (arrays + encodings). pub fn fixtures() -> Vec> { @@ -28,7 +29,7 @@ mod tests { for fixture in fixtures() { let array = fixture.build().unwrap(); check_expected_encodings(&array, fixture.as_ref()).unwrap(); - let bytes = adapter::write_file_to_bytes(array.clone()).unwrap(); + let bytes = adapter::write_file_to_bytes(Arc::clone(&array)).unwrap(); let roundtripped = adapter::read_file(bytes).unwrap(); assert_arrays_eq!(array, roundtripped); } diff --git a/vortex-tui/src/browse/app.rs b/vortex-tui/src/browse/app.rs index a6292d071a8..f51bec1f696 100644 --- a/vortex-tui/src/browse/app.rs +++ b/vortex-tui/src/browse/app.rs @@ -61,7 +61,7 @@ impl LayoutCursor { pub fn new(footer: Footer, segment_source: Arc) -> Self { Self { path: Vec::new(), - layout: footer.layout().clone(), + layout: Arc::clone(&footer.layout()), segment_map: Arc::clone(footer.segment_map()), footer, segment_source, @@ -76,7 +76,7 @@ impl LayoutCursor { segment_source: Arc, path: Vec, ) -> Self { - let mut layout = footer.layout().clone(); + let mut layout = Arc::clone(&footer.layout()); // Traverse the layout tree at each element of the path. for component in path.iter().copied() { @@ -99,7 +99,7 @@ impl LayoutCursor { let mut path = self.path.clone(); path.push(n); - Self::new_with_path(self.footer.clone(), self.segment_source.clone(), path) + Self::new_with_path(self.footer.clone(), Arc::clone(&self.segment_source), path) } /// Create a new cursor pointing at the parent of the current layout. @@ -109,7 +109,7 @@ impl LayoutCursor { let mut path = self.path.clone(); path.pop(); - Self::new_with_path(self.footer.clone(), self.segment_source.clone(), path) + Self::new_with_path(self.footer.clone(), Arc::clone(&self.segment_source), path) } /// Get a human-readable description of the flat layout metadata. @@ -355,7 +355,7 @@ impl AppState { use vortex::array::serde::ArrayParts; use vortex::expr::root; - let layout = &self.cursor.layout().clone(); + let layout = &Arc::clone(&self.cursor.layout()); let row_count = layout.row_count(); // Load the array. diff --git a/vortex-tui/src/browse/ui/layouts.rs b/vortex-tui/src/browse/ui/layouts.rs index 7f9967cb12f..324d0e1e0ad 100644 --- a/vortex-tui/src/browse/ui/layouts.rs +++ b/vortex-tui/src/browse/ui/layouts.rs @@ -34,6 +34,7 @@ use vortex::layout::layouts::flat::Flat; use vortex::layout::layouts::zoned::Zoned; use crate::browse::app::AppState; +use std::sync::Arc; /// Render the Layouts tab. pub fn render_layouts(app_state: &mut AppState, area: Rect, buf: &mut Buffer) { @@ -117,7 +118,7 @@ fn render_array(app: &AppState, area: Rect, buf: &mut Buffer, is_stats_table: bo // native, asynchronously on WASM) and cached in AppState. The render loop never // performs I/O. let array = match app.cached_flat_array.as_ref() { - Some(arr) => arr.clone(), + Some(arr) => Arc::clone(&arr), None => { let loading = Paragraph::new("Loading array data...").style(Style::default().fg(Color::DarkGray)); diff --git a/vortex-tui/src/inspect.rs b/vortex-tui/src/inspect.rs index d2258e59a4d..f09e7e6891b 100644 --- a/vortex-tui/src/inspect.rs +++ b/vortex-tui/src/inspect.rs @@ -210,8 +210,8 @@ async fn exec_inspect_json( let footer_json = if matches!(mode, InspectMode::Footer) && eof.valid_magic && postscript_json.is_some() { inspector.read_footer().await.ok().map(|footer| { - let segment_map = footer.segment_map().clone(); - let root_layout = footer.layout().clone(); + let segment_map = Arc::clone(&footer.segment_map()); + let root_layout = Arc::clone(&footer.layout()); let mut segment_paths: Vec>>> = vec![None; segment_map.len()]; let mut queue = @@ -538,14 +538,14 @@ impl FooterSegments { println!("\nSegment details:\n"); - let segment_map = self.0.segment_map().clone(); + let segment_map = Arc::clone(&self.0.segment_map()); if segment_map.is_empty() { println!(""); return; } let mut segment_paths: Vec>>> = vec![None; segment_map.len()]; - let root_layout = self.0.layout().clone(); + let root_layout = Arc::clone(&self.0.layout()); let mut queue = VecDeque::<(Vec>, LayoutRef)>::from_iter([(Vec::new(), root_layout)]); diff --git a/vortex-tui/src/tree.rs b/vortex-tui/src/tree.rs index a8799afea1e..649767079ba 100644 --- a/vortex-tui/src/tree.rs +++ b/vortex-tui/src/tree.rs @@ -12,6 +12,7 @@ use vortex::error::VortexResult; use vortex::file::OpenOptionsSessionExt; use vortex::layout::LayoutRef; use vortex::session::VortexSession; +use std::sync::Arc; /// Command-line arguments for the tree command. #[derive(Debug, clap::Parser)] @@ -115,7 +116,7 @@ async fn exec_layout_tree( let footer = vxf.footer(); if json { - let tree = layout_to_json(footer.layout().clone())?; + let tree = layout_to_json(Arc::clone(&footer.layout()))?; let json_output = serde_json::to_string_pretty(&tree) .map_err(|e| vortex::error::vortex_err!("Failed to serialize JSON: {e}"))?; println!("{json_output}"); diff --git a/vortex-utils/src/env.rs b/vortex-utils/src/env.rs index 9c4505ea443..19e78e1f12b 100644 --- a/vortex-utils/src/env.rs +++ b/vortex-utils/src/env.rs @@ -166,7 +166,7 @@ mod tests { let key = "VORTEX_TEST_ENV_VAR_WAIT"; let second_acquired = Arc::new(AtomicBool::new(false)); - let second_acquired_clone = second_acquired.clone(); + let second_acquired_clone = Arc::clone(&second_acquired); // First guard in main thread let _guard1 = EnvVarGuard::set(key, "first"); diff --git a/vortex/benches/common_encoding_tree_throughput.rs b/vortex/benches/common_encoding_tree_throughput.rs index d13049c780f..ff2b4728b34 100644 --- a/vortex/benches/common_encoding_tree_throughput.rs +++ b/vortex/benches/common_encoding_tree_throughput.rs @@ -35,6 +35,7 @@ use vortex::encodings::fsst::fsst_train_compressor; use vortex::encodings::runend::RunEndArray; use vortex::extension::datetime::TimeUnit; use vortex_fastlanes::BitPackedArray; +use std::sync::Arc; #[global_allocator] static GLOBAL: MiMalloc = MiMalloc; @@ -262,7 +263,7 @@ mod setup { fsst.symbols().clone(), fsst.symbol_lengths().clone(), compressed_codes, - fsst.uncompressed_lengths().clone(), + Arc::clone(&fsst.uncompressed_lengths()), ) .unwrap(); diff --git a/vortex/benches/single_encoding_throughput.rs b/vortex/benches/single_encoding_throughput.rs index 4776afa4a52..c292868fedf 100644 --- a/vortex/benches/single_encoding_throughput.rs +++ b/vortex/benches/single_encoding_throughput.rs @@ -39,6 +39,7 @@ use vortex_array::dtype::Nullability; use vortex_array::session::ArraySession; use vortex_sequence::SequenceArray; use vortex_session::VortexSession; +use std::sync::Arc; #[global_allocator] static GLOBAL: MiMalloc = MiMalloc; @@ -316,7 +317,7 @@ fn bench_zstd_compress_u32(bencher: Bencher) { let array = uint_array.into_array(); with_byte_counter(bencher, NUM_VALUES * 4) - .with_inputs(|| array.clone()) + .with_inputs(|| Arc::clone(&array)) .bench_values(|a| ZstdArray::from_array(a, 3, 8192).unwrap()); } @@ -389,7 +390,7 @@ fn bench_zstd_compress_string(bencher: Bencher) { let array = varbinview_arr.into_array(); with_byte_counter(bencher, nbytes) - .with_inputs(|| array.clone()) + .with_inputs(|| Arc::clone(&array)) .bench_values(|a| ZstdArray::from_array(a, 3, 8192).unwrap()); } diff --git a/vortex/examples/tracing_vortex.rs b/vortex/examples/tracing_vortex.rs index aa456a44f5f..5f844852c02 100644 --- a/vortex/examples/tracing_vortex.rs +++ b/vortex/examples/tracing_vortex.rs @@ -197,7 +197,7 @@ impl VortexLayer { let handle = WriterHandle::spawn(session, rx, output_dir, batch_size); ( Self { - sender: signal.clone(), + sender: Arc::clone(&signal), }, handle, ShutdownSignal { inner: signal },