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;
/**
* distinct 算子:
* 简单去重
*
*/
public class DistinctOperator {
public static void main(String[] args) {
SparkConf conf = new SparkConf().setMaster("local").setAppName("distinct");
JavaSparkContext sc = new JavaSparkContext(conf);
List<String> list1 = Arrays.asList("w1","w2","w3","w4","w2");
JavaRDD<String> list1Rdd = sc.parallelize(list1);
//此时result有3个分区
JavaRDD<String> result = list1Rdd.distinct(2);
result.foreach(new VoidFunction<String>() {
@Override
public void call(String s) throws Exception {
System.err.println(s);
}
});
}
}
微信扫描下图二维码加入博主知识星球,获取更多大数据、人工智能、算法等免费学习资料哦!