Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1f12ffe
moving enforce_distribution
logan-keede Jan 18, 2025
b58f9d6
formatting fix
logan-keede Jan 18, 2025
0d571a7
Update Cargo.toml
logan-keede Jan 18, 2025
24ab913
pulll source
logan-keede Jan 19, 2025
a7f8927
move_tests to core integration tests
logan-keede Jan 19, 2025
0296d04
remove tests from enforce_distribution.rs
logan-keede Jan 20, 2025
1d94407
Merge branch 'move_crates' of https://github.com/logan-keede/datafusi…
logan-keede Jan 20, 2025
7cd4b31
passes lint
buraksenn Jan 20, 2025
eb8ac39
forgotten license header
buraksenn Jan 20, 2025
8103f00
move enforce_sorting
logan-keede Jan 20, 2025
460c92d
merge main
buraksenn Jan 21, 2025
fef3c6e
import order
buraksenn Jan 21, 2025
7c1dad6
Merge branch 'move-enforce-sorting-to-new-crate' of https://github.co…
logan-keede Jan 21, 2025
dcbc0e1
merge fixes + formatting
logan-keede Jan 21, 2025
1f116e4
fix: forgotten license
logan-keede Jan 21, 2025
5093e61
fix: cargo fmt
logan-keede Jan 21, 2025
9c40e49
fix tests
buraksenn Jan 21, 2025
3d78ef2
Merge branch 'move-enforce-sorting-to-new-crate' of https://github.co…
logan-keede Jan 21, 2025
9d19863
fix: ci tests
logan-keede Jan 21, 2025
eba718a
fix: Cargo.toml formatting
logan-keede Jan 21, 2025
8926f90
Merge branch 'apache_main' into move_crates
berkaysynnada Jan 22, 2025
afb20f8
further removals
berkaysynnada Jan 22, 2025
f04332d
Further migrations and simplificaitons
berkaysynnada Jan 22, 2025
20d47d3
Fix failing tests
berkaysynnada Jan 22, 2025
b13ba8e
Final pass
berkaysynnada Jan 22, 2025
9e1dfbb
Update datafusion-testing
berkaysynnada Jan 22, 2025
b7373fb
Update test_utils.rs
berkaysynnada Jan 22, 2025
a8fe5ca
fix the dep
berkaysynnada Jan 22, 2025
99a419f
Update Cargo.toml
berkaysynnada Jan 22, 2025
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
1 change: 0 additions & 1 deletion datafusion/core/src/physical_optimizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
//!
//! [`ExecutionPlan`]: crate::physical_plan::ExecutionPlan

pub mod enforce_distribution;
pub mod enforce_sorting;
pub mod optimizer;
pub mod projection_pushdown;
Expand Down
2 changes: 2 additions & 0 deletions datafusion/physical-optimizer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ workspace = true

[features]
recursive_protection = ["dep:recursive"]
parquet = ["dep:parquet"]

[dependencies]
arrow = { workspace = true }
Expand All @@ -48,6 +49,7 @@ futures = { workspace = true }
itertools = { workspace = true }
log = { workspace = true }
recursive = { workspace = true, optional = true }
parquet = { workspace = true, optional = true, default-features = true }
Comment thread
logan-keede marked this conversation as resolved.
Outdated

[dev-dependencies]
datafusion-expr = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,30 @@
use std::fmt::Debug;
use std::sync::Arc;

use crate::config::ConfigOptions;
use crate::error::Result;
use crate::physical_optimizer::utils::{
use crate::optimizer::PhysicalOptimizerRule;
use crate::output_requirements::OutputRequirementExec;
use crate::utils::{
add_sort_above_with_check, is_coalesce_partitions, is_repartition,
is_sort_preserving_merge,
};
use crate::physical_plan::aggregates::{AggregateExec, AggregateMode, PhysicalGroupBy};
use crate::physical_plan::coalesce_partitions::CoalescePartitionsExec;
use crate::physical_plan::joins::{

use datafusion_common::config::ConfigOptions;
use datafusion_common::error::Result;

use datafusion_physical_plan::aggregates::{
AggregateExec, AggregateMode, PhysicalGroupBy,
};
use datafusion_physical_plan::coalesce_partitions::CoalescePartitionsExec;
use datafusion_physical_plan::joins::{
CrossJoinExec, HashJoinExec, PartitionMode, SortMergeJoinExec,
};
use crate::physical_plan::projection::ProjectionExec;
use crate::physical_plan::repartition::RepartitionExec;
use crate::physical_plan::sorts::sort_preserving_merge::SortPreservingMergeExec;
use crate::physical_plan::tree_node::PlanContext;
use crate::physical_plan::union::{can_interleave, InterleaveExec, UnionExec};
use crate::physical_plan::windows::WindowAggExec;
use crate::physical_plan::{Distribution, ExecutionPlan, Partitioning};
use datafusion_physical_plan::projection::ProjectionExec;
use datafusion_physical_plan::repartition::RepartitionExec;
use datafusion_physical_plan::sorts::sort_preserving_merge::SortPreservingMergeExec;
use datafusion_physical_plan::tree_node::PlanContext;
use datafusion_physical_plan::union::{can_interleave, InterleaveExec, UnionExec};
use datafusion_physical_plan::windows::WindowAggExec;
use datafusion_physical_plan::{Distribution, ExecutionPlan, Partitioning};

use arrow::compute::SortOptions;
use datafusion_common::stats::Precision;
Expand All @@ -53,8 +59,8 @@ use datafusion_physical_expr::{
physical_exprs_equal, EquivalenceProperties, PhysicalExpr, PhysicalExprRef,
};
use datafusion_physical_expr_common::sort_expr::LexOrdering;
use datafusion_physical_optimizer::output_requirements::OutputRequirementExec;
use datafusion_physical_optimizer::PhysicalOptimizerRule;
// use datafusion_physical_optimizer::output_requirements::OutputRequirementExec;
// use datafusion_physical_optimizer::PhysicalOptimizerRule;
use datafusion_physical_plan::execution_plan::EmissionType;
use datafusion_physical_plan::windows::{get_best_fitting_window, BoundedWindowAggExec};
use datafusion_physical_plan::ExecutionPlanProperties;
Expand Down
3 changes: 2 additions & 1 deletion datafusion/physical-optimizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
pub mod aggregate_statistics;
pub mod coalesce_batches;
pub mod combine_partial_final_agg;
pub mod enforce_distribution;
pub mod join_selection;
pub mod limit_pushdown;
pub mod limited_distinct_aggregation;
Expand All @@ -31,5 +32,5 @@ pub mod sanity_checker;
pub mod test_utils;
pub mod topk_aggregation;
pub mod update_aggr_exprs;

pub use optimizer::PhysicalOptimizerRule;
mod utils;
110 changes: 110 additions & 0 deletions datafusion/physical-optimizer/src/utils.rs
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

perhaps we can clean these up too

@logan-keede logan-keede Jan 18, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.
PS: you are talking about comments, right?

// 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>()
}