package de.hsma.informatik.bdea;

import java.util.Arrays;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

public class SimpleAdder {

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

		Integer[] ints = {1,2,4,5,6,7,8,9};
		JavaRDD<Integer> dist = sc.parallelize(Arrays.asList(ints));
		
		dist.collect().forEach(System.out::println);
		
		
		System.out.println(dist.reduce((x,y) -> x+y));

		
		Integer[] others = {2,3,1,0, 0, 3, 4};
		JavaRDD<Integer> dist2 = sc.parallelize(Arrays.asList(others));
//		JavaRDD<Integer> res = dist.intersection(dist2);
//		JavaPairRDD<Integer, Integer> res = dist.join(dist2);
//		res.collect().forEach(System.out::println);
		
		dist.intersection(dist2).collect().forEach(System.out::println);
		
		dist2 = dist2.sortBy(x->x, true, 1);
		
		dist2.sample(true, 0.5).collect().forEach(System.out::println);
//		dist2.take(2).forEach(System.out::println);
		dist2.collect().forEach(System.out::println);

	}

}
