spark daataframe 转换为json

调用spark 的隐式转换

scala> import spark.implicits._
import spark.implicits._

scala> val df=sc.parallelize(Array(("a",1),("b",2),("c",3)))

scala> df.show()
+---+---+                                                                       
| _1| _2|
+---+---+
|  a|  1|
|  b|  2|
|  c|  3|
+---+---+

scala> val jsonStr=df.toJSON.collect()
jsonStr: Array[String] = Array({"_1":"a","_2":1}, {"_1":"b","_2":2}, {"_1":"c","_2":3})

spark daataframe 转换为json

上一篇:特殊日期网站变灰


下一篇:jstack命令使用