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

feat: prepare logical plan to logical plan without params/placeholders #4561

Merged
merged 4 commits into from
Dec 12, 2022

Conversation

NGA-TRAN
Copy link
Contributor

@NGA-TRAN NGA-TRAN commented Dec 9, 2022

Which issue does this PR close?

Closes #4550

Rationale for this change

Convert a Prepare Logical Plan into a Logical Plan with all params replaced with values

What changes are included in this PR?

. Recursively walk the logical plan and its expressions to find and replace Placeholders with corresponding values
. Add corresponding tests

Are these changes tested?

Yes

Are there any user-facing changes?

Not yet until this is integrated into physical plan

@github-actions github-actions bot added core Core DataFusion crate logical-expr Logical plan and expressions sql SQL Planner labels Dec 9, 2022
// Test prepare statement from sql to final result
// This test is equivalent with the test parallel_query_with_filter below but using prepare statement
#[tokio::test]
async fn test_prepare_statement() -> Result<()> {
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 want to have this test to verify my logical plan works correctly

let expected_dt = "whatever";

prepare_stmt_quick_test(sql, expected_plan, expected_dt);
logical_plan(sql).unwrap();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of calling prepare_stmt_quick_test that will first generate logical plan (and then panic for this test), I call logical_plan directly to simplify the test but still test the same things

let param_values = vec![ScalarValue::Int32(Some(10))];
let expected_plan = "Projection: person.id, person.age\
\n Filter: person.age = Int64(10)\
\n TableScan: person";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the available tests for prepare logical plan are used to replace params with values


#[test]
#[should_panic(expected = "value: Internal(\"Expected 1 parameters, got 0\")")]
fn test_prepare_statement_to_plan_one_param_no_value_panic() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And more panics are added for new functions

@NGA-TRAN
Copy link
Contributor Author

NGA-TRAN commented Dec 9, 2022

@alamb : this PR is ready for review

@NGA-TRAN NGA-TRAN changed the title feat: prepare logical plan to logicl plan without params/placeholders feat: prepare logical plan to logical plan without params/placeholders Dec 9, 2022
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @NGA-TRAN -- the test coverage looks wonderful to me and the feature works as advertised. I had a few code suggestions that I think would make the code much shorter and simpler to maintain but it would also be ok with me if this PR was merged and we cleaned it up as a follow on PR

Copy link
Contributor Author

@NGA-TRAN NGA-TRAN left a comment

Choose a reason for hiding this comment

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

Wow, how amazing your suggestions make the code a lot a lot shorter. I did ask myself yesterday "this recursive replacement must happen a lot and there must be an easy way to do so" but I could not find it and thought the reviewers would pointed them out. And it happen 🎉

I have a addressed them in this PR and will commit shortly

@NGA-TRAN
Copy link
Contributor Author

NGA-TRAN commented Dec 9, 2022

@alamb : Thanks for your amazing suggestions. I have addressed them in the PR. It is ready to merge after all the runs finish

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

LGTM -- thanks @NGA-TRAN

FYI @metesynnada @mingmwang as you reviewed other parts of this feature

@alamb
Copy link
Contributor

alamb commented Dec 10, 2022

I think this is ready to go. I'll plan to merge it Monday unless anyone else would like more time to review or has other comments

@alamb alamb merged commit 4ecf3e7 into apache:master Dec 12, 2022
@alamb
Copy link
Contributor

alamb commented Dec 12, 2022

Thanks again @NGA-TRAN

@ursabot
Copy link

ursabot commented Dec 13, 2022

Benchmark runs are scheduled for baseline = d33457c and contender = 4ecf3e7. 4ecf3e7 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

SSebo pushed a commit to SSebo/arrow-datafusion that referenced this pull request Feb 22, 2023
apache#4561)

* feat: prepare logical plan to logicl plan without params/placeholders

* fix: typo

* refactor: address review comments

* refactor: add index of the params/values into the error message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate logical-expr Logical plan and expressions sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert a Prepare Logical Plan into a Logical Plan with all parameters replaced with values
3 participants