diff options
author | Reynold Xin <rxin@databricks.com> | 2015-11-24 12:54:37 -0800 |
---|---|---|
committer | Reynold Xin <rxin@databricks.com> | 2015-11-24 12:54:37 -0800 |
commit | f3152722791b163fa66597b3684009058195ba33 (patch) | |
tree | c3b23ead8eaea14229f5b21642d2a4e8c5c191b2 /python | |
parent | 81012546ee5a80d2576740af0dad067b0f5962c5 (diff) | |
download | spark-f3152722791b163fa66597b3684009058195ba33.tar.gz spark-f3152722791b163fa66597b3684009058195ba33.tar.bz2 spark-f3152722791b163fa66597b3684009058195ba33.zip |
[SPARK-11946][SQL] Audit pivot API for 1.6.
Currently pivot's signature looks like
```scala
scala.annotation.varargs
def pivot(pivotColumn: Column, values: Column*): GroupedData
scala.annotation.varargs
def pivot(pivotColumn: String, values: Any*): GroupedData
```
I think we can remove the one that takes "Column" types, since callers should always be passing in literals. It'd also be more clear if the values are not varargs, but rather Seq or java.util.List.
I also made similar changes for Python.
Author: Reynold Xin <rxin@databricks.com>
Closes #9929 from rxin/SPARK-11946.
Diffstat (limited to 'python')
-rw-r--r-- | python/pyspark/sql/group.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/python/pyspark/sql/group.py b/python/pyspark/sql/group.py index 227f40bc3c..d8ed7eb2dd 100644 --- a/python/pyspark/sql/group.py +++ b/python/pyspark/sql/group.py @@ -168,20 +168,24 @@ class GroupedData(object): """ @since(1.6) - def pivot(self, pivot_col, *values): + def pivot(self, pivot_col, values=None): """Pivots a column of the current DataFrame and preform the specified aggregation. :param pivot_col: Column to pivot :param values: Optional list of values of pivotColumn that will be translated to columns in the output data frame. If values are not provided the method with do an immediate call to .distinct() on the pivot column. - >>> df4.groupBy("year").pivot("course", "dotNET", "Java").sum("earnings").collect() + + >>> df4.groupBy("year").pivot("course", ["dotNET", "Java"]).sum("earnings").collect() [Row(year=2012, dotNET=15000, Java=20000), Row(year=2013, dotNET=48000, Java=30000)] + >>> df4.groupBy("year").pivot("course").sum("earnings").collect() [Row(year=2012, Java=20000, dotNET=15000), Row(year=2013, Java=30000, dotNET=48000)] """ - jgd = self._jdf.pivot(_to_java_column(pivot_col), - _to_seq(self.sql_ctx._sc, values, _create_column_from_literal)) + if values is None: + jgd = self._jdf.pivot(pivot_col) + else: + jgd = self._jdf.pivot(pivot_col, values) return GroupedData(jgd, self.sql_ctx) |