【文件属性】:
文件名称:spark集群安装
文件大小:879KB
文件格式:DOCX
更新时间:2021-12-23 15:38:54
spark
3.2.2.在spark shell中编写WordCount程序
1.首先启动hdfs
2.向hdfs上传一个文件到hdfs://hdp-01:9000/wordcount/input/a.txt
3.在spark shell中用scala语言编写spark程序
scala> sc.textFile("hdfs://hdp-01:9000/wordcount/input/")
spark是懒加载的,所以这里并没有真正执行任务。可使用collect方法快速查看数据。
lazy执行的,只有调用了action方法,才正式开始运行。
scala>sc.textFile("hdfs://hdp-01:9000/wordcount/input/").flatMap(_.split(" ")).map((_,1)).reduceByKey(_ + _).sortBy(_._2,false).collect
注意:这些flatMap,map等方法是R