错误提示:
Error:(19, 29) Unable to find encoder for type stored in a Dataset. Primitive types (Int, String, etc) and Product types (case classes) are supported by importing spark.implicits._ Support for serializing other types will be added in future releases.
var names =topTweets.map(row=>row.getString(0));
源代码
import com.alibaba.fastjson.{JSON, JSONObject}
import org.apache.spark.sql.{Encoders, Row}
import org.apache.spark.sql.hive.HiveContext
import org.apache.spark.{SparkConf, SparkContext}
object Testjson {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setMaster("local").setAppName("json test")
val sc = new SparkContext(conf)
val hiveCtx = new HiveContext(sc)
val input = hiveCtx.jsonFile("C:\\Users\\lyx\\Desktop\\Spark\\data.txt")
input.registerTempTable("tweets")
input.show()
val topTweets = hiveCtx.sql("SELECT explode(schemaName) from tweets")
topTweets.show()
var names =topTweets.map(row=>row.get(0));
}
}
修改后最后一行
var names =topTweets.rdd.map(row=>row.get(0)).foreach(println);