You can use vectorAssembler
:
import org.apache.spark.ml.linalg.Vector
import org.apache.spark.mllib.linalg.Vectors
import org.apache.spark.ml.feature.VectorAssembler
val df = Seq((1,2),(3,4)).toDF("col1","col2")
val va = new VectorAssembler().setInputCols(Array("col1","col2")).setOutputCol("vector")
val row0 = va.transform(df).select("vector").collect()(0).getAs[Vector](0)
val vector0 = Vectors.fromML(row0)
// vector0: org.apache.spark.mllib.linalg.Vector = [1.0,2.0]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…