Spark2 Dataset聚合操作

data.groupBy("gender").agg(count($"age"),max($"age").as("maxAge"), avg($"age").as("avgAge")).show
+------+----------+------+------+                                               
|gender|count(age)|maxAge|avgAge|
+------+----------+------+------+
|female|         5|  32.0|  29.0|
|  male|         5|  57.0|  39.0|
+------+----------+------+------+


data.groupBy("gender").agg("age"->"count","age" -> "max", "age" -> "avg").show
+------+----------+--------+--------+                                           
|gender|count(age)|max(age)|avg(age)|
+------+----------+--------+--------+
|female|         5|    32.0|    29.0|
|  male|         5|    57.0|    39.0|
+------+----------+--------+--------+

 

posted @ 2016-11-25 16:56  智能先行者  阅读(4608)  评论(0编辑  收藏  举报