You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/11/09 09:35:17 UTC

[GitHub] [spark] zhengruifeng commented on a diff in pull request #38549: [SPARK-41026][CONNECT][PYTHON][FOLLOW-UP] Add Coalesce and Repartition API to Python client.

zhengruifeng commented on code in PR #38549:
URL: https://github.com/apache/spark/pull/38549#discussion_r1017687960


##########
python/pyspark/sql/connect/dataframe.py:
##########
@@ -156,8 +156,53 @@ def count(self) -> int:
     def crossJoin(self, other: "DataFrame") -> "DataFrame":
         ...
 
-    def coalesce(self, num_partitions: int) -> "DataFrame":
-        ...
+    def coalesce(self, numPartitions: int) -> "DataFrame":
+        """
+        Returns a new :class:`DataFrame` that has exactly `numPartitions` partitions.
+
+        Coalesce does not trigger a shuffle.
+
+        .. versionadded:: 3.4.0
+
+        Parameters
+        ----------
+        numPartitions : int
+            specify the target number of partitions
+
+        Returns
+        -------
+        :class:`DataFrame`
+        """
+        if not numPartitions > 0:
+            raise ValueError("numPartitions must be positive.")
+        return DataFrame.withPlan(
+            plan.Repartition(self._plan, num_partitions=numPartitions, shuffle=False),
+            self._session,
+        )
+
+    def repartition(self, numPartitions: int) -> "DataFrame":

Review Comment:
   should support `*cols` after `repartitionByExpression` added



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org