alamb commented on a change in pull request #9333:
URL: https://github.com/apache/arrow/pull/9333#discussion_r565654606
##########
File path: rust/datafusion/tests/user_defined_plan.rs
##########
@@ -209,51 +209,31 @@ struct TopKOptimizerRule {}
impl OptimizerRule for TopKOptimizerRule {
// Example rewrite pass to insert a user defined LogicalPlanNode
fn optimize(&self, plan: &LogicalPlan) -> Result<LogicalPlan> {
- match plan {
- // Note: this code simply looks for the pattern of a Limit
followed by a
- // Sort and replaces it by a TopK node. It does not handle many
- // edge cases (e.g multiple sort columns, sort ASC / DESC), etc.
- LogicalPlan::Limit { ref n, ref input } => {
- if let LogicalPlan::Sort {
- ref expr,
- ref input,
- } = **input
- {
- if expr.len() == 1 {
- // we found a sort with a single sort expr, replace
with a a TopK
- return Ok(LogicalPlan::Extension {
- node: Arc::new(TopKPlanNode {
- k: *n,
- input: self.optimize(input.as_ref())?,
- expr: expr[0].clone(),
- }),
- });
- }
+ // Note: this code simply looks for the pattern of a Limit followed by
a
+ // Sort and replaces it by a TopK node. It does not handle many
+ // edge cases (e.g multiple sort columns, sort ASC / DESC), etc.
+ if let LogicalPlan::Limit { ref n, ref input } = plan {
Review comment:
👍 much nicer
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]