我想在spark中进行单词计数,我使用spark sql创建了一个rdd来从数据集中提取不同的推文 . 我想在RDD之上使用split函数,但它不允许我这样做 .
错误: - valuse split不是org.apache.spark.sql.SchemaRdd的成员
Spark代码无法进行字数统计: -
val disitnct_tweets=hiveCtx.sql("select distinct(text) from tweets_table where text <> ''")
val distinct_tweets_List=sc.parallelize(List(distinct_tweets))
//tried split on both the rdd disnt worked
distinct_tweets.flatmap(line => line.split(" ")).map(word => (word,1)).reduceByKey(_+_)
distinct_tweets_List.flatmap(line => line.split(" ")).map(word => (word,1)).reduceByKey(_+_)
但是,当我将sparksql中的数据输出到文件并再次加载并运行拆分时,它可以工作 .
有效的示例代码: -
val distinct_tweets=hiveCtx.sql("select dsitinct(text) from tweets_table where text <> ''")
val distinct_tweets_op=distinct_tweets.collect()
val rdd=sc.parallelize(distinct_tweets_op)
rdd.saveAsTextFile("/home/cloudera/bdp/op")
val textFile=sc.textFile("/home/cloudera/bdp/op/part-00000")
val counts=textFile.flatMap(line => line.split(" ")).map(word => (word,1)).reduceByKey(_+_)
counts.SaveAsTextFile("/home/cloudera/bdp/wordcount")
我需要一个答案而不是写入文件并再次加载以执行我的分割功能是否有解决功能的工作
谢谢