2016-03-15 52 views
-1

JSON数据:Spark - Scala:当json数据分布在多行时,读取json文件为dataframe不起作用?

{ "blogID" : "FJY26J1333", "date" : "2012-04-01", 
"name" : "vpxnksu", "comment" : "good stuff"} 
{"blogID" : "VSAUMDFGSD", "date" : "2012-04-12", "name" : "yhftrcx", "comment" : "another comment"} 

代码:

val dataFrame=sqlContext.read.json("sample.json") 
dataFrame.show() 

输出:

_corrupt_record  blogID  comment   date  name 
{ "blogID" : "FJY... null  null    null  null 
"name" : "vpxnksu... null  null    null  null 
null     VSAUMDFGSD another comment 2012-04-12 yhftrcx 

我怎样才能把它读作两个记录?

回答

0

确保每行其一JSON对象,这样在源文件中:

{ "blogID" : "FJY26J1333", "date" : "2012-04-01", "name" : "vpxnksu", "comment" : "good stuff"} 
{ "blogID" : "VSAUMDFGSD", "date" : "2012-04-12", "name" : "yhftrcx", "comment" : "another comment"} 
+0

除了您刚才提出的问题,你没有解决它。你可能想要使用spark来处理petabytes的多行json文本文件为你所建议的文件格式,所以你又回过头来问如何使用spark来读取多行json文件。 –