我尝试应用根据另一个数据集中的数据范围过滤掉数据集中某些值的函数。我已经执行了一些groupBys和join,因此传入函数的参数I的格式有两个Iterables,如下所示:
g1 = g0.map(lambda x: timefilter(x[0]))
其中x [0]为<pyspark.resultiterable.ResultIterable object at 0x23b6610>, <pyspark.resultiterable.ResultIterable object at 0x23b6310>)
当我输入函数timefilter
时,我现在需要根据x [0]中的值过滤出x [1]中的值。但是当我尝试以下内容时(在twoList
和twoRDD
上,虽然我只是在这里显示了两个):
def timefilter(RDDList):
oneList = list(RDDList[0])
twoList = list(RDDList[1])
twoRDD = RDDList[1]
test = twoList.filter(lambda x: x[4]=='helloworld')
return test
它给了我以下错误:AttributeError: 'ResultIterable' object has no attribute 'filter'
然后是一堆错误。
好像我不能在任何格式的迭代中使用过滤器,但感觉我错过了一些非常简单的东西。我在函数中缺少一个转换吗?
答案 0 :(得分:0)
事实证明,对可迭代RDD进行过滤是不可能的,所以我只使用了python内置过滤器函数。以下内容:filter(lambda x: x[1] in oneList, twoList)
。