在学习sparkSQL时,按照书中的例子敲了代码,但是报出map row:Missing Paramenter Type
的错误,意思就是没有指定row变量的类型。
当我在我的代码的val hiveCtx = new HiveContext(sc)
的下一行,添加import hiveCtx.implicits._
代码段之后,错误被解除了。因为这段代码会将RDD隐式转换为DataFrame
完整代码在下面贴出,希望可以帮助到你。
package spark.sparkSQL
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.sql.hive.HiveContext
object sparksql2 {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("sparksql").setMaster("local")
val sc = new SparkContext(conf)
sc.setLogLevel("ERROR")
val hiveCtx = new HiveContext(sc)
import hiveCtx.implicits._ // ImportType(hiveCtx.implicits)
val input = hiveCtx.jsonFile("./inputFile")
// Register the input schema RDD
input.registerTempTable("tweets")
hiveCtx.cacheTable("tweets")
// Select tweets based on the retweetCount
val topTweets = hiveCtx.sql("SELECT text, retweetCount FROM tweets ORDER BY retweetCount LIMIT 10")
topTweets.collect().map(println(_))
val topTweetText = topTweets.map(row => row.getString(0))
}
}