You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 7, 2025. It is now read-only.
feat: add data field in define_plan_node macro (#129)
Add a `data_name` field to `define_plan_node` macro. Plan nodes with
data field must implement a method `explain_data`.
**An example**
```rust
#[derive(Clone, Debug, Serialize, Deserialize)]
struct ComplexData {
a: i32,
b: String,
}
#[derive(Clone, Debug)]
struct PhysicalComplexDummy(PlanNode);
impl PhysicalComplexDummy {
pub fn explain_data(data: &Value) -> Vec<(&'static str, Pretty<'static>)> {
if let Value::Serialized(serialized_data) = data {
let data: ComplexData = bincode::deserialize(serialized_data).unwrap();
vec![
("a", data.a.to_string().into()),
("b", data.b.to_string().into()),
]
} else {
unreachable!()
}
}
}
define_plan_node!(
PhysicalComplexDummy: PlanNode,
PhysicalScan, [
{ 0, child: PlanNode }
], [
],
complex_data
);
```
I could just print data with `format!("{:?}, data)`, but the downside of
this is that for a struct
```rust
struct Foo {
a: i32,
b: i32,
}
```
The debug output would be `Foo { a: 1, b: 2}`. Here, the struct name is
implementation detail that should be hidden from the user, and the
bracket surrounding the fields makes these fields seem related in some
way, when they are actually not. So just letting user implement
`explain_data` gives maximum flexibility.
0 commit comments