Skip to content
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

Minor: Reduce even more redundancy creating window_agg in sort_enforcement tests #4945

Merged
merged 2 commits into from
Jan 18, 2023
Merged
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
65 changes: 33 additions & 32 deletions datafusion/core/src/physical_optimizer/sort_enforcement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,32 +671,18 @@ mod tests {
)];
let sort = sort_exec(sort_exprs.clone(), source);

let window_agg_exec = Arc::new(WindowAggExec::try_new(
vec![create_window_expr(
&WindowFunction::AggregateFunction(AggregateFunction::Count),
"count".to_owned(),
&[col("non_nullable_col", &schema)?],
&[],
&sort_exprs,
Arc::new(WindowFrame::new(true)),
schema.as_ref(),
)?],
sort.clone(),
sort.schema(),
vec![],
Some(sort_exprs),
)?) as Arc<dyn ExecutionPlan>;
let window_agg = window_exec("non_nullable_col", sort_exprs, sort);

let sort_exprs = vec![sort_expr_options(
"non_nullable_col",
&window_agg_exec.schema(),
&window_agg.schema(),
SortOptions {
descending: false,
nulls_first: false,
},
)];

let sort = sort_exec(sort_exprs.clone(), window_agg_exec);
let sort = sort_exec(sort_exprs.clone(), window_agg);

// Add dummy layer propagating Sort above, to test whether sort can be removed from multi layer before
let filter = filter_exec(
Expand All @@ -707,21 +693,7 @@ mod tests {
);

// let filter_exec = sort_exec;
let physical_plan = Arc::new(WindowAggExec::try_new(
vec![create_window_expr(
&WindowFunction::AggregateFunction(AggregateFunction::Count),
"count".to_owned(),
&[col("non_nullable_col", &schema)?],
&[],
&sort_exprs,
Arc::new(WindowFrame::new(true)),
schema.as_ref(),
)?],
filter.clone(),
filter.schema(),
vec![],
Some(sort_exprs),
)?) as Arc<dyn ExecutionPlan>;
let physical_plan = window_exec("non_nullable_col", sort_exprs, filter);

let expected_input = vec![
"WindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }]",
Expand Down Expand Up @@ -888,6 +860,35 @@ mod tests {
Arc::new(FilterExec::try_new(predicate, input).unwrap())
}

fn window_exec(
col_name: &str,
sort_exprs: impl IntoIterator<Item = PhysicalSortExpr>,
input: Arc<dyn ExecutionPlan>,
) -> Arc<dyn ExecutionPlan> {
let sort_exprs: Vec<_> = sort_exprs.into_iter().collect();
let schema = input.schema();

Arc::new(
WindowAggExec::try_new(
vec![create_window_expr(
&WindowFunction::AggregateFunction(AggregateFunction::Count),
"count".to_owned(),
&[col(col_name, &schema).unwrap()],
&[],
&sort_exprs,
Arc::new(WindowFrame::new(true)),
schema.as_ref(),
)
.unwrap()],
input.clone(),
input.schema(),
vec![],
Some(sort_exprs),
)
.unwrap(),
)
}

/// Create a non sorted parquet exec
fn parquet_exec(schema: &SchemaRef) -> Arc<ParquetExec> {
Arc::new(ParquetExec::new(
Expand Down