Skip to content

Commit

Permalink
[SPARK-12205][SQL] Pivot fails Analysis when aggregate is UnresolvedF…
Browse files Browse the repository at this point in the history
…unction

Delays application of ResolvePivot until all aggregates are resolved to prevent problems with UnresolvedFunction and adds unit test

Author: Andrew Ray <[email protected]>

Closes apache#10202 from aray/sql-pivot-unresolved-function.
  • Loading branch information
aray authored and yhuai committed Dec 8, 2015
1 parent 872a2ee commit 4bcb894
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class Analyzer(

object ResolvePivot extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan transform {
case p: Pivot if !p.childrenResolved => p
case p: Pivot if !p.childrenResolved | !p.aggregates.forall(_.resolved) => p
case Pivot(groupByExprs, pivotColumn, pivotValues, aggregates, child) =>
val singleAgg = aggregates.size == 1
val pivotAggregates: Seq[NamedExpression] = pivotValues.flatMap { value =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,12 @@ class DataFramePivotSuite extends QueryTest with SharedSQLContext{
sqlContext.conf.setConf(SQLConf.DATAFRAME_PIVOT_MAX_VALUES,
SQLConf.DATAFRAME_PIVOT_MAX_VALUES.defaultValue.get)
}

test("pivot with UnresolvedFunction") {
checkAnswer(
courseSales.groupBy("year").pivot("course", Seq("dotNET", "Java"))
.agg("earnings" -> "sum"),
Row(2012, 15000.0, 20000.0) :: Row(2013, 48000.0, 30000.0) :: Nil
)
}
}

0 comments on commit 4bcb894

Please sign in to comment.