import org.apache.spark.{SparkConf, SparkContext}
/**
* Created by yz02 on 2017/6/15.
*/
object T_filter {
System.setProperty("hadoop.home.dir","F:\\hadoop-2.6.5")
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("filter_test").setMaster("local")
val sc = new SparkContext(conf)
val numbers = Array(1, 2, 3, 4, 5)
val numberRDD = sc.parallelize(numbers)
//filter 过滤元素
val resultRDD = numberRDD.filter(x => x % 2 == 0)
.foreach(println)
}
}
运行结果:
2
4
4