Spark 广播变量(broadcast)更新方法
更新方法
spark 广播变量可以通过unpersist方法删除,然后重新广播
1
2
3
4
5
6
7
|
val map = sc.textFile( "/test.txt" ).map(line = > { val arr = line.split( "," ) (arr( 0 ), arr( 2 ).toInt) }).distinct var mapBC = sc.broadcast(map.take( 10 ).toMap) mapBC.unpersist mapBC = sc.broadcast(map.take( 2 ).toMap) |
执行结果
map count: 192374
first broadcast: 10
second broadcast: 2