java spark转换算子union、intersection、subtract
作者:互联网
/** * # _*_ coding:utf-8 _*_ * # Author:xiaoshubiao * # Time : 2020/5/14 8:33 **/ import org.apache.spark.SparkConf; import org.apache.spark.api.java.JavaRDD; import org.apache.spark.api.java.JavaSparkContext; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class union_test { public static void main(String[] args) { SparkConf conf = new SparkConf().setMaster("local[*]").setAppName("union_test"); JavaSparkContext sc = new JavaSparkContext(conf); List<String> list = Arrays.asList("a","b","c"); List<String> list2 = Arrays.asList("d","e","f","h","a"); JavaRDD<String> parallelize = sc.parallelize(list, 1); JavaRDD<String> parallelize2 = sc.parallelize(list2,1); parallelize.union(parallelize2).collect().forEach(x->System.out.println("union-并集结果:"+x));//是并集不去重的结果,在这a会出现两个 parallelize.intersection(parallelize2).collect().forEach(x->System.out.println("intersection-交集结果:"+x)); parallelize.subtract(parallelize2).collect().forEach(x->System.out.println("intersection-差集结果:"+x)); } }
标签:java,parallelize,union,parallelize2,import,spark 来源: https://www.cnblogs.com/7749ha/p/12886325.html