Is there a way to use flatMap
to flatten a list in an rdd like so:
rdd = sc.parallelize([[1,2,3],[6,7,8]])
rdd.flatMap(lambda r: [[r[0],r[1],r[2],[r[2]+1,r[2]+2]]]).collect()
My desired output:
[[1,2,3,4,5],[6,7,8,9,10]]
The actual output:
[[1,2,3,[4,5]], [6,7,8,[9,10]]]
I understand flatMap
flattens the array appropriately, and I am not confused as to the actual output above, but I would like to know if there is a way to effectively flatten the inner list.