在学习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))
}
}
本文介绍了一个在使用SparkSQL时遇到的maprow:MissingParamenterType错误,并给出了具体的解决方案。通过在代码中添加importhiveCtx.implicits._,可以成功地将RDD转换为DataFrame,从而解决问题。
4475

被折叠的 条评论
为什么被折叠?



