需求:统计出指定磁盘目录下文件中的单词在哪些文件存在过:
文件具体内容
文件doc1.txt:
hello spark
hello hadoop
文件doc2.txt:
hello hive
hello hbase
hello spark
文件doc3.txt:
hadoop hbase
hive scala
我的实现方式:
package liwen.zhao.invert
import org.apache.spark.SparkContext
import org.apache.spark.SparkConf
object Driver {
def main(args: Array[String]): Unit = {
val conf=new SparkConf().setMaster("local").setAppName("workcount")
//创建spark上下文对象
val sc=new SparkContext(conf)
val data=sc.wholeTextFiles("E:\\tmp\\sparktest\\data\\inverted", 1).map{case(x,y)=>(x.split("/").takeRight(1)(0)->y.repla