diff options
Diffstat (limited to 'sql')
3 files changed, 10 insertions, 2 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala index 3c58832d34..1957df89e6 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala @@ -477,7 +477,7 @@ class Analyzer( } else { val suffix = aggregate match { case n: NamedExpression => n.name - case _ => aggregate.sql + case _ => toPrettySQL(aggregate) } value + "_" + suffix } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala index 7853b22fec..e7079120bb 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala @@ -530,4 +530,12 @@ class DataFrameAggregateSuite extends QueryTest with SharedSQLContext { limit2Df.groupBy("id").count().select($"id"), limit2Df.select($"id")) } + + test("SPARK-17237 remove backticks in a pivot result schema") { + val df = Seq((2, 3, 4), (3, 4, 5)).toDF("a", "x", "y") + checkAnswer( + df.groupBy("a").pivot("x").agg(count("y"), avg("y")).na.fill(0), + Seq(Row(3, 0, 0.0, 1, 5.0), Row(2, 1, 4.0, 0, 0.0)) + ) + } } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/DataFramePivotSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/DataFramePivotSuite.scala index a8d854ccbc..51ffe34172 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/DataFramePivotSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/DataFramePivotSuite.scala @@ -200,7 +200,7 @@ class DataFramePivotSuite extends QueryTest with SharedSQLContext{ test("pivot preserves aliases if given") { assertResult( - Array("year", "dotNET_foo", "dotNET_avg(`earnings`)", "Java_foo", "Java_avg(`earnings`)") + Array("year", "dotNET_foo", "dotNET_avg(earnings)", "Java_foo", "Java_avg(earnings)") )( courseSales.groupBy($"year") .pivot("course", Seq("dotNET", "Java")) |