There's not an easy way. The closest thing you can do is: import org.apache.spark.sql.functions._
val df = ... df.withColumn("id", monotonicallyIncreasingId()) -Andrew 2015-11-19 8:23 GMT-08:00 xiaohe lan <zombiexco...@gmail.com>: > Hi, > > I have some csv file in HDFS with headers like col1, col2, col3, I want to > add a column named id, so the a record would be <id, col1, col2, col3> > > How can I do this using Spark SQL ? Can id be auto increment ? > > Thanks, > Xiaohe >