-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-52439][SQL] Support creating check constraint with NULL #51146
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
base: master
Are you sure you want to change the base?
Conversation
cc @aokolnychyi as well |
@@ -78,6 +78,7 @@ class V2ExpressionBuilder(e: Expression, isPredicate: Boolean = false) extends L | |||
expr: Expression, isPredicate: Boolean = false): Option[V2Expression] = expr match { | |||
case Literal(true, BooleanType) => Some(new AlwaysTrue()) | |||
case Literal(false, BooleanType) => Some(new AlwaysFalse()) | |||
case Cast(Literal(null, NullType), BooleanType, _, _) if isPredicate => Some(new AlwaysNull()) |
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.
why is it not constant folded to Literal(null, BooleanType)
?
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 happens in analyzer rule ResolveTableSpec
.
If we proactively constant folding it, the current-like expressions won't be resolved
* @since 4.1.0 | ||
*/ | ||
@Evolving | ||
public final class AlwaysNull extends Predicate implements Literal<Boolean> { |
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.
do we have to add it? can v2 Literal
do the work?
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.
It has to be a V2 Predicate:
https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala#L58
Also, having AlwaysNull besides AlwaysTrue
and AlwaysFalse
is reasonable.
What changes were proposed in this pull request?
Why are the changes needed?
Before the changes, there will be complation error if creating a check constraint with null
check(null)
. This PR fixes the issue.Does this PR introduce any user-facing change?
No
How was this patch tested?
New UT
Was this patch authored or co-authored using generative AI tooling?
No