美文网首页
141、Spark核心编程进阶之union以及公司部门合并案例

141、Spark核心编程进阶之union以及公司部门合并案例

作者: ZFH__ZJ | 来源:发表于2019-01-21 22:18 被阅读0次

union算子,将两个RDD的数据,合并为一个RDD

public class Union {
    public static void main(String[] args) {
        SparkConf conf = new SparkConf()
                .setAppName("UnionJava")
                .setMaster("local");
        JavaSparkContext sc = new JavaSparkContext(conf);

        List<String> department1StaffList = Arrays.asList("张三", "李四", "王二", "麻子");
        JavaRDD<String> department1StaffRDD = sc.parallelize(department1StaffList);

        List<String> department2StaffList = Arrays.asList("赵六", "王五", "小明", "小倩");
        JavaRDD<String> department2StaffRDD = sc.parallelize(department2StaffList);

        JavaRDD<String> departmentStaffRDD = department1StaffRDD.union(department2StaffRDD);

        for(String staff : departmentStaffRDD.collect()) {
            System.out.println(staff);
        }
    }
}

相关文章

网友评论

      本文标题:141、Spark核心编程进阶之union以及公司部门合并案例

      本文链接:https://www.haomeiwen.com/subject/gdxcjqtx.html