简体   繁体   中英

Convert a RDD[(Long,Long)] to RDD[Row]

How do I convert a RDD[(Long, Long)] to RDD[Row]?

I require the RDD[Row] to convert to a DataFrame. The closest I got to an answer is How to convert RDD[Row] to RDD[Vector] but I want to do the opposite.

Just apply schema to your RDD (ref: spark-sql-programming-guide )

case class MyObjectType(col1:Long, col2:Long)

val myRDD:RDD[Long, Long] = .........
val myDF = myRDD.map(r=>MyObjectType(r._1, r._2)).toDF

now if you want to run sql over this df, you can register it as temp table

myDF.createOrReplaceTempView("my_table")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM