当前位置:网站首页>Spark 算子之distinct使用
Spark 算子之distinct使用
2022-04-23 15:45:00 【逆风飞翔的小叔】
前言
相信使用过mysql的同学对sql语句中distinct关键字并不陌生,使用distinct关键字可以对查询的数据进行去重操作,在Spark 中,可以做类似的理解;
函数签名
def distinct()(implicit ord: Ordering[T] = null): RDD[T]def distinct( numPartitions: Int )(implicit ord: Ordering[T] = null): RDD[T]
函数说明
将数据集中重复的数据去重
案例:对集合中的一组数字去重
import org.apache.spark.{SparkConf, SparkContext}
object Distinct_Test {
def main(args: Array[String]): Unit = {
val sparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
val sc = new SparkContext(sparkConf)
val rdd = sc.makeRDD(List(1,2,3,4,5,3,5,2,2))
rdd.distinct().collect().foreach(println)
sc.stop()
}
}
运行上面的程序,观察控制台输出结果,可以发现重复的元素最终只输出了一次

版权声明
本文为[逆风飞翔的小叔]所创,转载请带上原文链接,感谢
https://blog.csdn.net/congge_study/article/details/124356121
边栏推荐
- [backtrader source code analysis 18] Yahoo Py code comments and analysis (boring, interested in the code, you can refer to)
- Redis主从复制过程
- 编译,连接 -- 笔记
- Go并发和通道
- CVPR 2022 优质论文分享
- 通过 PDO ODBC 将 PHP 连接到 MSSQL
- Go language, condition, loop, function
- MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问
- Pgpool II 4.3 Chinese Manual - introductory tutorial
- 大厂技术实现 | 行业解决方案系列教程
猜你喜欢

IronPDF for .NET 2022.4.5455

山寨版归并【上】

WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile

Configuration of multi spanning tree MSTP

KNN, kmeans and GMM

Do we media make money now? After reading this article, you will understand

Why disable foreign key constraints

Cap theorem

Why is IP direct connection prohibited in large-scale Internet

负载均衡器
随机推荐
大厂技术实现 | 行业解决方案系列教程
导入地址表分析(根据库文件名求出:导入函数数量、函数序号、函数名称)
The length of the last word of the string
Demonstration meeting on startup and implementation scheme of swarm intelligence autonomous operation smart farm project
Modèle de Cluster MySQL et scénario d'application
s16.基于镜像仓库一键安装containerd脚本
What is CNAs certification? What are the software evaluation centers recognized by CNAs?
提取不重复的整数
考试考试自用
What if the server is poisoned? How does the server prevent virus intrusion?
网站建设与管理的基本概念
怎么看基金是不是reits,通过银行购买基金安全吗
通过 PDO ODBC 将 PHP 连接到 MySQL
ICE -- 源码分析
MySQL集群模式與應用場景
CVPR 2022 优质论文分享
Pgpool II 4.3 Chinese Manual - introductory tutorial
String sorting
Introduction to dynamic programming of leetcode learning plan day3 (198213740)
贫困的无网地区怎么有钱建设网络?