diff --git a/bench-vortex/benches/compress.rs b/bench-vortex/benches/compress.rs index a5fbe3949f..093b023bf5 100644 --- a/bench-vortex/benches/compress.rs +++ b/bench-vortex/benches/compress.rs @@ -104,7 +104,7 @@ fn parquet_decompress_read(buf: bytes::Bytes) -> usize { } fn parquet_compressed_written_size(array: &ArrayData, compression: Compression) -> usize { - let chunked = ChunkedArray::maybe_from(array.clone()).unwrap(); + let chunked = ChunkedArray::maybe_from(array).unwrap(); let (batches, schema) = chunked_to_vec_record_batch(chunked); parquet_compress_write(batches, schema, compression, &mut Vec::new()) } diff --git a/vortex-array/src/array/extension/compute/compare.rs b/vortex-array/src/array/extension/compute/compare.rs index 47e53be14b..48fb3bd9cc 100644 --- a/vortex-array/src/array/extension/compute/compare.rs +++ b/vortex-array/src/array/extension/compute/compare.rs @@ -23,7 +23,7 @@ impl CompareFn for ExtensionEncoding { } // If the RHS is an extension array matching ours, we can extract the storage. - if let Some(rhs_ext) = ExtensionArray::maybe_from(rhs.clone()) { + if let Some(rhs_ext) = ExtensionArray::maybe_from(rhs) { return compare(lhs.storage(), rhs_ext.storage(), operator).map(Some); } diff --git a/vortex-array/src/macros.rs b/vortex-array/src/macros.rs index 42863258c3..df5f127430 100644 --- a/vortex-array/src/macros.rs +++ b/vortex-array/src/macros.rs @@ -64,8 +64,9 @@ macro_rules! impl_encoding { /// /// Preferred in cases where a backtrace isn't needed, like when trying multiple encoding to go /// down different code paths. - pub fn maybe_from(data: $crate::ArrayData) -> Option { - (data.encoding().id() == <[<$Name Encoding>] as $crate::encoding::Encoding>::ID).then_some(Self(data)) + pub fn maybe_from(data: impl AsRef<$crate::ArrayData>) -> Option { + let data = data.as_ref(); + (data.encoding().id() == <[<$Name Encoding>] as $crate::encoding::Encoding>::ID).then_some(Self(data.clone())) } } diff --git a/vortex-ipc/src/stream_writer/mod.rs b/vortex-ipc/src/stream_writer/mod.rs index 25097c172c..c991ab8870 100644 --- a/vortex-ipc/src/stream_writer/mod.rs +++ b/vortex-ipc/src/stream_writer/mod.rs @@ -82,7 +82,7 @@ impl StreamArrayWriter { } pub async fn write_array(self, array: ArrayData) -> VortexResult { - if let Some(chunked_array) = ChunkedArray::maybe_from(array.clone()) { + if let Some(chunked_array) = ChunkedArray::maybe_from(&array) { self.write_array_stream(chunked_array.array_stream()).await } else { self.write_array_stream(array.into_array_stream()).await diff --git a/vortex-sampling-compressor/src/compressors/alp.rs b/vortex-sampling-compressor/src/compressors/alp.rs index f23026ab0e..232a643f4f 100644 --- a/vortex-sampling-compressor/src/compressors/alp.rs +++ b/vortex-sampling-compressor/src/compressors/alp.rs @@ -28,7 +28,7 @@ impl EncodingCompressor for ALPCompressor { fn can_compress(&self, array: &ArrayData) -> Option<&dyn EncodingCompressor> { // Only support primitive arrays - let parray = PrimitiveArray::maybe_from(array.clone())?; + let parray = PrimitiveArray::maybe_from(array)?; // Only supports f32 and f64 if !matches!(parray.ptype(), PType::F32 | PType::F64) { diff --git a/vortex-sampling-compressor/src/compressors/alp_rd.rs b/vortex-sampling-compressor/src/compressors/alp_rd.rs index c133acd3a7..c805ad05e7 100644 --- a/vortex-sampling-compressor/src/compressors/alp_rd.rs +++ b/vortex-sampling-compressor/src/compressors/alp_rd.rs @@ -34,7 +34,7 @@ impl EncodingCompressor for ALPRDCompressor { fn can_compress(&self, array: &ArrayData) -> Option<&dyn EncodingCompressor> { // Only support primitive arrays - let parray = PrimitiveArray::maybe_from(array.clone())?; + let parray = PrimitiveArray::maybe_from(array)?; // Only supports f32 and f64 if !matches!(parray.ptype(), PType::F32 | PType::F64) { diff --git a/vortex-sampling-compressor/src/compressors/bitpacked.rs b/vortex-sampling-compressor/src/compressors/bitpacked.rs index a1baa92e53..e51b0572a9 100644 --- a/vortex-sampling-compressor/src/compressors/bitpacked.rs +++ b/vortex-sampling-compressor/src/compressors/bitpacked.rs @@ -55,7 +55,7 @@ impl EncodingCompressor for BitPackedCompressor { fn can_compress(&self, array: &ArrayData) -> Option<&dyn EncodingCompressor> { // Only support primitive arrays - let parray = PrimitiveArray::maybe_from(array.clone())?; + let parray = PrimitiveArray::maybe_from(array)?; // Only supports unsigned ints if !parray.ptype().is_unsigned_int() { diff --git a/vortex-sampling-compressor/src/compressors/delta.rs b/vortex-sampling-compressor/src/compressors/delta.rs index a7aa6555fc..3b071a71ba 100644 --- a/vortex-sampling-compressor/src/compressors/delta.rs +++ b/vortex-sampling-compressor/src/compressors/delta.rs @@ -23,7 +23,7 @@ impl EncodingCompressor for DeltaCompressor { fn can_compress(&self, array: &ArrayData) -> Option<&dyn EncodingCompressor> { // Only support primitive arrays - let parray = PrimitiveArray::maybe_from(array.clone())?; + let parray = PrimitiveArray::maybe_from(array)?; // Only supports ints if !parray.ptype().is_unsigned_int() { diff --git a/vortex-sampling-compressor/src/compressors/dict.rs b/vortex-sampling-compressor/src/compressors/dict.rs index 168296fb4e..82951ac0a0 100644 --- a/vortex-sampling-compressor/src/compressors/dict.rs +++ b/vortex-sampling-compressor/src/compressors/dict.rs @@ -54,13 +54,13 @@ impl EncodingCompressor for DictCompressor { like: Option>, ctx: SamplingCompressor<'a>, ) -> VortexResult> { - let (codes, values) = if let Some(p) = PrimitiveArray::maybe_from(array.clone()) { + let (codes, values) = if let Some(p) = PrimitiveArray::maybe_from(array) { let (codes, values) = dict_encode_primitive(&p); (codes.into_array(), values.into_array()) - } else if let Some(vb) = VarBinArray::maybe_from(array.clone()) { + } else if let Some(vb) = VarBinArray::maybe_from(array) { let (codes, values) = dict_encode_varbin(&vb); (codes.into_array(), values.into_array()) - } else if let Some(vb) = VarBinViewArray::maybe_from(array.clone()) { + } else if let Some(vb) = VarBinViewArray::maybe_from(array) { let (codes, values) = dict_encode_varbinview(&vb); (codes.into_array(), values.into_array()) } else { diff --git a/vortex-sampling-compressor/src/compressors/for.rs b/vortex-sampling-compressor/src/compressors/for.rs index 4f22266f3a..f296be13fc 100644 --- a/vortex-sampling-compressor/src/compressors/for.rs +++ b/vortex-sampling-compressor/src/compressors/for.rs @@ -26,7 +26,7 @@ impl EncodingCompressor for FoRCompressor { fn can_compress(&self, array: &ArrayData) -> Option<&dyn EncodingCompressor> { // Only support primitive arrays - let parray = PrimitiveArray::maybe_from(array.clone())?; + let parray = PrimitiveArray::maybe_from(array)?; // Only supports integers if !parray.ptype().is_int() { diff --git a/vortex-sampling-compressor/src/compressors/zigzag.rs b/vortex-sampling-compressor/src/compressors/zigzag.rs index 659f676055..99ad2f8134 100644 --- a/vortex-sampling-compressor/src/compressors/zigzag.rs +++ b/vortex-sampling-compressor/src/compressors/zigzag.rs @@ -24,7 +24,7 @@ impl EncodingCompressor for ZigZagCompressor { fn can_compress(&self, array: &ArrayData) -> Option<&dyn EncodingCompressor> { // Only support primitive arrays - let parray = PrimitiveArray::maybe_from(array.clone())?; + let parray = PrimitiveArray::maybe_from(array)?; // Only supports signed integers if !parray.ptype().is_signed_int() {