-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Move EnforceDistribution into datafusion-physical-optimizer crate
#14190
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
Changes from 3 commits
1f12ffe
b58f9d6
0d571a7
24ab913
a7f8927
0296d04
1d94407
7cd4b31
eb8ac39
8103f00
460c92d
fef3c6e
7c1dad6
dcbc0e1
1f116e4
5093e61
9c40e49
3d78ef2
9d19863
eba718a
8926f90
afb20f8
f04332d
20d47d3
b13ba8e
9e1dfbb
b7373fb
a8fe5ca
99a419f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| //! Collection of utility functions that are leveraged by the query optimizer rules | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| use datafusion_physical_plan::coalesce_partitions::CoalescePartitionsExec; | ||
| use datafusion_physical_plan::repartition::RepartitionExec; | ||
| use datafusion_physical_plan::sorts::sort::SortExec; | ||
| use datafusion_physical_plan::sorts::sort_preserving_merge::SortPreservingMergeExec; | ||
| // use datafusion_physical_plan::union::UnionExec; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps we can clean these up too
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept it because I thought it would need to be moved here sooner or later, but sure it can be cleaned. |
||
| // use datafusion_physical_plan::windows::{BoundedWindowAggExec, WindowAggExec}; | ||
| use datafusion_physical_plan::{ExecutionPlan, ExecutionPlanProperties}; | ||
|
|
||
| use datafusion_physical_expr::LexRequirement; | ||
| use datafusion_physical_expr_common::sort_expr::LexOrdering; | ||
| // use datafusion_physical_plan::limit::{GlobalLimitExec, LocalLimitExec}; | ||
| use datafusion_physical_plan::tree_node::PlanContext; | ||
|
|
||
| /// This utility function adds a `SortExec` above an operator according to the | ||
| /// given ordering requirements while preserving the original partitioning. | ||
| pub fn add_sort_above<T: Clone + Default>( | ||
| node: PlanContext<T>, | ||
| sort_requirements: LexRequirement, | ||
| fetch: Option<usize>, | ||
| ) -> PlanContext<T> { | ||
| let mut sort_expr = LexOrdering::from(sort_requirements); | ||
| sort_expr.retain(|sort_expr| { | ||
| !node | ||
| .plan | ||
| .equivalence_properties() | ||
| .is_expr_constant(&sort_expr.expr) | ||
| }); | ||
| let mut new_sort = SortExec::new(sort_expr, Arc::clone(&node.plan)).with_fetch(fetch); | ||
| if node.plan.output_partitioning().partition_count() > 1 { | ||
| new_sort = new_sort.with_preserve_partitioning(true); | ||
| } | ||
| PlanContext::new(Arc::new(new_sort), T::default(), vec![node]) | ||
| } | ||
|
|
||
| /// This utility function adds a `SortExec` above an operator according to the | ||
| /// given ordering requirements while preserving the original partitioning. If | ||
| /// requirement is already satisfied no `SortExec` is added. | ||
| pub fn add_sort_above_with_check<T: Clone + Default>( | ||
| node: PlanContext<T>, | ||
| sort_requirements: LexRequirement, | ||
| fetch: Option<usize>, | ||
| ) -> PlanContext<T> { | ||
| if !node | ||
| .plan | ||
| .equivalence_properties() | ||
| .ordering_satisfy_requirement(&sort_requirements) | ||
| { | ||
| add_sort_above(node, sort_requirements, fetch) | ||
| } else { | ||
| node | ||
| } | ||
| } | ||
|
|
||
| /// Checks whether the given operator is a limit; | ||
| /// i.e. either a [`LocalLimitExec`] or a [`GlobalLimitExec`]. | ||
| // pub fn is_limit(plan: &Arc<dyn ExecutionPlan>) -> bool { | ||
| // plan.as_any().is::<GlobalLimitExec>() || plan.as_any().is::<LocalLimitExec>() | ||
| // } | ||
|
|
||
| /// Checks whether the given operator is a window; | ||
| /// i.e. either a [`WindowAggExec`] or a [`BoundedWindowAggExec`]. | ||
| // pub fn is_window(plan: &Arc<dyn ExecutionPlan>) -> bool { | ||
| // plan.as_any().is::<WindowAggExec>() || plan.as_any().is::<BoundedWindowAggExec>() | ||
| // } | ||
|
|
||
| /// Checks whether the given operator is a [`SortExec`]. | ||
| // pub fn is_sort(plan: &Arc<dyn ExecutionPlan>) -> bool { | ||
| // plan.as_any().is::<SortExec>() | ||
| // } | ||
|
|
||
| /// Checks whether the given operator is a [`SortPreservingMergeExec`]. | ||
| pub fn is_sort_preserving_merge(plan: &Arc<dyn ExecutionPlan>) -> bool { | ||
| plan.as_any().is::<SortPreservingMergeExec>() | ||
| } | ||
|
|
||
| /// Checks whether the given operator is a [`CoalescePartitionsExec`]. | ||
| pub fn is_coalesce_partitions(plan: &Arc<dyn ExecutionPlan>) -> bool { | ||
| plan.as_any().is::<CoalescePartitionsExec>() | ||
| } | ||
|
|
||
| /// Checks whether the given operator is a [`UnionExec`]. | ||
| // pub fn is_union(plan: &Arc<dyn ExecutionPlan>) -> bool { | ||
| // plan.as_any().is::<UnionExec>() | ||
| // } | ||
|
|
||
| /// Checks whether the given operator is a [`RepartitionExec`]. | ||
| pub fn is_repartition(plan: &Arc<dyn ExecutionPlan>) -> bool { | ||
| plan.as_any().is::<RepartitionExec>() | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.