import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.VoidFunction;
import java.util.Arrays;
import java.util.List;
/**
* intersection 算子:
* 将两个RDD求交集
* 然后去重
*/
public class IntersectionOperator {
public static void main(String[] args) {
SparkConf conf = new SparkConf().setMaster("local").setAppName("intersection");
JavaSparkContext sc = new JavaSparkContext(conf);
List<String> list1 = Arrays.asList("w1","w2","w3");
JavaRDD<String> listRdd = sc.parallelize(list1);
List<String> list2 = Arrays.asList("w2","w3","w4");
JavaRDD<String> list2Rdd = sc.parallelize(list2);
listRdd.intersection(list2Rdd).foreach(new VoidFunction<String>() {
@Override
public void call(String s) throws Exception {
System.err.println(s);
}
});
}
}
微信扫描下图二维码加入博主知识星球,获取更多大数据、人工智能、算法等免费学习资料哦!