I'd like to use a conditional statement in a map function. For example,
JavaPairRDD<Integer, Long> rdd1 = sc.parallelize(Arrays.asList(1, 2, 1, 0)).zipWithIndex();
rdd1.map(x -> if x._1 == 2 return x._1*x._1 else return x._1).foreach(x -> System.out.println(x));
should print [(1,0), (4, 1), (1, 2), (0, 3)].
So, what's the proper way of using the map function in such way ?