当前位置:网站首页>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
边栏推荐
- Codejock Suite Pro v20. three
- What role does the software performance test report play? How much is the third-party test report charged?
- 字符串排序
- 基于 TiDB 的 Apache APISIX 高可用配置中心的最佳实践
- Recommended search common evaluation indicators
- Accumulation of applet knowledge points
- 【自娱自乐】构造笔记 week 2
- 【开源工具分享】单片机调试助手(示波/改值/日志) - LinkScope
- MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问
- 幂等性的处理
猜你喜欢
时序模型:门控循环单元网络(GRU)
cadence SPB17. 4 - Active Class and Subclass
服务器中毒了怎么办?服务器怎么防止病毒入侵?
贫困的无网地区怎么有钱建设网络?
API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
Codejock Suite Pro v20.3.0
山寨版归并【上】
Modèle de Cluster MySQL et scénario d'application
一刷314-剑指 Offer 09. 用两个栈实现队列(e)
Redis master-slave replication process
随机推荐
导入地址表分析(根据库文件名求出:导入函数数量、函数序号、函数名称)
One brush 312 - simple repetition set - Sword finger offer 03 Duplicate number in array (E)
多级缓存使用
【自娱自乐】构造笔记 week 2
Codejock Suite Pro v20. three
Explanation 2 of redis database (redis high availability, persistence and performance management)
Connect PHP to MSSQL via PDO ODBC
Upgrade MySQL 5.1 to 5.69
Cookie&Session
s16. One click installation of containerd script based on image warehouse
Recommended search common evaluation indicators
[leetcode daily question] install fence
APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)
Demonstration meeting on startup and implementation scheme of swarm intelligence autonomous operation smart farm project
Redis主从复制过程
提取不重复的整数
For examination
What if the package cannot be found
布隆过滤器在亿级流量电商系统的应用
PHP 的运算符