Skip to content

Commit

Permalink
bug in casewhen resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-wang committed Sep 3, 2014
1 parent e70aff6 commit eed35fc
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ case class CaseWhen(branches: Seq[Expression]) extends Expression {
false
} else {
val allCondBooleans = predicates.forall(_.dataType == BooleanType)
val dataTypesEqual = values.map(_.dataType).distinct.size <= 1
val valueTypes = branches.sliding(2, 2).map {
case Seq(_, value) => value.dataType
case Seq(elseVal) => elseVal.dataType
}.toSeq
val dataTypesEqual = valueTypes.distinct.size <= 1
allCondBooleans && dataTypesEqual
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NULL
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NULL
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NULL
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NULL
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NULL
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class HiveTypeCoercionSuite extends HiveComparisonTest {
}
}

val nullVal = "null"
baseTypes.init.foreach { i =>
createQueryTest(s"case when then $i else $nullVal end ", s"SELECT case when true then $i else $nullVal end FROM src limit 1")
createQueryTest(s"case when then $nullVal else $i end ", s"SELECT case when true then $nullVal else $i end FROM src limit 1")
}

test("[SPARK-2210] boolean cast on boolean value should be removed") {
val q = "select cast(cast(key=0 as boolean) as boolean) from src"
val project = TestHive.sql(q).queryExecution.executedPlan.collect { case e: Project => e }.head
Expand Down

0 comments on commit eed35fc

Please sign in to comment.