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

    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;

    /**
    * union 算子:
    * 取两个RDD的并集,不去重,会增加partition的数量,同时并行度也会增加
    *
    */
    public class UnionOperator {
    public static void main(String[] args) {
    SparkConf conf = new SparkConf().setMaster("local").setAppName("sampleTake");
    JavaSparkContext sc = new JavaSparkContext(conf);
    List<String> list1 = Arrays.asList("w1","w2","w3","w4","w5");
    List<String> list2 = Arrays.asList("q1","q2","q3","q4","q5");

    JavaRDD<String> list1Rdd = sc.parallelize(list1,2);
    JavaRDD<String> list2Rdd = sc.parallelize(list2);

    //此时result有3个分区
    JavaRDD<String> result = list1Rdd.union(list2Rdd);

    result.foreach(new VoidFunction<String>() {
    @Override
    public void call(String s) throws Exception {
    System.err.println(s);
    }
    });

    }
    }

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

  • 相关阅读:
    swf上传地址
    Nape 获取碰撞点加特效
    vbs打包exe工具
    Air打包exe
    JDK12的安装搭建
    Dubble 入门
    FastDFS 集群
    PAT Advanced 1077 Kuchiguse (20 分)
    高可用4层lvs——keepalived
    PAT Advanced 1035 Password (20 分)
  • 原文地址:https://www.cnblogs.com/guokai870510826/p/11635235.html
Copyright © 2011-2022 走看看