Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add name() method to UserDefinedLogicalNode #5450

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions datafusion/core/src/physical_plan/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2402,6 +2402,10 @@ Internal error: Optimizer rule 'type_coercion' failed due to unexpected error: E
self
}

fn name(&self) -> &str {
"NoOp"
}

fn inputs(&self) -> Vec<&LogicalPlan> {
vec![]
}
Expand Down
4 changes: 4 additions & 0 deletions datafusion/core/tests/user_defined_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ impl UserDefinedLogicalNode for TopKPlanNode {
self
}

fn name(&self) -> &str {
"TopK"
}

fn inputs(&self) -> Vec<&LogicalPlan> {
vec![&self.input]
}
Expand Down
3 changes: 3 additions & 0 deletions datafusion/expr/src/logical_plan/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub trait UserDefinedLogicalNode: fmt::Debug + Send + Sync {
/// Return a reference to self as Any, to support dynamic downcasting
fn as_any(&self) -> &dyn Any;

/// Return the plan's name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think similar information is present via

    fn fmt_for_explain(&self, f: &mut fmt::Formatter) -> fmt::Result;

For example: https://github.com/apache/arrow-datafusion/blob/a95e0ec2fd929aae1c2f67148243eb4825d81a3b/datafusion/proto/src/logical_plan/mod.rs#L1681-L1683

However, it is not easy to use (as you need a formatter, etc)

What would you think about making a function like the following that returned the result of format_for_explain

    fn to_string(&self) -> String {
       // figure out how to call format_for_explain here
     }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ignored the fmt_for_explain method... You are right, they are redundant information.

What would you think about making a function like the following that returned the result of format_for_explain

The returned string (like "TopK: k=1") is also not easy to use for the dispatching purpose, like we need to .contains() or .start_with() those strings. What do you think about separate name and parameters? E.g.:

fn name(&self) -> &'str {
  "TopK"
}

fn fmt_for_params(&self, f: &mut fmt::Formatter) -> fmt::Result { 
   write!(f, "k={}", self.k) 
}

// this can be provided as default implementation
fn fmt_for_explain(&self, f: &mut fmt::Formatter) -> fmt::Result { 
   write!(f, "{}: {}", self.name(), self.fmt_for_params()) 
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about separate name and parameters? E.g.:

I think it would make sense, but could also be done as a follow on PR. I think this PR is good enough for now.

Thanks @waynexia

fn name(&self) -> &str;

/// Return the logical plan's inputs
fn inputs(&self) -> Vec<&LogicalPlan>;

Expand Down
4 changes: 4 additions & 0 deletions datafusion/optimizer/src/push_down_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,10 @@ mod tests {
self
}

fn name(&self) -> &str {
"NoopPlan"
}

fn inputs(&self) -> Vec<&LogicalPlan> {
self.input.iter().collect()
}
Expand Down
4 changes: 4 additions & 0 deletions datafusion/optimizer/src/test/user_defined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ impl UserDefinedLogicalNode for TestUserDefinedPlanNode {
self
}

fn name(&self) -> &str {
"TestUserDefined"
}

fn inputs(&self) -> Vec<&LogicalPlan> {
vec![&self.input]
}
Expand Down
4 changes: 4 additions & 0 deletions datafusion/proto/src/logical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,10 @@ mod roundtrip_tests {
self
}

fn name(&self) -> &str {
"TopK"
}

fn inputs(&self) -> Vec<&LogicalPlan> {
vec![&self.input]
}
Expand Down