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/24 06:37:40 UTC

[GitHub] [spark] zhengruifeng commented on a diff in pull request #38768: [SPARK-41230][CONNECT][PYTHON] Remove `str` from Aggregate expression type

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


##########
python/pyspark/sql/connect/dataframe.py:
##########
@@ -51,24 +52,11 @@
 
 
 class GroupingFrame(object):

Review Comment:
   not related to this PR, but shall we rename it `GroupedData` to be the same with pyspark?



##########
python/pyspark/sql/connect/dataframe.py:
##########
@@ -164,8 +156,20 @@ def selectExpr(self, *expr: Union[str, List[str]]) -> "DataFrame":
 
         return DataFrame.withPlan(plan.Project(self._plan, *sql_expr), session=self._session)
 
-    def agg(self, exprs: Optional[GroupingFrame.MeasuresType]) -> "DataFrame":
-        return self.groupBy().agg(exprs)
+    def agg(self, *exprs: Union[Expression, Dict[str, str]]) -> "DataFrame":
+        if not exprs:
+            raise ValueError("Argument 'exprs' must not be empty")
+
+        if len(exprs) == 1 and isinstance(exprs[0], dict):
+            measures = []
+            for e, fun in exprs[0].items():
+                measures.append(ScalarFunctionExpression(fun, Column(e)))

Review Comment:
   ```suggestion
               measures = [ScalarFunctionExpression(f, Column(e)) for e, f in exprs[0].items()]
   ```



-- 
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