Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/9929#discussion_r45785141
--- Diff: python/pyspark/sql/group.py ---
@@ -168,20 +168,24 @@ def sum(self, *cols):
"""
@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)
--- End diff --
Should we use `_to_java_column(pivot_col)` and `_to_seq()` here? or
`df.pivot(df.a)` may fail
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]