aboutsummaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorWenchen Fan <cloud0fan@outlook.com>2015-09-02 11:13:17 -0700
committerMichael Armbrust <michael@databricks.com>2015-09-02 11:13:17 -0700
commit56c4c172e99a5e14f4bc3308e7ff36d94113b63e (patch)
treeb0e1c78e2eafccb55524f26a0eff513c2e94c257 /sql
parentc3b881a7d7e4736f7131ff002a80e25def1f63af (diff)
downloadspark-56c4c172e99a5e14f4bc3308e7ff36d94113b63e.tar.gz
spark-56c4c172e99a5e14f4bc3308e7ff36d94113b63e.tar.bz2
spark-56c4c172e99a5e14f4bc3308e7ff36d94113b63e.zip
[SPARK-10034] [SQL] add regression test for Sort on Aggregate
Before #8371, there was a bug for `Sort` on `Aggregate` that we can't use aggregate expressions named `_aggOrdering` and can't use more than one ordering expressions which contains aggregate functions. The reason of this bug is that: The aggregate expression in `SortOrder` never get resolved, we alias it with `_aggOrdering` and call `toAttribute` which gives us an `UnresolvedAttribute`. So actually we are referencing aggregate expression by name, not by exprId like we thought. And if there is already an aggregate expression named `_aggOrdering` or there are more than one ordering expressions having aggregate functions, we will have conflict names and can't search by name. However, after #8371 got merged, the `SortOrder`s are guaranteed to be resolved and we are always referencing aggregate expression by exprId. The Bug doesn't exist anymore and this PR add regression tests for it. Author: Wenchen Fan <cloud0fan@outlook.com> Closes #8231 from cloud-fan/sort-agg.
Diffstat (limited to 'sql')
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala8
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala10
2 files changed, 18 insertions, 0 deletions
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
index 284fff1840..a4871e247c 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
@@ -887,4 +887,12 @@ class DataFrameSuite extends QueryTest with SharedSQLContext {
.select(struct($"b"))
.collect()
}
+
+ test("SPARK-10034: Sort on Aggregate with aggregation expression named 'aggOrdering'") {
+ val df = Seq(1 -> 2).toDF("i", "j")
+ val query = df.groupBy('i)
+ .agg(max('j).as("aggOrdering"))
+ .orderBy(sum('j))
+ checkAnswer(query, Row(1, 2))
+ }
}
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
index 9e172b2c26..28201073a2 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
@@ -1493,6 +1493,16 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
checkAnswer(
sql(
"""
+ |SELECT sum(b)
+ |FROM orderByData
+ |GROUP BY a
+ |ORDER BY sum(b), max(b)
+ """.stripMargin),
+ Row(3) :: Row(7) :: Row(11) :: Row(15) :: Nil)
+
+ checkAnswer(
+ sql(
+ """
|SELECT a, sum(b)
|FROM orderByData
|GROUP BY a