import org.apache.spark.sql.functions._
df.withColumn("id", monotonically_increasing_id)