Przeglądaj źródła

Rewrite aggregation

theenglishway (time) 2 lat temu
rodzic
commit
e28da8cd79
1 zmienionych plików z 7 dodań i 2 usunięć
  1. 7 2
      src/main/scala/spark.worksheet.sc

+ 7 - 2
src/main/scala/spark.worksheet.sc

@@ -6,7 +6,7 @@ val spark = SparkSession
   .config("spark.master", "local")
   .getOrCreate()
 
-import org.apache.spark.sql.functions.when
+import org.apache.spark.sql.functions.{when, sum}
 import spark.implicits._
 
 def readInput(filePath: String) = {
@@ -73,7 +73,12 @@ stats_games.count()
 
 val stats_games_pts = stats_games
   .groupBy($"game.id".alias("game_id"), $"team.id".alias("team_id"))
-  .agg(Map("pts" -> "sum", "ast" -> "sum", "blk" -> "sum", "reb" -> "sum"))
+  .agg(
+    sum($"pts").alias("pts"),
+    sum($"ast").alias("ast"),
+    sum($"blk").alias("blk"),
+    sum($"reb").alias("reb")
+  )
 stats_games_pts.show()
 
 val teams_games = teams_df