Skip to content

Commit d9fcf06

Browse files
feat[vortex-expr]: better debug print (#5374)
Signed-off-by: Joe Isaacs <[email protected]>
1 parent b1054d0 commit d9fcf06

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

vortex-array/src/expr/expression.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use std::any::Any;
55
use std::fmt;
6-
use std::fmt::{Display, Formatter};
6+
use std::fmt::{Debug, Display, Formatter};
77
use std::hash::{Hash, Hasher};
88
use std::sync::Arc;
99

@@ -18,7 +18,7 @@ use crate::expr::{ChildName, ExprId, ExprVTable, ExpressionView, StatsCatalog, V
1818
///
1919
/// Expressions represent scalar computations that can be performed on data. Each
2020
/// expression consists of an encoding (vtable), heap-allocated metadata, and child expressions.
21-
#[derive(Clone, Debug)]
21+
#[derive(Clone)]
2222
pub struct Expression {
2323
/// The vtable for this expression.
2424
vtable: ExprVTable,
@@ -270,6 +270,33 @@ impl Display for Expression {
270270
}
271271
}
272272

273+
struct FormatExpressionData<'a> {
274+
vtable: &'a ExprVTable,
275+
data: &'a Arc<dyn Any + Send + Sync>,
276+
}
277+
278+
impl<'a> Debug for FormatExpressionData<'a> {
279+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
280+
self.vtable.as_dyn().fmt_data(self.data.as_ref(), f)
281+
}
282+
}
283+
284+
impl Debug for Expression {
285+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
286+
f.debug_struct("Expression")
287+
.field("vtable", &self.vtable)
288+
.field(
289+
"data",
290+
&FormatExpressionData {
291+
vtable: &self.vtable,
292+
data: &self.data,
293+
},
294+
)
295+
.field("children", &self.children)
296+
.finish()
297+
}
298+
}
299+
273300
impl PartialEq for Expression {
274301
fn eq(&self, other: &Self) -> bool {
275302
self.vtable.as_dyn().id() == other.vtable.as_dyn().id()

vortex-array/src/expr/exprs/binary.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,4 +587,19 @@ mod tests {
587587
DType::Bool(Nullability::Nullable)
588588
);
589589
}
590+
591+
#[test]
592+
fn test_debug_print() {
593+
let expr = gt(lit(1), lit(2));
594+
assert_eq!(
595+
format!("{expr:?}"),
596+
"Expression { vtable: vortex.binary, data: >, children: [Expression { vtable: vortex.literal, data: 1i32, children: [] }, Expression { vtable: vortex.literal, data: 2i32, children: [] }] }"
597+
);
598+
}
599+
600+
#[test]
601+
fn test_display_print() {
602+
let expr = gt(lit(1), lit(2));
603+
assert_eq!(format!("{expr}"), "(1i32 > 2i32)");
604+
}
590605
}

0 commit comments

Comments
 (0)