Skip to content

Commit 6e3b133

Browse files
committed
Remove DataFrame.pivot monster method
1 parent 1af796d commit 6e3b133

File tree

2 files changed

+0
-49
lines changed

2 files changed

+0
-49
lines changed

sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -988,41 +988,6 @@ class DataFrame private[sql](
988988
GroupedData(this, colNames.map(colName => resolve(colName)), GroupedData.CubeType)
989989
}
990990

991-
/**
992-
* (Scala-specific) Pivots a column of the current [[DataFrame]] and preform the specified
993-
* aggregation.
994-
* {{{
995-
* // Compute the sum of earnings for each year by course with each course as a separate column.
996-
* df.pivot(Seq($"year"), $"course", Seq("dotNET", "Java"), sum($"earnings"))
997-
* }}}
998-
* @param groupBy Columns to group by.
999-
* @param pivotColumn Column to pivot
1000-
* @param pivotValues Values of pivotColumn that will be translated to columns in the output data
1001-
* frame.
1002-
* @param aggregate Aggregate expression to preform for each combination of groupBy and
1003-
* pivotValues.
1004-
* @group dfops
1005-
* @since 1.6.0
1006-
*/
1007-
def pivot(
1008-
groupBy: Seq[Column],
1009-
pivotColumn: Column,
1010-
pivotValues: Seq[String],
1011-
aggregate: Column): DataFrame = {
1012-
1013-
val aliasedGroupBy = groupBy.map(_.expr).map {
1014-
// Wrap UnresolvedAttribute with UnresolvedAlias, as when we resolve UnresolvedAttribute, we
1015-
// will remove intermediate Alias for ExtractValue chain, and we need to alias it again to
1016-
// make it a NamedExpression.
1017-
case u: UnresolvedAttribute => UnresolvedAlias(u)
1018-
case expr: NamedExpression => expr
1019-
case expr: Expression => Alias(expr, expr.prettyString)()
1020-
}
1021-
1022-
new DataFrame(sqlContext,
1023-
Pivot(aliasedGroupBy, pivotColumn.expr, pivotValues, Seq(aggregate.expr), this.logicalPlan))
1024-
}
1025-
1026991
/**
1027992
* (Scala-specific) Aggregates on the entire [[DataFrame]] without groups.
1028993
* {{{

sql/core/src/test/scala/org/apache/spark/sql/DataFramePivotSuite.scala

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,6 @@ import org.apache.spark.sql.test.SharedSQLContext
2323
class DataFramePivotSuite extends QueryTest with SharedSQLContext{
2424
import testImplicits._
2525

26-
test("pivot courses") {
27-
checkAnswer(
28-
courseSales.pivot(Seq($"year"), $"course", Seq("dotNET", "Java"), sum($"earnings")),
29-
Row(2012, 15000.0, 20000.0) :: Row(2013, 48000.0, 30000.0) :: Nil
30-
)
31-
}
32-
33-
test("pivot year") {
34-
checkAnswer(
35-
courseSales.pivot(Seq($"course"), $"year", Seq("2012", "2013"), sum($"earnings")),
36-
Row("dotNET", 15000.0, 48000.0) :: Row("Java", 20000.0, 30000.0) :: Nil
37-
)
38-
}
39-
4026
test("pivot courses groupBy") {
4127
checkAnswer(
4228
courseSales.groupBy($"year").pivot($"course", "dotNET", "Java").agg(sum($"earnings")),

0 commit comments

Comments
 (0)