2014-06-25 5 views
3

IN 튜토리얼이 제안cogroup는 PySpark

('a', (<pyspark.resultiterable.ResultIterable object at 0x1d8b190>, <pyspark.resultiterable.ResultIterable object at 0x1d8b150>)) 
('b', (<pyspark.resultiterable.ResultIterable object at 0x1d8b210>, <pyspark.resultiterable.ResultIterable object at 0x1d8b1d0>)) 

나는에 출력을 저장하는 경우이 ', 중첩의 3 수준이 R '및 이렇게 :

for i in r: 
    for j in i[1]: 
     print list(j) 

내가 올바른 cogrouped 번호를 얻을 :

1) Cogroup이 PySpark에서 rightjoin/leftouterjoin 등의 숫자를 반환하지 않는 이유는 무엇입니까? 2) PySpark 셸에서 예제를 복제 할 수없는 이유는 무엇입니까? 그 cogroup은 기본적으로 가입,

/** 
    * For each key k in `this` or `other`, return a resulting RDD that contains a tuple with the 
    * list of values for that key in `this` as well as `other`. 
    */ 
    def cogroup[W](other: RDD[(K, W)]): RDD[(K, (Iterable[V], Iterable[W]))] 

실제로 cogroup 구현하는 스파크에 조인 반환하도록되어 무엇 때문에

+0

게시물을 편집하여 참조 된 튜토리얼에 링크 할 수 있습니까? –

+0

@Nick : http://spark.apache.org/docs/0.7.0/api/pyspark/pyspark.rdd.RDD-class.html#cogroup 링크가 있습니다.이 자습서는 유효하지 않을 수 있습니다. Spark의 최신 릴리스. – Vedant

+1

예, 0.7.0 용 문서를보고 있습니다. Spark의 최신 버전은 1.0.0입니다. 'cogroup()'에 해당하는 문서는 [here] (http://spark.apache.org/docs/latest/api/python/pyspark.rdd.RDD-class.html#cogroup)이며, 올바른 출력. –

답변

1

쉬운 대답은 단지 튜플에 cogroup에서 반복 가능 객체를 나누기. 다음은 spark에서 조인을 삽입하는 방법입니다. 인터프리터 출력의 약간의 차이에 관해서는

def join[W](other: RDD[(K, W)], partitioner: Partitioner): RDD[(K, (V, W))] = { 
    this.cogroup(other, partitioner).flatMapValues { case (vs, ws) => 
     for (v <- vs; w <- ws) yield (v, w) 
    } 
    } 

내가 자습서를 참조하지 않는 한, 나는 확신 할 수 없다 (마음에 출력을 유지에서 Iterable이 내용의 표시하지 않는 pyspark 제외하고는 동일합니다). 튜토리얼은 출력이 실제로 나타나지 않더라도 출력이 더 선명하게 표시 될 수 있습니다. 한가지 더 스칼라 셸에서 비슷한 스크립트를 실행하고 모든 결과를 보여줍니다.

Array((a,(ArrayBuffer(1),ArrayBuffer(2))), (b,(ArrayBuffer(4),ArrayBuffer())))