Skip to content
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
2 changes: 1 addition & 1 deletion datafusion/expr/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ impl LogicalPlanBuilder {
/// Apply a filter which is used for a having clause
pub fn having(self, expr: impl Into<Expr>) -> Result<Self> {
let expr = normalize_col(expr.into(), &self.plan)?;
Filter::try_new_with_having(expr, self.plan)
Filter::try_new(expr, self.plan)
.map(LogicalPlan::Filter)
.map(Self::from)
}
Expand Down
23 changes: 7 additions & 16 deletions datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,9 @@ impl LogicalPlan {
// todo it isn't clear why the schema is not recomputed here
Ok(LogicalPlan::Values(Values { schema, values }))
}
LogicalPlan::Filter(Filter {
predicate,
input,
having,
}) => Filter::try_new_internal(predicate, input, having)
.map(LogicalPlan::Filter),
LogicalPlan::Filter(Filter { predicate, input }) => {
Filter::try_new(predicate, input).map(LogicalPlan::Filter)
}
LogicalPlan::Repartition(_) => Ok(self),
LogicalPlan::Window(Window {
input,
Expand Down Expand Up @@ -2259,8 +2256,6 @@ pub struct Filter {
pub predicate: Expr,
/// The incoming logical plan
pub input: Arc<LogicalPlan>,
/// The flag to indicate if the filter is a having clause
pub having: bool,
}

impl Filter {
Expand All @@ -2269,13 +2264,14 @@ impl Filter {
/// Notes: as Aliases have no effect on the output of a filter operator,
/// they are removed from the predicate expression.
pub fn try_new(predicate: Expr, input: Arc<LogicalPlan>) -> Result<Self> {
Self::try_new_internal(predicate, input, false)
Self::try_new_internal(predicate, input)
}

/// Create a new filter operator for a having clause.
/// This is similar to a filter, but its having flag is set to true.
#[deprecated(since = "48.0.0", note = "Use `try_new` instead")]
pub fn try_new_with_having(predicate: Expr, input: Arc<LogicalPlan>) -> Result<Self> {
Self::try_new_internal(predicate, input, true)
Self::try_new_internal(predicate, input)
}

fn is_allowed_filter_type(data_type: &DataType) -> bool {
Expand All @@ -2289,11 +2285,7 @@ impl Filter {
}
}

fn try_new_internal(
predicate: Expr,
input: Arc<LogicalPlan>,
having: bool,
) -> Result<Self> {
fn try_new_internal(predicate: Expr, input: Arc<LogicalPlan>) -> Result<Self> {
// Filter predicates must return a boolean value so we try and validate that here.
// Note that it is not always possible to resolve the predicate expression during plan
// construction (such as with correlated subqueries) so we make a best effort here and
Expand All @@ -2309,7 +2301,6 @@ impl Filter {
Ok(Self {
predicate: predicate.unalias_nested().data,
input,
having,
})
}

Expand Down
29 changes: 7 additions & 22 deletions datafusion/expr/src/logical_plan/tree_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,9 @@ impl TreeNode for LogicalPlan {
schema,
})
}),
LogicalPlan::Filter(Filter {
predicate,
input,
having,
}) => input.map_elements(f)?.update_data(|input| {
LogicalPlan::Filter(Filter {
predicate,
input,
having,
})
}),
LogicalPlan::Filter(Filter { predicate, input }) => input
.map_elements(f)?
.update_data(|input| LogicalPlan::Filter(Filter { predicate, input })),
LogicalPlan::Repartition(Repartition {
input,
partitioning_scheme,
Expand Down Expand Up @@ -509,17 +501,10 @@ impl LogicalPlan {
LogicalPlan::Values(Values { schema, values }) => values
.map_elements(f)?
.update_data(|values| LogicalPlan::Values(Values { schema, values })),
LogicalPlan::Filter(Filter {
predicate,
input,
having,
}) => f(predicate)?.update_data(|predicate| {
LogicalPlan::Filter(Filter {
predicate,
input,
having,
})
}),
LogicalPlan::Filter(Filter { predicate, input }) => f(predicate)?
.update_data(|predicate| {
LogicalPlan::Filter(Filter { predicate, input })
}),
LogicalPlan::Repartition(Repartition {
input,
partitioning_scheme,
Expand Down