I am trying to replicate the given code to see how foreach
works, I tried with the following code:
rdd = sc.parallelize([1,2,3,4,5])
def f(a):
print(a)
rdd.collect().foreach(f)
But it gives the following error:
AttributeError: 'list' object has no attribute 'foreach'
I understand the error that return type of collect()
is a array
(which is list) and it doesn't have foreach
attribute associated with it but, I don't understand how this doesn't work if it's given in the official spark 3.0.1
documentation. What am I missing. I am using Spark 3.0.1