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

Reduce redundancy in sort_enforcement tests #4928

Merged
merged 1 commit into from
Jan 17, 2023

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jan 17, 2023

Which issue does this PR close?

re #4943

Rationale for this change

Rationale: I am working on a bug related to sort enforcement and wanted to add a new test and the current structure was very hard to do without a lot of copy / paste.

What changes are included in this PR?

refactor repetition in sort_enforcement.rs tests into a macro

Are these changes tested?

Only tests

Are there any user-facing changes?

No -- there is no intended change in behavior

@github-actions github-actions bot added the core Core DataFusion crate label Jan 17, 2023
expected, actual_trim_last,
"\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n"
);
let source = memory_exec(&schema);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the new structure is much clearer about what the tests are doing -- if you look at the whitespace blind diff https://github.com/apache/arrow-datafusion/pull/4928/files?w=1 you can see that all the plans (original and optimized) are the same

@alamb
Copy link
Contributor Author

alamb commented Jan 17, 2023

cc @mustafasrepo and @mingmwang who I think have worked on this code

@mustafasrepo
Copy link
Contributor

This is much cleaner and more readable. Thanks @alamb.

@mingmwang
Copy link
Contributor

Nice !!

let sort_exprs = sort_exprs.into_iter().collect();
Arc::new(SortPreservingMergeExec::new(sort_exprs, input))
}

Copy link
Contributor

@mustafasrepo mustafasrepo Jan 17, 2023

Choose a reason for hiding this comment

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

Maybe we can add here one more function to encapsulate window exec creation

fn window_exec(
    input: Arc<dyn ExecutionPlan>,
    schema: SchemaRef,
    sort_exprs: &[PhysicalSortExpr],
    arg_column_name: &str,
) -> Result<Arc<dyn ExecutionPlan>> {
    Ok(Arc::new(WindowAggExec::try_new(
        vec![create_window_expr(
            &WindowFunction::AggregateFunction(AggregateFunction::Count),
            "count".to_owned(),
            &[col(arg_column_name, &schema)?],
            &[],
            sort_exprs,
            Arc::new(WindowFrame::new(true)),
            schema.as_ref(),
        )?],
        input,
        schema,
        vec![],
        Some(sort_exprs.to_vec()),
    )?) as Arc<dyn ExecutionPlan>)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

By the way this is just a suggestion. I think, with or without this change PR is ready to merge

// let filter_exec = sort_exec;
let window_agg_exec = Arc::new(WindowAggExec::try_new(
let physical_plan = Arc::new(WindowAggExec::try_new(
Copy link
Contributor

@mustafasrepo mustafasrepo Jan 17, 2023

Choose a reason for hiding this comment

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

given util function window_exec is available we can construct physical_plan with

let physical_plan = window_exec(
    filter.clone(),
    filter.schema(),
    &sort_exprs,
    "non_nullable_col",
)?;

as Arc<dyn ExecutionPlan>;
)];
let sort = sort_exec(sort_exprs.clone(), source);

let window_agg_exec = Arc::new(WindowAggExec::try_new(
Copy link
Contributor

Choose a reason for hiding this comment

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

given util function window_exec is available, we can use below snippet to create window_agg_exec

let window_agg_exec =
    window_exec(sort.clone(), sort.schema(), &sort_exprs, "non_nullable_col")?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you -- I was being lazy -- I will do so

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in #4945

@alamb
Copy link
Contributor Author

alamb commented Jan 17, 2023

Update #4943 is the bug I am working on with sort enforcement

@alamb
Copy link
Contributor Author

alamb commented Jan 17, 2023

Will implement suggestions in a follow on PR. Thank you for the review @mustafasrepo

@alamb alamb merged commit e7c2ef0 into apache:master Jan 17, 2023
@alamb alamb deleted the alamb/refactor_enforce_sort_tests branch January 17, 2023 12:14
@ursabot
Copy link

ursabot commented Jan 17, 2023

Benchmark runs are scheduled for baseline = 4e08117 and contender = e7c2ef0. e7c2ef0 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

alamb added a commit to alamb/datafusion that referenced this pull request Jan 17, 2023
alamb added a commit to alamb/datafusion that referenced this pull request Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants