Skip to content

Conversation

cloud-fan
Copy link
Contributor

What changes were proposed in this pull request?

This is a followup of #30849, to fix a correctness issue caused by null value handling.

Why are the changes needed?

Fix a correctness issue. If(null, true, false) should return false, not true.

Does this PR introduce any user-facing change?

Yes, but the bug only exist in the master branch.

How was this patch tested?

updated tests.

@github-actions github-actions bot added the SQL label Dec 28, 2020
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check result here to make sure there is no correctness issue.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

case p: LogicalPlan => p transformExpressions {
// For `EqualNullSafe` with a `TrueLiteral`, whether the other side is null or false has no
// difference, as `null <=> true` and `false <=> true` both return false.
case EqualNullSafe(left, TrueLiteral) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The change is needed here to not fail the existing tests. When we convert If to EqualNullSafe, we should make sure the rule ReplaceNullWithFalseInPredicate still applies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be great if someone can pull this out and open a separated PR/JIRA. Otherwise, I'll do it tomorrow.

Copy link
Member

Choose a reason for hiding this comment

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

NullPropagation should optimize EqualNullSafe(null, TrueLiteral) to false too, isn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can, but not with And, e.g. EqualNullSafe(col && null, true) => EqualNullSafe(col && false, true) => EqualNullSafe(false, true) => false.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see. Makes sense.

@cloud-fan
Copy link
Contributor Author

cc @wangyum @dongjoon-hyun @maropu @HyukjinKwon

Copy link
Member

@viirya viirya left a comment

Choose a reason for hiding this comment

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

Good catch!

@SparkQA
Copy link

SparkQA commented Dec 28, 2020

Test build #133457 has finished for PR 30953 at commit 34a5628.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, LGTM. Thank you, @cloud-fan and @viirya .
Merged to master.

@wangyum
Copy link
Member

wangyum commented Dec 29, 2020

Late LGTM.

@HyukjinKwon
Copy link
Member

Thanks, LGTM

@maropu
Copy link
Member

maropu commented Dec 29, 2020

good catch, late lgtm

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants