From e240a50e3f2af3c97cfc29af26e8893dd4259069 Mon Sep 17 00:00:00 2001 From: Dan King Date: Fri, 4 Oct 2024 09:38:13 -0400 Subject: [PATCH] feat: teach *Metadata and ScalarValue to Display (#975) `tree_display` is a fantastic debugging tool until you get a ConstantArray whose value is a BufferString of a Buffer which is a 1 character slice of a buffer of 65,536 "F"s which get Debug'ed as the number 70 with a comma and a space repeated 65,536 times. --- encodings/alp/src/alp/array.rs | 8 ++++- encodings/alp/src/alp_rd/array.rs | 8 +++++ encodings/bytebool/src/lib.rs | 8 ++++- encodings/datetime-parts/src/array.rs | 8 ++++- encodings/dict/src/dict.rs | 8 ++++- encodings/fastlanes/src/bitpacking/mod.rs | 8 +++++ encodings/fastlanes/src/delta/mod.rs | 8 ++++- encodings/fastlanes/src/for/mod.rs | 8 ++++- encodings/fsst/src/array.rs | 7 ++++ encodings/roaring/src/boolean/mod.rs | 8 ++++- encodings/roaring/src/integer/mod.rs | 8 ++++- encodings/runend-bool/src/array.rs | 8 +++++ encodings/runend/src/runend.rs | 8 ++++- encodings/zigzag/src/zigzag.rs | 8 +++++ vortex-array/src/array/bool/mod.rs | 8 +++++ vortex-array/src/array/chunked/mod.rs | 8 +++++ vortex-array/src/array/constant/mod.rs | 11 ++++++ vortex-array/src/array/extension/mod.rs | 8 +++++ vortex-array/src/array/null/mod.rs | 8 +++++ vortex-array/src/array/primitive/mod.rs | 7 ++++ vortex-array/src/array/sparse/mod.rs | 8 +++++ vortex-array/src/array/struct_/mod.rs | 8 +++++ vortex-array/src/array/varbin/mod.rs | 8 ++++- vortex-array/src/array/varbinview/mod.rs | 8 ++++- vortex-array/src/metadata.rs | 6 ++-- vortex-array/src/tree.rs | 9 +---- vortex-array/src/validity.rs | 7 ++++ vortex-datafusion/src/plans.rs | 6 ++-- vortex-scalar/src/value.rs | 44 +++++++++++++++++++++++ 29 files changed, 240 insertions(+), 25 deletions(-) diff --git a/encodings/alp/src/alp/array.rs b/encodings/alp/src/alp/array.rs index 1950cdcc74..4c707089e5 100644 --- a/encodings/alp/src/alp/array.rs +++ b/encodings/alp/src/alp/array.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use std::fmt::{Debug, Display}; use std::sync::Arc; use serde::{Deserialize, Serialize}; @@ -23,6 +23,12 @@ pub struct ALPMetadata { exponents: Exponents, } +impl Display for ALPMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl ALPArray { pub fn try_new( encoded: Array, diff --git a/encodings/alp/src/alp_rd/array.rs b/encodings/alp/src/alp_rd/array.rs index ce1ef06e7c..ff9cdcb14b 100644 --- a/encodings/alp/src/alp_rd/array.rs +++ b/encodings/alp/src/alp_rd/array.rs @@ -1,3 +1,5 @@ +use std::fmt::{Debug, Display}; + use serde::{Deserialize, Serialize}; use vortex::array::{PrimitiveArray, SparseArray}; use vortex::encoding::ids; @@ -21,6 +23,12 @@ pub struct ALPRDMetadata { has_exceptions: bool, } +impl Display for ALPRDMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl ALPRDArray { pub fn try_new( dtype: DType, diff --git a/encodings/bytebool/src/lib.rs b/encodings/bytebool/src/lib.rs index 1a2afda2a4..9ada3ae361 100644 --- a/encodings/bytebool/src/lib.rs +++ b/encodings/bytebool/src/lib.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use std::fmt::{Debug, Display}; use std::mem::ManuallyDrop; use arrow_buffer::BooleanBuffer; @@ -24,6 +24,12 @@ pub struct ByteBoolMetadata { validity: ValidityMetadata, } +impl Display for ByteBoolMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl ByteBoolArray { pub fn validity(&self) -> Validity { self.metadata().validity.to_validity(|| { diff --git a/encodings/datetime-parts/src/array.rs b/encodings/datetime-parts/src/array.rs index 9c7cf5060c..95492f1df2 100644 --- a/encodings/datetime-parts/src/array.rs +++ b/encodings/datetime-parts/src/array.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use std::fmt::{Debug, Display}; use serde::{Deserialize, Serialize}; use vortex::array::StructArray; @@ -25,6 +25,12 @@ pub struct DateTimePartsMetadata { subseconds_ptype: PType, } +impl Display for DateTimePartsMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl DateTimePartsArray { pub fn try_new( dtype: DType, diff --git a/encodings/dict/src/dict.rs b/encodings/dict/src/dict.rs index 2d418d3e00..85aaac50e4 100644 --- a/encodings/dict/src/dict.rs +++ b/encodings/dict/src/dict.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use std::fmt::{Debug, Display}; use serde::{Deserialize, Serialize}; use vortex::accessor::ArrayAccessor; @@ -24,6 +24,12 @@ pub struct DictMetadata { values_len: usize, } +impl Display for DictMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl DictArray { pub fn try_new(codes: Array, values: Array) -> VortexResult { if !codes.dtype().is_unsigned_int() || codes.dtype().is_nullable() { diff --git a/encodings/fastlanes/src/bitpacking/mod.rs b/encodings/fastlanes/src/bitpacking/mod.rs index ecfe2af76b..6fe4a26965 100644 --- a/encodings/fastlanes/src/bitpacking/mod.rs +++ b/encodings/fastlanes/src/bitpacking/mod.rs @@ -1,3 +1,5 @@ +use std::fmt::{Debug, Display}; + use ::serde::{Deserialize, Serialize}; pub use compress::*; use fastlanes::BitPacking; @@ -29,6 +31,12 @@ pub struct BitPackedMetadata { has_patches: bool, } +impl Display for BitPackedMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + /// NB: All non-null values in the patches array are considered patches impl BitPackedArray { /// Create a new bitpacked array using a buffer of packed data. diff --git a/encodings/fastlanes/src/delta/mod.rs b/encodings/fastlanes/src/delta/mod.rs index 822258fec7..dcfb977e43 100644 --- a/encodings/fastlanes/src/delta/mod.rs +++ b/encodings/fastlanes/src/delta/mod.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use std::fmt::{Debug, Display}; pub use compress::*; use serde::{Deserialize, Serialize}; @@ -24,6 +24,12 @@ pub struct DeltaMetadata { offset: usize, // must be <1024 } +impl Display for DeltaMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + /// A FastLanes-style delta-encoded array of primitive values. /// /// A [`DeltaArray`] comprises a sequence of _chunks_ each representing 1,024 delta-encoded values, diff --git a/encodings/fastlanes/src/for/mod.rs b/encodings/fastlanes/src/for/mod.rs index eec771cac9..5c8a587431 100644 --- a/encodings/fastlanes/src/for/mod.rs +++ b/encodings/fastlanes/src/for/mod.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use std::fmt::{Debug, Display}; pub use compress::*; use serde::{Deserialize, Serialize}; @@ -23,6 +23,12 @@ pub struct FoRMetadata { shift: u8, } +impl Display for FoRMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl FoRArray { pub fn try_new(child: Array, reference: Scalar, shift: u8) -> VortexResult { if reference.is_null() { diff --git a/encodings/fsst/src/array.rs b/encodings/fsst/src/array.rs index f802498c50..2b4e551273 100644 --- a/encodings/fsst/src/array.rs +++ b/encodings/fsst/src/array.rs @@ -1,3 +1,4 @@ +use std::fmt::{Debug, Display}; use std::sync::Arc; use fsst::{Decompressor, Symbol}; @@ -24,6 +25,12 @@ pub struct FSSTMetadata { uncompressed_lengths_dtype: DType, } +impl Display for FSSTMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl FSSTArray { /// Build an FSST array from a set of `symbols` and `codes`. /// diff --git a/encodings/roaring/src/boolean/mod.rs b/encodings/roaring/src/boolean/mod.rs index 127b56445a..18301434b4 100644 --- a/encodings/roaring/src/boolean/mod.rs +++ b/encodings/roaring/src/boolean/mod.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::fmt::Debug; +use std::fmt::{Debug, Display}; use arrow_buffer::{BooleanBuffer, Buffer as ArrowBuffer}; pub use compress::*; @@ -29,6 +29,12 @@ pub struct RoaringBoolMetadata { length: usize, } +impl Display for RoaringBoolMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl RoaringBoolArray { pub fn try_new(bitmap: Bitmap, length: usize) -> VortexResult { if length < bitmap.cardinality() as usize { diff --git a/encodings/roaring/src/integer/mod.rs b/encodings/roaring/src/integer/mod.rs index 0ccab6f110..6ec2a031dd 100644 --- a/encodings/roaring/src/integer/mod.rs +++ b/encodings/roaring/src/integer/mod.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use std::fmt::{Debug, Display}; pub use compress::*; use croaring::{Bitmap, Portable}; @@ -25,6 +25,12 @@ pub struct RoaringIntMetadata { ptype: PType, } +impl Display for RoaringIntMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl RoaringIntArray { pub fn try_new(bitmap: Bitmap, ptype: PType) -> VortexResult { if !ptype.is_unsigned_int() { diff --git a/encodings/runend-bool/src/array.rs b/encodings/runend-bool/src/array.rs index 5e8ec946b2..c101a57169 100644 --- a/encodings/runend-bool/src/array.rs +++ b/encodings/runend-bool/src/array.rs @@ -1,3 +1,5 @@ +use std::fmt::{Debug, Display}; + use serde::{Deserialize, Serialize}; use vortex::compute::unary::scalar_at; use vortex::compute::{search_sorted, SearchSortedSide}; @@ -26,6 +28,12 @@ pub struct RunEndBoolMetadata { length: usize, } +impl Display for RunEndBoolMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl RunEndBoolArray { pub fn try_new(ends: Array, start: bool, validity: Validity) -> VortexResult { let length: usize = scalar_at(&ends, ends.len() - 1)?.as_ref().try_into()?; diff --git a/encodings/runend/src/runend.rs b/encodings/runend/src/runend.rs index 8851b79c48..13c5460da2 100644 --- a/encodings/runend/src/runend.rs +++ b/encodings/runend/src/runend.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use std::fmt::{Debug, Display}; use serde::{Deserialize, Serialize}; use vortex::array::PrimitiveArray; @@ -29,6 +29,12 @@ pub struct RunEndMetadata { length: usize, } +impl Display for RunEndMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl RunEndArray { pub fn try_new(ends: Array, values: Array, validity: Validity) -> VortexResult { let length: usize = scalar_at(&ends, ends.len() - 1)?.as_ref().try_into()?; diff --git a/encodings/zigzag/src/zigzag.rs b/encodings/zigzag/src/zigzag.rs index 4ce5109eb5..7dcce7c571 100644 --- a/encodings/zigzag/src/zigzag.rs +++ b/encodings/zigzag/src/zigzag.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use serde::{Deserialize, Serialize}; use vortex::array::PrimitiveArray; use vortex::encoding::ids; @@ -22,6 +24,12 @@ impl_encoding!("vortex.zigzag", ids::ZIGZAG, ZigZag); #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ZigZagMetadata; +impl Display for ZigZagMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "ZigZagMetadata") + } +} + impl ZigZagArray { pub fn try_new(encoded: Array) -> VortexResult { let encoded_dtype = encoded.dtype().clone(); diff --git a/vortex-array/src/array/bool/mod.rs b/vortex-array/src/array/bool/mod.rs index 7e0fb8498f..90ea09729b 100644 --- a/vortex-array/src/array/bool/mod.rs +++ b/vortex-array/src/array/bool/mod.rs @@ -1,3 +1,5 @@ +use std::fmt::{Debug, Display}; + use arrow_buffer::bit_iterator::{BitIndexIterator, BitSliceIterator}; use arrow_buffer::BooleanBuffer; use itertools::Itertools; @@ -25,6 +27,12 @@ pub struct BoolMetadata { first_byte_bit_offset: u8, } +impl Display for BoolMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl BoolArray { pub fn buffer(&self) -> &Buffer { self.as_ref() diff --git a/vortex-array/src/array/chunked/mod.rs b/vortex-array/src/array/chunked/mod.rs index 29a9be145c..e5a5e192e4 100644 --- a/vortex-array/src/array/chunked/mod.rs +++ b/vortex-array/src/array/chunked/mod.rs @@ -2,6 +2,8 @@ //! //! Vortex is a chunked array library that's able to +use std::fmt::{Debug, Display}; + use futures_util::stream; use itertools::Itertools; use serde::{Deserialize, Serialize}; @@ -33,6 +35,12 @@ pub struct ChunkedMetadata { nchunks: usize, } +impl Display for ChunkedMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl ChunkedArray { const ENDS_DTYPE: DType = DType::Primitive(PType::U64, Nullability::NonNullable); diff --git a/vortex-array/src/array/constant/mod.rs b/vortex-array/src/array/constant/mod.rs index a7be493433..93503e7059 100644 --- a/vortex-array/src/array/constant/mod.rs +++ b/vortex-array/src/array/constant/mod.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::fmt::Display; use serde::{Deserialize, Serialize}; use vortex_error::{vortex_panic, VortexResult}; @@ -22,6 +23,16 @@ pub struct ConstantMetadata { scalar_value: ScalarValue, } +impl Display for ConstantMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "ConstantMetadata {{ scalar_value: {} }}", + self.scalar_value + ) + } +} + impl ConstantArray { pub fn new(scalar: S, length: usize) -> Self where diff --git a/vortex-array/src/array/extension/mod.rs b/vortex-array/src/array/extension/mod.rs index 65dcabee39..66c6e5b0d0 100644 --- a/vortex-array/src/array/extension/mod.rs +++ b/vortex-array/src/array/extension/mod.rs @@ -1,3 +1,5 @@ +use std::fmt::{Debug, Display}; + use serde::{Deserialize, Serialize}; use vortex_dtype::{DType, ExtDType, ExtID}; use vortex_error::{VortexExpect as _, VortexResult}; @@ -18,6 +20,12 @@ pub struct ExtensionMetadata { storage_dtype: DType, } +impl Display for ExtensionMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl ExtensionArray { pub fn new(ext_dtype: ExtDType, storage: Array) -> Self { Self::try_from_parts( diff --git a/vortex-array/src/array/null/mod.rs b/vortex-array/src/array/null/mod.rs index c2efd1c4ab..4cf6083bf0 100644 --- a/vortex-array/src/array/null/mod.rs +++ b/vortex-array/src/array/null/mod.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use serde::{Deserialize, Serialize}; use vortex_dtype::DType; use vortex_error::{VortexExpect as _, VortexResult}; @@ -16,6 +18,12 @@ impl_encoding!("vortex.null", ids::NULL, Null); #[derive(Debug, Clone, Serialize, Deserialize)] pub struct NullMetadata; +impl Display for NullMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "NullMetadata") + } +} + impl NullArray { pub fn new(len: usize) -> Self { Self::try_from_parts( diff --git a/vortex-array/src/array/primitive/mod.rs b/vortex-array/src/array/primitive/mod.rs index d4183d33a0..1b62e6ff62 100644 --- a/vortex-array/src/array/primitive/mod.rs +++ b/vortex-array/src/array/primitive/mod.rs @@ -1,3 +1,4 @@ +use std::fmt::{Debug, Display}; use std::mem::{transmute, MaybeUninit}; use std::ptr; use std::sync::Arc; @@ -33,6 +34,12 @@ pub struct PrimitiveMetadata { validity: ValidityMetadata, } +impl Display for PrimitiveMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl PrimitiveArray { pub fn new(buffer: Buffer, ptype: PType, validity: Validity) -> Self { let length = match_each_native_ptype!(ptype, |$P| { diff --git a/vortex-array/src/array/sparse/mod.rs b/vortex-array/src/array/sparse/mod.rs index c0ec5094c0..c9ef620818 100644 --- a/vortex-array/src/array/sparse/mod.rs +++ b/vortex-array/src/array/sparse/mod.rs @@ -1,3 +1,5 @@ +use std::fmt::{Debug, Display}; + use ::serde::{Deserialize, Serialize}; use vortex_dtype::{match_each_integer_ptype, DType}; use vortex_error::{vortex_bail, vortex_panic, VortexExpect as _, VortexResult}; @@ -26,6 +28,12 @@ pub struct SparseMetadata { fill_value: ScalarValue, } +impl Display for SparseMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl SparseArray { pub fn try_new( indices: Array, diff --git a/vortex-array/src/array/struct_/mod.rs b/vortex-array/src/array/struct_/mod.rs index 44ab782c57..dde61da432 100644 --- a/vortex-array/src/array/struct_/mod.rs +++ b/vortex-array/src/array/struct_/mod.rs @@ -1,3 +1,5 @@ +use std::fmt::{Debug, Display}; + use serde::{Deserialize, Serialize}; use vortex_dtype::field::Field; use vortex_dtype::{DType, FieldName, FieldNames, StructDType}; @@ -19,6 +21,12 @@ pub struct StructMetadata { validity: ValidityMetadata, } +impl Display for StructMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl StructArray { pub fn validity(&self) -> Validity { self.metadata().validity.to_validity(|| { diff --git a/vortex-array/src/array/varbin/mod.rs b/vortex-array/src/array/varbin/mod.rs index 43be6df45e..871776ccdc 100644 --- a/vortex-array/src/array/varbin/mod.rs +++ b/vortex-array/src/array/varbin/mod.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use std::fmt::{Debug, Display}; use num_traits::AsPrimitive; use serde::{Deserialize, Serialize}; @@ -37,6 +37,12 @@ pub struct VarBinMetadata { bytes_len: usize, } +impl Display for VarBinMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl VarBinArray { pub fn try_new( offsets: Array, diff --git a/vortex-array/src/array/varbinview/mod.rs b/vortex-array/src/array/varbinview/mod.rs index 2d5d2c91a1..61c78a50ca 100644 --- a/vortex-array/src/array/varbinview/mod.rs +++ b/vortex-array/src/array/varbinview/mod.rs @@ -1,4 +1,4 @@ -use std::fmt::{Debug, Formatter}; +use std::fmt::{Debug, Display, Formatter}; use std::ops::Deref; use std::sync::Arc; use std::{mem, slice}; @@ -114,6 +114,12 @@ pub struct VarBinViewMetadata { data_lens: Vec, } +impl Display for VarBinViewMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl VarBinViewArray { pub fn try_new( views: Array, diff --git a/vortex-array/src/metadata.rs b/vortex-array/src/metadata.rs index 01639f8254..dc37ee22fa 100644 --- a/vortex-array/src/metadata.rs +++ b/vortex-array/src/metadata.rs @@ -1,5 +1,5 @@ use std::any::Any; -use std::fmt::Debug; +use std::fmt::{Debug, Display}; use std::sync::Arc; use flexbuffers::{FlexbufferSerializer, Reader}; @@ -12,7 +12,9 @@ use vortex_error::{vortex_err, VortexResult}; /// metadata trait, and not the entire array trait. We require 'static so that we can downcast /// use the Any trait. /// TODO(ngates): add Display -pub trait ArrayMetadata: 'static + Send + Sync + Debug + TrySerializeArrayMetadata { +pub trait ArrayMetadata: + 'static + Send + Sync + Debug + TrySerializeArrayMetadata + Display +{ fn as_any(&self) -> &dyn Any; fn as_any_arc(self: Arc) -> Arc; } diff --git a/vortex-array/src/tree.rs b/vortex-array/src/tree.rs index 90a898ac81..bc1ae8e542 100644 --- a/vortex-array/src/tree.rs +++ b/vortex-array/src/tree.rs @@ -41,7 +41,6 @@ pub struct TreeFormatter<'a, 'b: 'a> { /// TODO(ngates): I think we want to go back to the old explicit style. It gives arrays more /// control over how their metadata etc is displayed. impl<'a, 'b: 'a> ArrayVisitor for TreeFormatter<'a, 'b> { - #[allow(clippy::use_debug)] fn visit_child(&mut self, name: &str, array: &Array) -> VortexResult<()> { array.with_dyn(|a| { let nbytes = a.nbytes(); @@ -57,13 +56,7 @@ impl<'a, 'b: 'a> ArrayVisitor for TreeFormatter<'a, 'b> { )?; self.indent(|i| { let array_data = ArrayData::from(array.clone()); - writeln!( - i.fmt, - // TODO(ngates): use Display for metadata - "{}metadata: {:?}", - i.indent, - array_data.metadata() - ) + writeln!(i.fmt, "{}metadata: {}", i.indent, array_data.metadata()) })?; let old_total_size = self.total_size; diff --git a/vortex-array/src/validity.rs b/vortex-array/src/validity.rs index 5b69a6d472..38b9ab52c3 100644 --- a/vortex-array/src/validity.rs +++ b/vortex-array/src/validity.rs @@ -1,3 +1,4 @@ +use std::fmt::{Debug, Display}; use std::ops::BitAnd; use arrow_buffer::{BooleanBuffer, BooleanBufferBuilder, NullBuffer}; @@ -26,6 +27,12 @@ pub enum ValidityMetadata { Array, } +impl Display for ValidityMetadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(self, f) + } +} + impl ValidityMetadata { pub fn to_validity(&self, array_fn: F) -> Validity where diff --git a/vortex-datafusion/src/plans.rs b/vortex-datafusion/src/plans.rs index 669223f9ce..9d41a59390 100644 --- a/vortex-datafusion/src/plans.rs +++ b/vortex-datafusion/src/plans.rs @@ -74,14 +74,13 @@ impl Debug for RowSelectorExec { } } -#[allow(clippy::use_debug)] impl DisplayAs for RowSelectorExec { fn fmt_as( &self, _display_format_type: DisplayFormatType, f: &mut Formatter, ) -> std::fmt::Result { - write!(f, "{:?}", self) + Debug::fmt(self, f) } } @@ -237,10 +236,9 @@ impl Debug for TakeRowsExec { } } -#[allow(clippy::use_debug)] impl DisplayAs for TakeRowsExec { fn fmt_as(&self, _display_type: DisplayFormatType, f: &mut Formatter) -> std::fmt::Result { - write!(f, "{:?}", self) + Debug::fmt(self, f) } } diff --git a/vortex-scalar/src/value.rs b/vortex-scalar/src/value.rs index 591aebb184..a36a5fdd7a 100644 --- a/vortex-scalar/src/value.rs +++ b/vortex-scalar/src/value.rs @@ -1,3 +1,4 @@ +use std::fmt::{Display, Write}; use std::sync::Arc; use vortex_buffer::{Buffer, BufferString}; @@ -24,6 +25,49 @@ pub enum ScalarValue { Null, } +fn to_hex(slice: &[u8]) -> Result { + let mut output = String::new(); + for byte in slice { + write!(output, "{:02x}", byte)?; + } + Ok(output) +} + +impl Display for ScalarValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ScalarValue::Bool(b) => write!(f, "{}", b), + ScalarValue::Primitive(pvalue) => write!(f, "{}", pvalue), + ScalarValue::Buffer(buf) => { + if buf.len() > 10 { + write!( + f, + "{}..{}", + to_hex(&buf[0..5])?, + to_hex(&buf[buf.len() - 5..buf.len()])?, + ) + } else { + write!(f, "{}", to_hex(buf.as_slice())?) + } + } + ScalarValue::BufferString(bufstr) => { + if bufstr.len() > 10 { + write!( + f, + "{}..{}", + &bufstr.as_str()[0..5], + &bufstr.as_str()[bufstr.len() - 5..bufstr.len()], + ) + } else { + write!(f, "{}", bufstr.as_str()) + } + } + ScalarValue::List(_) => todo!(), + ScalarValue::Null => write!(f, "null"), + } + } +} + impl ScalarValue { pub fn is_null(&self) -> bool { matches!(self, Self::Null)