I am trying to add a new column to my spark DF. I understand the following code can be used:
df.withColumn("row",monotonically_increasing_id)
But my use case is:
Input DF:
col value
1
2
2
3
3
3
Output DF:
col_value identifier
1 1
2 1
2 2
3 1
3 2
3 3
Any suggestions on getting this with monotonically_increasing or rowWithUniqueIndex.