Skip to content

Commit 336a36d

Browse files
committed
[SQL] Fixed expression data type matching.
There was a bug introduced by apache#5350
1 parent 6220d93 commit 336a36d

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ abstract class CodeGenerator[InType <: AnyRef, OutType <: AnyRef] extends Loggin
279279
org.apache.spark.sql.types.UTF8String(${eval.primitiveTerm}.toString)
280280
""".children
281281

282-
case EqualTo(e1: BinaryType, e2: BinaryType) =>
282+
case EqualTo(e1 @ BinaryType(), e2 @ BinaryType()) =>
283283
(e1, e2).evaluateAs (BooleanType) {
284284
case (eval1, eval2) =>
285285
q"""

sql/catalyst/src/main/scala/org/apache/spark/sql/types/BinaryType.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,3 @@ class BinaryType private() extends AtomicType {
5858

5959
private[spark] override def asNullable: BinaryType = this
6060
}
61-
62-
63-
case object BinaryType extends BinaryType

sql/catalyst/src/main/scala/org/apache/spark/sql/types/DataType.scala

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ import org.apache.spark.util.Utils
4040
*/
4141
@DeveloperApi
4242
abstract class DataType {
43-
/** Matches any expression that evaluates to this DataType */
44-
def unapply(a: Expression): Boolean = a match {
43+
/**
44+
* Enables matching against NumericType for expressions:
45+
* {{{
46+
* case Cast(child @ BinaryType(), StringType) =>
47+
* ...
48+
* }}}
49+
*/
50+
private[sql] def unapply(a: Expression): Boolean = a match {
4551
case e: Expression if e.dataType == this => true
4652
case _ => false
4753
}
@@ -104,12 +110,25 @@ abstract class NumericType extends AtomicType {
104110

105111

106112
private[sql] object NumericType {
113+
/**
114+
* Enables matching against NumericType for expressions:
115+
* {{{
116+
* case Cast(child @ NumericType(), StringType) =>
117+
* ...
118+
* }}}
119+
*/
107120
def unapply(e: Expression): Boolean = e.dataType.isInstanceOf[NumericType]
108121
}
109122

110123

111-
/** Matcher for any expressions that evaluate to [[IntegralType]]s */
112124
private[sql] object IntegralType {
125+
/**
126+
* Enables matching against IntegralType for expressions:
127+
* {{{
128+
* case Cast(child @ IntegralType(), StringType) =>
129+
* ...
130+
* }}}
131+
*/
113132
def unapply(a: Expression): Boolean = a match {
114133
case e: Expression if e.dataType.isInstanceOf[IntegralType] => true
115134
case _ => false
@@ -122,9 +141,14 @@ private[sql] abstract class IntegralType extends NumericType {
122141
}
123142

124143

125-
126-
/** Matcher for any expressions that evaluate to [[FractionalType]]s */
127144
private[sql] object FractionalType {
145+
/**
146+
* Enables matching against FractionalType for expressions:
147+
* {{{
148+
* case Cast(child @ FractionalType(), StringType) =>
149+
* ...
150+
* }}}
151+
*/
128152
def unapply(a: Expression): Boolean = a match {
129153
case e: Expression if e.dataType.isInstanceOf[FractionalType] => true
130154
case _ => false

0 commit comments

Comments
 (0)