This is question based on answer from Sumit from below link
[Spark SQL: apply aggregate functions to a list of columns
Here are the details
val Claim1 = StructType(Seq(StructField("pid", StringType, true),StructField("diag1", StringType,
true),StructField("diag2", StringType, true), StructField("allowed", IntegerType, true),
StructField("allowed1", IntegerType, true)))
val claimsData1 = Seq(("PID1", "diag1", "diag2", 100, 200), ("PID1", "diag2", "diag3", 300, 600),
("PID1", "diag1", "diag5", 340, 680), ("PID2", "diag3", "diag4", 245, 490), ("PID2", "diag2",
"diag1", 124, 248))
val claimRDD1 = sc.parallelize(claimsData1)
val claimRDDRow1 = claimRDD1.map(p => Row(p._1, p._2, p._3, p._4, p._5))
val claimRDD2DF1 = sqlContext.createDataFrame(claimRDDRow1, Claim1)
val exprs = Map("allowed" -> "sum", "allowed1" -> "avg")
claimRDD2DF1.groupBy("pid").agg(exprs) show false
But it doesn't provide alias for naming the new column, I have a dataframe where I need to perform multiple aggregation for set of columns,it can be sum,avg,min,max on multiple sets of columns, So please let me know if there is a way to resolve the above issue or any better way to achieve this?
Thanks in advance.