Scala所需依赖

<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.8</version>
</dependency>

Scala WordCount代码

val source: List[String] = Source.fromFile("./src/main/data/wordCount.txt").getLines().toList
source.flatMap(elem => elem.split(" "))
.filter(_.nonEmpty)
.groupBy(elem => elem.toLowerCase)
.mapValues(elem => elem.size)
.foreach(println)

Spark所需依赖

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.3.4</version>
</dependency>

Spark WordCount代码

val sparkContext = new SparkContext((new SparkConf).setAppName("SparkWordCount").setMaster("local[2]"))
sparkContext.setLogLevel("WARN")
val source: RDD[String] = sparkContext.textFile("./src/main/data/wordCount.txt")
source.flatMap(_.split(" "))
.filter(_.nonEmpty)
.map(elem => (elem.toLowerCase, 1))
.reduceByKey(_+_)
.foreach(println)
sparkContext.stop

最新文章

  1. 【NLP】揭秘马尔可夫模型神秘面纱系列文章(四)
  2. 协议分析TMP
  3. Ceph的集群全部换IP
  4. MySQL 建表字段长度的限制
  5. 反射给对象赋值遇到的问题——类型转换[转http://blog.csdn.net/xiaohan2826/article/details/8536074]
  6. windows 数据类型转换为 dotnet 数据类型
  7. linux下用shell删除三天前或者三天内的文件
  8. HTML5 的WebSocket
  9. Spring3实战第二章第一小节 Spring bean的初始化和销毁三种方式及优先级
  10. linux 下搭建php环境
  11. QTP 自动化测试桌面程序--笔记(下拉选择、右键菜单、在控件仓库中查找对应的控件)
  12. linux环境启动数据库
  13. web 前端知识体系 网站资源分析
  14. Mac系统安装和卸载brew包管理
  15. 关于Base64编码的理解
  16. HTML5 多媒体音视频处理
  17. Spring Boot 2 实践记录之 封装依赖及尽可能不创建静态方法以避免在 Service 和 Controller 的单元测试中使用 Powermock
  18. openssl https 单向认证连接成功示例
  19. 在linux下设置定时任务
  20. 图像运动去模糊(Motion Deblurring)代码

热门文章

  1. linux 配置启动supervisor详细
  2. AttributeError: module &#39;pytest&#39; has no attribute &#39;allure&#39;
  3. SpringBoot:使用Jenkins自动部署SpringBoot项目(二)具体配置
  4. html上传文件限制、前端限制文件类型
  5. vue.js动态绑定input的checked
  6. [Beta阶段]第十一次Scrum Meeting
  7. [Beta]Scrum Meeting#8
  8. Pushing state-of-the-art in 3D content understanding
  9. 虚拟环境上的jupyterhub开机启动设置
  10. mysql 排序长度限制之max_length_for_sort_data以及mysql两种排序算法