scala> def getColAtIndex(id:Int): Column = col(s"column1")(id).as(s"column1_${id+1}") getColAtIndex: (id: Int)org.apache.spark.sql.Column scala> val columns: IndexedSeq[Column] = (0 to 2).map(getColAtIndex) :+ col("column2") //Here, instead of 2, you can give the value of n columns: IndexedSeq[org.apache.spark.sql.Column] = Vector(column1[0] AS `column1_1`, column1[1] AS `column1_2`, column1[2] AS `column1_3`, column2)