-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
[SPARK-20121][SQL] simplify NullPropagation with NullIntolerant #17450
Conversation
cc @gatorsmile |
Test build #75298 has started for PR 17450 at commit |
retest this please |
Test build #75318 has finished for PR 17450 at commit
|
@@ -1122,7 +1119,7 @@ case class StringSpace(child: Expression) | |||
""") | |||
// scalastyle:on line.size.limit | |||
case class Substring(str: Expression, pos: Expression, len: Expression) | |||
extends TernaryExpression with ImplicitCastInputTypes { | |||
extends TernaryExpression with ImplicitCastInputTypes with NullIntolerant { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the function SUBSTRING null-intolerant? What is the return value if str
is a null value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result can be null; if any argument is null, the result is the null value.
Ref: https://www.ibm.com/support/knowledgecenter/en/SSEPEK_10.0.0/sqlref/src/tpc/db2z_bif_substr.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be confused with the terminologies: NullIntolerant expression versus "null-intolerant predicate". But if SUBSTRING is marked null-intolerant expression, why do we not mark the class of string functions such as STARTSWITH, etc. the same way? Am I missing anything here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should mark NullIntolerant
to the other expressions, if possible, and also update the document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nsyca If you have a bandwidth, could you please review all the expressions and see whether they can be marked as NullIntolerant
?
You can check the impl of these expressions and compare them with the corresponding ones in the other RDBMS. Thanks!
Below is a ref PR you can use: https://github.com/apache/spark/pull/15850/files. You can continue my work if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will certainly take a look. On a second thought, since "most" of the SQL functions are null-intolerant, isn't easier to mark only functions that are null-tolerant such as ISNOTNULL? I am just pitching an idea here, not indicating we should abandon this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the beginning, when we introduce NullIntolerant
, @marmbrus said we should do it more carefully. We prefer to using the white-list solution for avoiding hidden bugs. Marking it NullIntolerant
if and only if we are ensure that they are null intolerant. Thus, when we doing it, we should also add the corresponding test cases and documents.
// If the value expression is NULL then transform the In expression to | ||
// Literal(null) | ||
case In(Literal(null, _), list) => Literal.create(null, BooleanType) | ||
|
||
// Put exceptional cases above if any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Attribute
is also NullIntolerant
Maybe add a comment?
Non-leaf NullIntolerant
expressions will return null
, if at least one of its children is a null literal.
Great! LGTM except a minor comment. |
trait StringPredicate extends Predicate with ImplicitCastInputTypes { | ||
self: BinaryExpression => | ||
abstract class StringPredicate extends BinaryExpression | ||
with Predicate with ImplicitCastInputTypes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing with NullIntolerant
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is just to simplify the existing rule NullPropagation
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above StringRegexExpression
, similar to it, in order to simplify the NullPropagation
, we need to add NullIntolerant
, so it can propagate null value...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally got your point. StringPredicate
is used for inferring the null constants in the rule NullPropagation
. Thus, we should mark it as NullIntolerant
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. :-)
LGTM |
Test build #75390 has finished for PR 17450 at commit
|
retest this please |
Test build #75392 has finished for PR 17450 at commit
|
Thanks! Merging to master. |
What changes were proposed in this pull request?
Instead of iterating all expressions that can return null for null inputs, we can just check
NullIntolerant
.How was this patch tested?
existing tests