Here is my pyspark code:
mydf = df.groupby(key1,key2) .agg(collect_list(struct(key3)).alias("list2")) .groupby(key1)