-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-13995][SQL] Extract correct IsNotNull constraints for Expression #11809
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
Changes from 1 commit
c2f9b05
b4e6033
d6bb43b
3d08625
5fa1760
c819572
3373396
56ca15f
c8fb736
81c46c7
6f7751d
8e8dd72
ec84c5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -202,3 +202,25 @@ object Unions { | |
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A pattern that finds the original expression from a sequence of casts. | ||
| */ | ||
| object Casts { | ||
| def unapply(expr: Expression): Option[Attribute] = expr match { | ||
| case c: Cast => collectCasts(expr) | ||
| case _ => None | ||
| } | ||
|
|
||
| private def collectCasts(e: Expression): Option[Attribute] = { | ||
| if (e.isInstanceOf[Cast]) { | ||
| collectCasts(e.children(0)) | ||
|
||
| } else { | ||
| if (e.isInstanceOf[Attribute]) { | ||
| Some(e.asInstanceOf[Attribute]) | ||
|
||
| } else { | ||
| None | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| package org.apache.spark.sql.catalyst.plans | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.planning.Casts | ||
| import org.apache.spark.sql.catalyst.trees.TreeNode | ||
| import org.apache.spark.sql.types.{DataType, StructType} | ||
|
|
||
|
|
@@ -36,6 +37,13 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]] extends TreeNode[PlanT | |
| .union(constructIsNotNullConstraints(constraints)) | ||
| .filter(constraint => | ||
| constraint.references.nonEmpty && constraint.references.subsetOf(outputSet)) | ||
| .map(_.transform { | ||
|
||
| case n @ IsNotNull(c) => | ||
| c match { | ||
| case Casts(a) if outputSet.contains(a) => IsNotNull(a) | ||
| case _ => n | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
Can use pattern matching to simplify this block. Perhaps something along the lines of:
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.
:)
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.
Great! Also add the tag
@tailrec?