在reduceByKey()api spark中获取密钥

时间:2017-03-03 02:40:52

标签: apache-spark pyspark

有没有办法可以在reduceByKey()函数中的pyspark中获取键的名称,这样我才能得到传递给reduceByKey()函数的两个值之间的共同键?

例如:

inside reduceByKey(combineValues) where

def combineValues(a,b): 
//can i get the key value common to both a and b here ?? 
return a+b;

1 个答案:

答案 0 :(得分:1)

你可以在RDD上使用aggregate函数,但是你失去了HashPartitioner的好处,所以如果重要的话,我建议你把密钥存储在你的值中。