I was just studying some pyspark code and didnt understand these particular lines. I have a python code such as below:
emp = [("James", "Java", "4"),
("James", "R", "4"),
("James", "Python", "1"),
("Michael", "Java", "2"),
("Michael", "PHP", "4"),
("Michael", "PHP", "2"),
("Robert", "C#", "3"),
("Robert", "Java", "4"),
("Robert", "R", "1"),
("Washington", "Java", "2")
]
empColumns = ["name", "booksInterested", "id"]
empDF = spark.createDataFrame(data=emp, schema=empColumns)
empDF.show()
w = Window.partitionBy('id')
empDF = empDF.withColumn('e_array', F.collect_list('booksInterested').over(w))
empDF.show(truncate=False)
empDF = empDF.agg(F.max('e_array').alias('new_array'))
empDF.show(truncate=False)
When showing empDF after
empDF = empDF.agg(F.max('e_array').alias('new_array'))
Isn't it supposed to show the longest list? It is showing [Python , R] as the output ? I dont understand how is this output coming?