I have a requirement to save partitions to the text file with different names for each partition. But while running below code snippet only one file is saving by overwriting the previous partition.
def chunks(iterator):
chunks.counter += 1
l = (list(iterator))
df = pd.DataFrame(l,index=None)
df.to_csv(parent_path+"C"+str(chunks.counter+1)+".txt", header=None, index=None, sep=' ')
chunks.counter=0
sc.parallelize([1,2,3,4,5,6],num_partions).foreachPartition(chunks)
Is there any way that I can know which partition is currently running in pySpark?