使用java、scala、python三种语言实现spark rdd的reduce算子的使用
时间: 2024-05-15 20:16:15 浏览: 161
数据源文件data01.txt
Java:
```
JavaRDD<Integer> numbers = sc.parallelize(Arrays.asList(1, 2, 3, 4, 5));
int sum = numbers.reduce((a, b) -> a + b);
System.out.println(sum);
```
Scala:
```
val numbers = sc.parallelize(Seq(1, 2, 3, 4, 5))
val sum = numbers.reduce(_ + _)
println(sum)
```
Python:
```
numbers = sc.parallelize([1, 2, 3, 4, 5])
sum = numbers.reduce(lambda a, b: a + b)
print(sum)
```
阅读全文