aboutsummaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorYin Huai <yhuai@databricks.com>2015-07-06 16:26:31 -0700
committerMichael Armbrust <michael@databricks.com>2015-07-06 16:28:47 -0700
commit7b467cc9348fa910e445ad08914a72f8ed4fc249 (patch)
tree1141417169582c2c4e82a9415172d5efcd213f25 /sql
parent0effe180f4c2cf37af1012b33b43912bdecaf756 (diff)
downloadspark-7b467cc9348fa910e445ad08914a72f8ed4fc249.tar.gz
spark-7b467cc9348fa910e445ad08914a72f8ed4fc249.tar.bz2
spark-7b467cc9348fa910e445ad08914a72f8ed4fc249.zip
[SPARK-8588] [SQL] Regression test
This PR adds regression test for https://issues.apache.org/jira/browse/SPARK-8588 (fixed by https://github.com/apache/spark/commit/457d07eaa023b44b75344110508f629925eb6247). Author: Yin Huai <yhuai@databricks.com> This patch had conflicts when merged, resolved by Committer: Michael Armbrust <michael@databricks.com> Closes #7103 from yhuai/SPARK-8588-test and squashes the following commits: eb5f418 [Yin Huai] Add a query test. c61a173 [Yin Huai] Regression test for SPARK-8588.
Diffstat (limited to 'sql')
-rw-r--r--sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercionSuite.scala21
-rw-r--r--sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala16
2 files changed, 37 insertions, 0 deletions
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercionSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercionSuite.scala
index b564266177..93db33d44e 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercionSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercionSuite.scala
@@ -271,4 +271,25 @@ class HiveTypeCoercionSuite extends PlanTest {
Literal(true)
)
}
+
+ /**
+ * There are rules that need to not fire before child expressions get resolved.
+ * We use this test to make sure those rules do not fire early.
+ */
+ test("make sure rules do not fire early") {
+ // InConversion
+ val inConversion = HiveTypeCoercion.InConversion
+ ruleTest(inConversion,
+ In(UnresolvedAttribute("a"), Seq(Literal(1))),
+ In(UnresolvedAttribute("a"), Seq(Literal(1)))
+ )
+ ruleTest(inConversion,
+ In(Literal("test"), Seq(UnresolvedAttribute("a"), Literal(1))),
+ In(Literal("test"), Seq(UnresolvedAttribute("a"), Literal(1)))
+ )
+ ruleTest(inConversion,
+ In(Literal("a"), Seq(Literal(1), Literal("b"))),
+ In(Literal("a"), Seq(Cast(Literal(1), StringType), Cast(Literal("b"), StringType)))
+ )
+ }
}
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 6d645393a6..bf9f2ecd51 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
@@ -990,5 +990,21 @@ class SQLQuerySuite extends QueryTest {
Timestamp.valueOf("1969-12-31 16:00:00"),
String.valueOf("1969-12-31 16:00:00"),
Timestamp.valueOf("1970-01-01 00:00:00")))
+
+ }
+
+ test("SPARK-8588 HiveTypeCoercion.inConversion fires too early") {
+ val df =
+ TestHive.createDataFrame(Seq((1, "2014-01-01"), (2, "2015-01-01"), (3, "2016-01-01")))
+ df.toDF("id", "date").registerTempTable("test_SPARK8588")
+ checkAnswer(
+ TestHive.sql(
+ """
+ |select id, concat(year(date))
+ |from test_SPARK8588 where concat(year(date), ' year') in ('2015 year', '2014 year')
+ """.stripMargin),
+ Row(1, "2014") :: Row(2, "2015") :: Nil
+ )
+ TestHive.dropTempTable("test_SPARK8588")
}
}