Skip to content

Commit

Permalink
feat: teach *Metadata and ScalarValue to Display (#975)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
danking authored Oct 4, 2024
1 parent 1f21e30 commit e240a50
Show file tree
Hide file tree
Showing 29 changed files with 240 additions and 25 deletions.
8 changes: 7 additions & 1 deletion encodings/alp/src/alp/array.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Debug;
use std::fmt::{Debug, Display};
use std::sync::Arc;

use serde::{Deserialize, Serialize};
Expand All @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions encodings/alp/src/alp_rd/array.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{Debug, Display};

use serde::{Deserialize, Serialize};
use vortex::array::{PrimitiveArray, SparseArray};
use vortex::encoding::ids;
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion encodings/bytebool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Debug;
use std::fmt::{Debug, Display};
use std::mem::ManuallyDrop;

use arrow_buffer::BooleanBuffer;
Expand All @@ -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(|| {
Expand Down
8 changes: 7 additions & 1 deletion encodings/datetime-parts/src/array.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Debug;
use std::fmt::{Debug, Display};

use serde::{Deserialize, Serialize};
use vortex::array::StructArray;
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion encodings/dict/src/dict.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Debug;
use std::fmt::{Debug, Display};

use serde::{Deserialize, Serialize};
use vortex::accessor::ArrayAccessor;
Expand All @@ -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<Self> {
if !codes.dtype().is_unsigned_int() || codes.dtype().is_nullable() {
Expand Down
8 changes: 8 additions & 0 deletions encodings/fastlanes/src/bitpacking/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{Debug, Display};

use ::serde::{Deserialize, Serialize};
pub use compress::*;
use fastlanes::BitPacking;
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion encodings/fastlanes/src/delta/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Debug;
use std::fmt::{Debug, Display};

pub use compress::*;
use serde::{Deserialize, Serialize};
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion encodings/fastlanes/src/for/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Debug;
use std::fmt::{Debug, Display};

pub use compress::*;
use serde::{Deserialize, Serialize};
Expand All @@ -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<Self> {
if reference.is_null() {
Expand Down
7 changes: 7 additions & 0 deletions encodings/fsst/src/array.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::{Debug, Display};
use std::sync::Arc;

use fsst::{Decompressor, Symbol};
Expand All @@ -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`.
///
Expand Down
8 changes: 7 additions & 1 deletion encodings/roaring/src/boolean/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -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<Self> {
if length < bitmap.cardinality() as usize {
Expand Down
8 changes: 7 additions & 1 deletion encodings/roaring/src/integer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Debug;
use std::fmt::{Debug, Display};

pub use compress::*;
use croaring::{Bitmap, Portable};
Expand All @@ -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<Self> {
if !ptype.is_unsigned_int() {
Expand Down
8 changes: 8 additions & 0 deletions encodings/runend-bool/src/array.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<Self> {
let length: usize = scalar_at(&ends, ends.len() - 1)?.as_ref().try_into()?;
Expand Down
8 changes: 7 additions & 1 deletion encodings/runend/src/runend.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Debug;
use std::fmt::{Debug, Display};

use serde::{Deserialize, Serialize};
use vortex::array::PrimitiveArray;
Expand Down Expand Up @@ -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<Self> {
let length: usize = scalar_at(&ends, ends.len() - 1)?.as_ref().try_into()?;
Expand Down
8 changes: 8 additions & 0 deletions encodings/zigzag/src/zigzag.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use serde::{Deserialize, Serialize};
use vortex::array::PrimitiveArray;
use vortex::encoding::ids;
Expand All @@ -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<Self> {
let encoded_dtype = encoded.dtype().clone();
Expand Down
8 changes: 8 additions & 0 deletions vortex-array/src/array/bool/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{Debug, Display};

use arrow_buffer::bit_iterator::{BitIndexIterator, BitSliceIterator};
use arrow_buffer::BooleanBuffer;
use itertools::Itertools;
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions vortex-array/src/array/chunked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions vortex-array/src/array/constant/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::fmt::Display;

use serde::{Deserialize, Serialize};
use vortex_error::{vortex_panic, VortexResult};
Expand All @@ -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<S>(scalar: S, length: usize) -> Self
where
Expand Down
8 changes: 8 additions & 0 deletions vortex-array/src/array/extension/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions vortex-array/src/array/null/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use serde::{Deserialize, Serialize};
use vortex_dtype::DType;
use vortex_error::{VortexExpect as _, VortexResult};
Expand All @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions vortex-array/src/array/primitive/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::{Debug, Display};
use std::mem::{transmute, MaybeUninit};
use std::ptr;
use std::sync::Arc;
Expand Down Expand Up @@ -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| {
Expand Down
Loading

0 comments on commit e240a50

Please sign in to comment.