-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters