当前位置:网站首页>Spark small case - RDD, broadcast
Spark small case - RDD, broadcast
2022-04-23 04:41:00 【Z-hhhhh】
RDD Small cases
object RDD01 {
def main(args: Array[String]): Unit = {
val sparkConf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("RDD01")
val sc: SparkContext = new SparkContext(sparkConf)
// Create... From the collection RDD,spark Two methods are provided ,parallelize and makeRDD,makeRDD Is to achieve parallelize
sc.parallelize(
List(1,2,3,4)
).filter(_>3)
.collect()
.foreach(println)
sc.stop()
}
}
broadcast Small cases
/** * broadCast A simple case * Broadcast variables are used to efficiently distribute large objects . Send a read-only value to all working nodes , * For one or more Spark Operation and use . such as , If your application needs to send a large read-only query table to all nodes , * Broadcast variables are easy to use . Using the same variable in multiple parallel operations , however Spark Each task will be sent separately . */
object BroadCast01 {
def main(args: Array[String]): Unit = {
val sparkConf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("broadcast01")
val sc: SparkContext = new SparkContext(sparkConf)
val rdd1= sc.makeRDD(List(("a", 1), ("b", 2), ("c", 3), ("d", 4)))
val list= List(("a", 5), ("b", 6), ("c",7))
// Declare broadcast variables
val broadcast: Broadcast[List[(String,Int)]] = sc.broadcast(list)
rdd1.map {
case (key, num) => {
var num2 = 0
// Use broadcast variables
for ((k, v) <- broadcast.value) {
if (key == k) {
num2 = num * v
}
}
(key, num2)
}
}.filter(x=>x._2>0) // Screening value>0 Of
.foreach(x=>{
println(x._1+":"+x._2)})
sc.stop()
}
}
版权声明
本文为[Z-hhhhh]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220559122446.html
边栏推荐
- AWS eks add cluster user or Iam role
- Record your own dataset with d435i, run orbslam2 and build a dense point cloud
- The perfect combination of collaborative process and multi process
- Summary of Android development posts I interviewed in those years (attached test questions + answer analysis)
- 国外LEAD,联盟经理常见问答
- [pytoch foundation] torch Split() usage
- Redis command Encyclopedia
- Practice and exploration of knowledge map visualization technology in meituan
- Innovative practice of short video content understanding and generation technology in meituan
- 520. Detect capital letters
猜你喜欢

How to regulate intestinal flora? Introduction to common natural substances, probiotics and prebiotics

Gut liver axis: host microbiota interaction affects hepatocarcinogenesis

HMS Core Discovery第14期回顾长文|纵享丝滑剪辑,释放视频创作力
![Luogu p1858 [multi person knapsack] (knapsack seeking the top k optimal solution)](/img/2e/3313e563ac4f54057e359941a45098.png)
Luogu p1858 [multi person knapsack] (knapsack seeking the top k optimal solution)

New terminal play method: script guidance independent of technology stack

优麒麟 22.04 LTS 版本正式发布 | UKUI 3.1开启全新体验

AWS EKS添加集群用户或IAM角色

Eight misunderstandings that should be avoided in data visualization

Understand the gut organ axis, good gut and good health

383. Ransom letter
随机推荐
Nature medicine reveals individual risk factors of coronary artery disease
协程与多进程的完美结合
Effects of antibiotics on microbiome and human health
229. 求众数 II
Go 语言中的 logger 和 zap 日志库
MYSQL去重方法汇总
Recommended scheme of national manufactured electronic components
兼容NSR20F30NXT5G的小体积肖特基二极管
Recommended scheme for national production of electronic components for wireless charging
[pytoch foundation] torch Split() usage
QML进阶(四)-绘制自定义控件
MySQL queries users logged in for at least N consecutive days
Luogu p1858 [multi person knapsack] (knapsack seeking the top k optimal solution)
AWS EKS 部署要点以及控制台与eksctl创建的差异
Leetcode008 -- implement strstr() function
【论文阅读】【3d目标检测】Voxel Transformer for 3D Object Detection
Go反射—Go语言圣经学习笔记
重剑无锋,大巧不工
C language: spoof games
leetcode007--判断字符串中的括号是否匹配