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

Remove dead code in UnwrapCastExprRewriter that may mask errors #3703

Merged
merged 3 commits into from
Oct 7, 2022

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Oct 4, 2022

Which issue does this PR close?

re #3690

Rationale for this change

While reviewing code I found this code which may be masking errors

What changes are included in this PR?

Do not silently ignore errors getting schema

Are there any user-facing changes?

No

@alamb alamb requested a review from liukun4515 October 4, 2022 13:02
@github-actions github-actions bot added the optimizer Optimizer rules label Oct 4, 2022
Comment on lines -125 to -163
// can't get the data type, just return the expr
if left_type.is_err() || right_type.is_err() {
return Ok(expr.clone());
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we know for sure that this is dead code versus untested code?

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 do not know for sure. It is clearly untested

Copy link
Contributor

@liukun4515 liukun4515 Oct 6, 2022

Choose a reason for hiding this comment

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

Why we need to remove this code? @alamb
From the interface get_type which may return error like that:

            Expr::Wildcard => Err(DataFusionError::Internal(
                "Wildcard expressions are not valid in a logical query plan".to_owned(),
            )),
            Expr::QualifiedWildcard { .. } => Err(DataFusionError::Internal(
                "QualifiedWildcard expressions are not valid in a logical query plan"
                    .to_owned(),
            )),

Do we need to throw the error for this rule, when get an error with get_type of the expr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why we need to remove this code? @alamb

My thinking was that any such error is the result of some other issue with the planning or other pass; Thus, if we ignore the error in the UnwrapCastExprRewriter pass we make it harder to find and debug the real underlying problem.

It also has no test coverage (no test fails when this code is removed) which also makes me think all it will do is make debugging future errors harder

@liukun4515 if you think strongly this code should still be here it is fine with me and I will close the PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need to remove this code? @alamb

My thinking was that any such error is the result of some other issue with the planning or other pass; Thus, if we ignore the error in the UnwrapCastExprRewriter pass we make it harder to find and debug the real underlying problem.

It also has no test coverage (no test fails when this code is removed) which also makes me think all it will do is make debugging future errors harder

@liukun4515 if you think strongly this code should still be here it is fine with me and I will close the PR

agree with your comments

// can't get the data type, just return the expr
if left_type.is_err() || right_type.is_err() {
return Ok(expr.clone());
}
// Because the plan has been done the type coercion, the left and right must be equal
let left_type = left_type?;
let right_type = right_type?;
Copy link
Member

@andygrove andygrove Oct 5, 2022

Choose a reason for hiding this comment

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

I reviewed this again, and I think this is safe to remove. If we have expressions where we cannot determine the types then it indicates that an earlier rule has introduced an invalid expression.

I think the change could be slightly larger, replacing lines 123 through 131 just with:

                let left_type = left.get_type(&self.schema)?;
                let right_type = right.get_type(&self.schema)?;

Copy link
Contributor

Choose a reason for hiding this comment

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

If we need to throw the error when can't get_type of the expr, I think this fix maybe reasonable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

think the change could be slightly larger, replacing lines 123 through 131 just with:

Done in 139f08d

@alamb alamb changed the title Remove dead code in UnwrapCastExprRewriter Remove dead code in UnwrapCastExprRewriter that may mask errors Oct 6, 2022
@alamb alamb merged commit 4dd4d43 into apache:master Oct 7, 2022
@alamb alamb deleted the alamb/avoid_unecessary_check branch October 7, 2022 19:43
@ursabot
Copy link

ursabot commented Oct 7, 2022

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

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