Skip to content

Commit

Permalink
[SQL] Fixed expression data type matching.
Browse files Browse the repository at this point in the history
There was a bug introduced by apache#5350
  • Loading branch information
rxin committed Apr 24, 2015
1 parent 6220d93 commit 336a36d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ abstract class CodeGenerator[InType <: AnyRef, OutType <: AnyRef] extends Loggin
org.apache.spark.sql.types.UTF8String(${eval.primitiveTerm}.toString)
""".children

case EqualTo(e1: BinaryType, e2: BinaryType) =>
case EqualTo(e1 @ BinaryType(), e2 @ BinaryType()) =>
(e1, e2).evaluateAs (BooleanType) {
case (eval1, eval2) =>
q"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,3 @@ class BinaryType private() extends AtomicType {

private[spark] override def asNullable: BinaryType = this
}


case object BinaryType extends BinaryType
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ import org.apache.spark.util.Utils
*/
@DeveloperApi
abstract class DataType {
/** Matches any expression that evaluates to this DataType */
def unapply(a: Expression): Boolean = a match {
/**
* Enables matching against NumericType for expressions:
* {{{
* case Cast(child @ BinaryType(), StringType) =>
* ...
* }}}
*/
private[sql] def unapply(a: Expression): Boolean = a match {
case e: Expression if e.dataType == this => true
case _ => false
}
Expand Down Expand Up @@ -104,12 +110,25 @@ abstract class NumericType extends AtomicType {


private[sql] object NumericType {
/**
* Enables matching against NumericType for expressions:
* {{{
* case Cast(child @ NumericType(), StringType) =>
* ...
* }}}
*/
def unapply(e: Expression): Boolean = e.dataType.isInstanceOf[NumericType]
}


/** Matcher for any expressions that evaluate to [[IntegralType]]s */
private[sql] object IntegralType {
/**
* Enables matching against IntegralType for expressions:
* {{{
* case Cast(child @ IntegralType(), StringType) =>
* ...
* }}}
*/
def unapply(a: Expression): Boolean = a match {
case e: Expression if e.dataType.isInstanceOf[IntegralType] => true
case _ => false
Expand All @@ -122,9 +141,14 @@ private[sql] abstract class IntegralType extends NumericType {
}



/** Matcher for any expressions that evaluate to [[FractionalType]]s */
private[sql] object FractionalType {
/**
* Enables matching against FractionalType for expressions:
* {{{
* case Cast(child @ FractionalType(), StringType) =>
* ...
* }}}
*/
def unapply(a: Expression): Boolean = a match {
case e: Expression if e.dataType.isInstanceOf[FractionalType] => true
case _ => false
Expand Down

0 comments on commit 336a36d

Please sign in to comment.