Skip to content

Commit

Permalink
Clena up
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Liu <[email protected]>

Clean up

Signed-off-by: Austin Liu <[email protected]>
  • Loading branch information
austin362667 committed Oct 2, 2024
1 parent 3337d66 commit 2ccaa96
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion datafusion/core/src/physical_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2558,7 +2558,7 @@ mod tests {
unimplemented!("NoOp");
}

fn allows_limit_to_inputs(&self) -> bool {
fn supports_limit_pushdown(&self) -> bool {
false // Disallow limit push-down by default
}
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/user_defined/user_defined_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl UserDefinedLogicalNodeCore for TopKPlanNode {
})
}

fn allows_limit_to_inputs(&self) -> bool {
fn supports_limit_pushdown(&self) -> bool {
false // Disallow limit push-down by default
}
}
Expand Down
28 changes: 20 additions & 8 deletions datafusion/expr/src/logical_plan/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,15 @@ pub trait UserDefinedLogicalNode: fmt::Debug + Send + Sync {
fn dyn_eq(&self, other: &dyn UserDefinedLogicalNode) -> bool;
fn dyn_ord(&self, other: &dyn UserDefinedLogicalNode) -> Option<Ordering>;

/// Indicates to the optimizer if its safe to push a limit down past
/// this extension node
fn allows_limit_to_inputs(&self) -> bool;
/// Returns `true` if a limit can be safely pushed down through this
/// `UserDefinedLogicalNode` node.
///
/// If this method returns `true`, and the query plan contains a limit at
/// the output of this node, DataFusion will push the limit to the input
/// of this node.
fn supports_limit_pushdown(&self) -> bool {
false
}
}

impl Hash for dyn UserDefinedLogicalNode {
Expand Down Expand Up @@ -300,9 +306,15 @@ pub trait UserDefinedLogicalNodeCore:
None
}

/// Indicates to the optimizer if its safe to push a limit down past
/// this extension node
fn allows_limit_to_inputs(&self) -> bool;
/// Returns `true` if a limit can be safely pushed down through this
/// `UserDefinedLogicalNode` node.
///
/// If this method returns `true`, and the query plan contains a limit at
/// the output of this node, DataFusion will push the limit to the input
/// of this node.
fn supports_limit_pushdown(&self) -> bool {
false // Disallow limit push-down by default
}
}

/// Automatically derive UserDefinedLogicalNode to `UserDefinedLogicalNode`
Expand Down Expand Up @@ -370,8 +382,8 @@ impl<T: UserDefinedLogicalNodeCore> UserDefinedLogicalNode for T {
.and_then(|other| self.partial_cmp(other))
}

fn allows_limit_to_inputs(&self) -> bool {
self.allows_limit_to_inputs()
fn supports_limit_pushdown(&self) -> bool {
self.supports_limit_pushdown()
}
}

Expand Down
2 changes: 1 addition & 1 deletion datafusion/optimizer/src/analyzer/subquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ mod test {
})
}

fn allows_limit_to_inputs(&self) -> bool {
fn supports_limit_pushdown(&self) -> bool {
false // Disallow limit push-down by default
}
}
Expand Down
4 changes: 2 additions & 2 deletions datafusion/optimizer/src/optimize_projections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ mod tests {
Some(vec![output_columns.to_vec()])
}

fn allows_limit_to_inputs(&self) -> bool {
fn supports_limit_pushdown(&self) -> bool {
false // Disallow limit push-down by default
}
}
Expand Down Expand Up @@ -996,7 +996,7 @@ mod tests {
Some(vec![left_reqs, right_reqs])
}

fn allows_limit_to_inputs(&self) -> bool {
fn supports_limit_pushdown(&self) -> bool {
false // Disallow limit push-down by default
}
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/optimizer/src/push_down_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ mod tests {
})
}

fn allows_limit_to_inputs(&self) -> bool {
fn supports_limit_pushdown(&self) -> bool {
false // Disallow limit push-down by default
}
}
Expand Down
12 changes: 3 additions & 9 deletions datafusion/optimizer/src/push_down_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,7 @@ impl OptimizerRule for PushDownLimit {
Ok(Transformed::yes(LogicalPlan::SubqueryAlias(subquery_alias)))
}
LogicalPlan::Extension(extension_plan)
if !extension_plan.node.allows_limit_to_inputs() =>
{
// If push down is not allowed, keep the original limit
original_limit(skip, fetch, LogicalPlan::Extension(extension_plan))
}
LogicalPlan::Extension(extension_plan)
if extension_plan.node.allows_limit_to_inputs() =>
if extension_plan.node.supports_limit_pushdown() =>
{
let new_children = extension_plan
.node
Expand Down Expand Up @@ -353,7 +347,7 @@ mod test {
})
}

fn allows_limit_to_inputs(&self) -> bool {
fn supports_limit_pushdown(&self) -> bool {
true // Allow limit push-down
}
}
Expand Down Expand Up @@ -406,7 +400,7 @@ mod test {
})
}

fn allows_limit_to_inputs(&self) -> bool {
fn supports_limit_pushdown(&self) -> bool {
false // Disallow limit push-down by default
}
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/optimizer/src/test/user_defined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl UserDefinedLogicalNodeCore for TestUserDefinedPlanNode {
})
}

fn allows_limit_to_inputs(&self) -> bool {
fn supports_limit_pushdown(&self) -> bool {
false // Disallow limit push-down by default
}
}
2 changes: 1 addition & 1 deletion datafusion/proto/tests/cases/roundtrip_logical_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ impl UserDefinedLogicalNodeCore for TopKPlanNode {
})
}

fn allows_limit_to_inputs(&self) -> bool {
fn supports_limit_pushdown(&self) -> bool {
false // Disallow limit push-down by default
}
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/substrait/tests/cases/roundtrip_logical_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl UserDefinedLogicalNode for MockUserDefinedLogicalPlan {
unimplemented!()
}

fn allows_limit_to_inputs(&self) -> bool {
fn supports_limit_pushdown(&self) -> bool {
false // Disallow limit push-down by default
}
}
Expand Down

0 comments on commit 2ccaa96

Please sign in to comment.