I work with a spark Dataframe and I try to create a new table with aggregation using groupby :
My data example :

and this is the desired result :

I tried this code data.groupBy("id1").agg(countDistinct("id2").alias("id2"), sum("value").alias("value"))
Anyone can help please ? Thank you