zzzsw0412


可以先用local模式读取一下

步骤
一、先将做测试的数据上传到HDFS
cd /export/servers/sparkdatas
hdfs dfs -mkdir -p /sparkwordcount
hdfs dfs -put wordcount.txt  /sparkwordcount
二、开发scala代码
sc.textFile("hdfs://node01:8020/sparkwordcount/wordcount.txt").flatMap(_.split(" ")).map((_,1)).reduceByKey(_ + _).collect

在这里插入图片描述
如果不需要查看结果,而是需要将结果存储为文本文件,则将.collect换成.saveAsTestFile(要存放的Path)即可


standAlone模式查看HDFS上的文件

步骤
一、退出local模式,重新进入Spark-shell
bin/spark-shell --master spark://node01:7077 \
 --executor-memory 1g \
 --total-executor-cores 2
二、开发scala代码
sc.textFile("hdfs://node01:8020/sparkwordcount/wordcount.txt").flatMap(_.split(" ")).map((_,1)).reduceByKey(_ + _).collect

在这里插入图片描述

分类:

技术点:

相关文章:

  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2021-04-14
  • 2021-11-18
  • 2021-09-22
  • 2021-12-23
猜你喜欢
  • 2021-11-18
  • 2021-11-18
  • 2022-12-23
  • 2021-11-18
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案