当前位置:网站首页>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
边栏推荐
- 补充番外14:cmake实践项目笔记(未完待续4/22)
- [timing] empirical evaluation of general convolution and cyclic networks for sequence modeling based on TCN
- Installation du compilateur croisé de la plateforme zynq
- 【时序】基于 TCN 的用于序列建模的通用卷积和循环网络的经验评估
- 520. Detect capital letters
- KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘
- Last day of 2017
- Recommended scheme for national production of electronic components for wireless charging
- AWS eks add cluster user or Iam role
- QML进阶(四)-绘制自定义控件
猜你喜欢
第四章 --- 了解标准设备文件、过滤器和管道
PIP3 installation requests Library - the most complete pit sorting
Installation of zynq platform cross compiler
MYSQL查询至少连续n天登录的用户
Bacterial infection and antibiotic use
520. Detect capital letters
IDE Idea 自动编译 与 On Upate Action 、 On Frame Deactivation 的配置
Experience summary and sharing of the first prize of 2021 National Mathematical Modeling Competition
无线充电全国产化电子元件推荐方案
How to regulate intestinal flora? Introduction to common natural substances, probiotics and prebiotics
随机推荐
Leetcode001 -- returns the subscript of the array element whose sum is target
IEEE Transactions on Systems, Man, and Cybernetics: Systems(TSMC)投稿须知
Key points of AWS eks deployment and differences between console and eksctl creation
无线充电全国产化电子元件推荐方案
[timing] empirical evaluation of general convolution and cyclic networks for sequence modeling based on TCN
Youqilin 22.04 lts version officially released | ukui 3.1 opens a new experience
Innovative practice of short video content understanding and generation technology in meituan
[paper reading] [3D object detection] voxel transformer for 3D object detection
[pytoch foundation] torch Split() usage
RC低通滤波器的逆系统
Use recyclerview to realize left-right side-by-side classification selection
从MySQL数据库迁移到AWS DynamoDB
Interaction of diet gut microbiota on cardiovascular disease
Luogu p1858 [multi person knapsack] (knapsack seeking the top k optimal solution)
test
电钻、电锤、电镐的区别
Installation of zynq platform cross compiler
Eight misunderstandings that should be avoided in data visualization
Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘