当前位置:首页 - Spark

Spark filter算子学习使用详解

作者:高景洋 日期:2020-10-25 10:09:45 浏览次数:2412

filter(func):

    1、选出所有func返回值为true的元素,生成一个新的分布式数据集返回


如图:


示例代码:

实现 Rdd ,每个元素*2,并输出结果>5的数据



def my_filter():
    data = [1,2,3,4,5]
    rdd1 =sc.parallelize(data)
    map_rdd = rdd1.map(lambda x:x*2) 
 print(map_rdd.collect())
    filter_rdd = map_rdd.filter(lambda x:x>5) 
 print(filter_rdd.collect()) 
 #链示实示方式  
 #sc.parallelize(data).map(lambda x:x*2).filter(lambda x:x>5).collect()


本文永久性链接:
<a href="http://r4.com.cn/art149.aspx">Spark filter算子学习使用详解</a>