zoukankan      html  css  js  c++  java
  • java实现spark常用算子之intersection



    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);
    }
    });

    }
    }

    微信扫描下图二维码加入博主知识星球,获取更多大数据、人工智能、算法等免费学习资料哦!

  • 相关阅读:
    滑雪
    2084 数塔HDU
    括号匹配(二)
    项链
    单调递增最长子序列
    矩形嵌套
    最长公共子序列
    poj3253
    表达式求值
    颜色16进制代码表显示和16进制数值对比显示方便查找
  • 原文地址:https://www.cnblogs.com/guokai870510826/p/11598857.html
Copyright © 2011-2022 走看看