转换一个RDD到数据帧中使用Scala星火 [英] Convert an RDD to a DataFrame in Spark using Scala

查看:251
本文介绍了转换一个RDD到数据帧中使用Scala星火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

textRDD:org.apache.spark.rdd.RDD [(字符串,字符串)]

我想将其转换为数据帧。列对应于每一页(行)的标题和内容。

I would like to convert it to a DataFrame. The columns correspond to the title and content of each page(row).

推荐答案

使用 toDF(),提供的列名,如果你有他们。

Use toDF(), provide the column names if you have them.

val textDF = textRDD.toDF("title": String, "content": String)
textDF: org.apache.spark.sql.DataFrame = [title: string, content: string]

val textDF = textRDD.toDF()
textDF: org.apache.spark.sql.DataFrame = [_1: string, _2: string]

壳自动进口(我用1.5版本),但您可能需要进口sqlContext.implicits ._ 在应用程序中。

这篇关于转换一个RDD到数据帧中使用Scala星火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆