[Spark][Python][DataFrame][RDD]从DataFrame得到RDD的例子

[Spark][Python][DataFrame][RDD]从DataFrame得到RDD的例子

$ hdfs dfs -cat people.json

{"name":"Alice","pcode":"94304"}
{"name":"Brayden","age":30,"pcode":"94304"}
{"name":"Carla","age":19,"pcoe":"10036"}
{"name":"Diana","age":46}
{"name":"Etienne","pcode":"94104"}

 

$pyspark

sqlContext = HiveContext(sc)

peopleDF = sqlContext.read.json("people.json")

peopleRDD = peopleDF.rdd
peopleRDD.take(5)

[Row(age=None, name=u'Alice', pcode=u'94304', pcoe=None),
Row(age=30, name=u'Brayden', pcode=u'94304', pcoe=None),
Row(age=19, name=u'Carla', pcode=None, pcoe=u'10036'),
Row(age=46, name=u'Diana', pcode=None, pcoe=None),
Row(age=None, name=u'Etienne', pcode=u'94104', pcoe=None)]

 

posted @ 2017-10-07 16:24  健哥的数据花园  阅读(965)  评论(0编辑  收藏  举报