Scala Spark WordCount
2024-09-04 06:32:53
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
最新文章
- 【NLP】揭秘马尔可夫模型神秘面纱系列文章(四)
- 协议分析TMP
- Ceph的集群全部换IP
- MySQL 建表字段长度的限制
- 反射给对象赋值遇到的问题——类型转换[转http://blog.csdn.net/xiaohan2826/article/details/8536074]
- windows 数据类型转换为 dotnet 数据类型
- linux下用shell删除三天前或者三天内的文件
- HTML5 的WebSocket
- Spring3实战第二章第一小节 Spring bean的初始化和销毁三种方式及优先级
- linux 下搭建php环境
- QTP 自动化测试桌面程序--笔记(下拉选择、右键菜单、在控件仓库中查找对应的控件)
- linux环境启动数据库
- web 前端知识体系 网站资源分析
- Mac系统安装和卸载brew包管理
- 关于Base64编码的理解
- HTML5 多媒体音视频处理
- Spring Boot 2 实践记录之 封装依赖及尽可能不创建静态方法以避免在 Service 和 Controller 的单元测试中使用 Powermock
- openssl https 单向认证连接成功示例
- 在linux下设置定时任务
- 图像运动去模糊(Motion Deblurring)代码
热门文章
- linux 配置启动supervisor详细
- AttributeError: module &#39;pytest&#39; has no attribute &#39;allure&#39;
- SpringBoot:使用Jenkins自动部署SpringBoot项目(二)具体配置
- html上传文件限制、前端限制文件类型
- vue.js动态绑定input的checked
- [Beta阶段]第十一次Scrum Meeting
- [Beta]Scrum Meeting#8
- Pushing state-of-the-art in 3D content understanding
- 虚拟环境上的jupyterhub开机启动设置
- mysql 排序长度限制之max_length_for_sort_data以及mysql两种排序算法