aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Armbrust <michael@databricks.com>2015-03-31 11:34:29 -0700
committerMichael Armbrust <michael@databricks.com>2015-03-31 11:34:52 -0700
commitbeebb7ffc21c66ae3e4c615555194d1e19ede1bb (patch)
tree83dd08c4f63010589de1a72c83dcf3c785e93c93
parentb5bd75d90a761199c3f9cb583c1fe48c8fda7780 (diff)
downloadspark-beebb7ffc21c66ae3e4c615555194d1e19ede1bb.tar.gz
spark-beebb7ffc21c66ae3e4c615555194d1e19ede1bb.tar.bz2
spark-beebb7ffc21c66ae3e4c615555194d1e19ede1bb.zip
[SPARK-5371][SQL] Propagate types after function conversion, before futher resolution
Before it was possible for a query to flip back and forth from a resolved state, allowing resolution to propagate up before coercion had stabilized. The issue was that `ResolvedReferences` would run after `FunctionArgumentConversion`, but before `PropagateTypes` had run. This PR ensures we correctly `PropagateTypes` after any coercion has applied. Author: Michael Armbrust <michael@databricks.com> Closes #5278 from marmbrus/unionNull and squashes the following commits: dc3581a [Michael Armbrust] [SPARK-5371][SQL] Propogate types after function conversion / before futher resolution
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala1
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicOperators.scala2
-rw-r--r--sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala26
3 files changed, 27 insertions, 2 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala
index 34ef7d28cc..3c7b46e070 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala
@@ -78,6 +78,7 @@ trait HiveTypeCoercion {
FunctionArgumentConversion ::
CaseWhenCoercion ::
Division ::
+ PropagateTypes ::
Nil
/**
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicOperators.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicOperators.scala
index 190209238a..8633e06093 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicOperators.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicOperators.scala
@@ -80,7 +80,7 @@ case class Union(left: LogicalPlan, right: LogicalPlan) extends BinaryNode {
override lazy val resolved: Boolean =
childrenResolved &&
- !left.output.zip(right.output).exists { case (l,r) => l.dataType != r.dataType }
+ left.output.zip(right.output).forall { case (l,r) => l.dataType == r.dataType }
override def statistics: Statistics = {
val sizeInBytes = left.statistics.sizeInBytes + right.statistics.sizeInBytes
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
index 2f50a33448..2065f0d60d 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
@@ -41,8 +41,32 @@ case class NestedArray1(a: NestedArray2)
*/
class SQLQuerySuite extends QueryTest {
+ test("SPARK-5371: union with null and sum") {
+ val df = Seq((1, 1)).toDF("c1", "c2")
+ df.registerTempTable("table1")
+
+ val query = sql(
+ """
+ |SELECT
+ | MIN(c1),
+ | MIN(c2)
+ |FROM (
+ | SELECT
+ | SUM(c1) c1,
+ | NULL c2
+ | FROM table1
+ | UNION ALL
+ | SELECT
+ | NULL c1,
+ | SUM(c2) c2
+ | FROM table1
+ |) a
+ """.stripMargin)
+ checkAnswer(query, Row(1, 1) :: Nil)
+ }
+
test("explode nested Field") {
- Seq(NestedArray1(NestedArray2(Seq(1,2,3)))).toDF.registerTempTable("nestedArray")
+ Seq(NestedArray1(NestedArray2(Seq(1, 2, 3)))).toDF.registerTempTable("nestedArray")
checkAnswer(
sql("SELECT ints FROM nestedArray LATERAL VIEW explode(a.b) a AS ints"),
Row(1) :: Row(2) :: Row(3) :: Nil)