zoukankan      html  css  js  c++  java
  • 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));
    
        }
    }
  • 相关阅读:
    红帽7 创建网络会话
    红帽7 Iptables与Firewalld防火墙
    红帽7 配置网卡
    红帽7 LVM逻辑卷管理器
    红帽7 RAID磁盘冗余阵列
    红帽7 磁盘划分
    wpf学习一(转)
    选中当前点击的位置
    c#客显
    两个程序间的通信有三种
  • 原文地址:https://www.cnblogs.com/7749ha/p/12886325.html
Copyright © 2011-2022 走看看