Skip to content

Commit

Permalink
init import.
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Mar 17, 2016
1 parent 8ef3399 commit c2f9b05
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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}

Expand All @@ -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
}
})
}

/**
Expand Down

0 comments on commit c2f9b05

Please sign in to comment.