The original task was to append a column with row identificators (basically, a sequence 1 to numRows) to any given data frame, so the rows order/presence can be tracked (e.g. when you sample). This can be achieved by something along these lines:
map(case(d, i)=>i.toString + delimiter + d).
The "closest" approach to this functionality in Spark API are withColumn, withColumnRenamed and join.
You can also use row_number with Window function as below to get the distinct id for each rows in a dataframe. Also you can use monotonically_increasing_id for the same.
df.withColumn("ID", row_number() over Window.orderBy("any column name in the dataframe"))
If you want to know more about Spark, then do check out this awesome video tutorial: