Skip to content

add a checker to confirm optimizer can keep plan schema immutable. - #4233

Merged
andygrove merged 2 commits into
apache:masterfrom
jackwener:check
Nov 17, 2022
Merged

andygrove merged 2 commits into
apache:masterfrom
jackwener:check

Conversation

@jackwener

@jackwener jackwener commented Nov 16, 2022 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #.

In the previous code, we did not verify whether the schema is equal, which may cause some problems.

We can add a checkrt to confirm optimizer can keep plan schema immutable.

Rationale for this change

It's found when I try wo add a new rule.

What changes are included in this PR?

add a checker to confirm optimizer can keep plan schema immutable.

Are these changes tested?

Are there any user-facing changes?

@jackwener jackwener changed the title add a check to confirm optimizer can keep plan schema immutable. add a checker to confirm optimizer can keep plan schema immutable. Nov 16, 2022
@github-actions github-actions Bot added the optimizer Optimizer rules label Nov 16, 2022
@jackwener
jackwener marked this pull request as ready for review November 16, 2022 06:05
match result {
Ok(Some(plan)) => {
if plan.schema() != new_plan.schema() {
return Err(DataFusionError::Internal(format!(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we include the expected and actual schema in the error message? This will make debugging much easier.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, could you add a unit test?

@andygrove

Copy link
Copy Markdown
Member

Thanks @jackwener. This is a good improvement. Could you fill out the PR description? It helps with the reviews.

@jackwener

Copy link
Copy Markdown
Member Author

Thanks @andygrove review.
polish error message to add the expected and actual schema, and add a UT.

@mingmwang

Copy link
Copy Markdown
Contributor

This is really nice!

@mingmwang

Copy link
Copy Markdown
Contributor

I think we also need to do the same check for physical optimizer.

@github-actions github-actions Bot added core Core DataFusion crate and removed core Core DataFusion crate labels Nov 17, 2022

@andygrove andygrove left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very nice. Thanks @jackwener

@andygrove

Copy link
Copy Markdown
Member

I think we also need to do the same check for physical optimizer.

Sounds like a good idea. Do you want to file an issue for that?

@andygrove
andygrove merged commit 5ed40e0 into apache:master Nov 17, 2022
@ursabot

ursabot commented Nov 17, 2022

Copy link
Copy Markdown

Benchmark runs are scheduled for baseline = 6f62870 and contender = 5ed40e0. 5ed40e0 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

@jackwener
jackwener deleted the check branch November 18, 2022 07:40
@mingmwang

Copy link
Copy Markdown
Contributor

I think we also need to do the same check for physical optimizer.

Sounds like a good idea. Do you want to file an issue for that?

Yes, track this via #4299

Comment on lines +228 to +229
if plan.schema() != new_plan.schema() {
return Err(DataFusionError::Internal(format!(

@mingmwang mingmwang Nov 21, 2022 •

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.

@jackwener
Is it possible that the check can not always pass in case that some of the optimization rules might change the nullability of the Schema ?
For example a Column Expression was replaced by a Literal Constant due to Constant propagation ?

select max(t1.id) from (select 123 as id ) as t1 where t1.id = 123;

@jackwener jackwener Nov 21, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Indeed, we may need to relax restrictions on some conditions, such as nullable.
In this way we can get more room for optimization.
But in most cases, we don't need to do this, we can wait until we need to do this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants