2017-02-06 1 views
1

MRJob을 사용하여 MapReduce를 기반으로 프로그램을 작성합니다. 감속기의 매개 변수에 대한 질문이 있습니다. 아시다시피, 감속기 기능은 키와 값인 두 가지 매개 변수를 사용합니다. 가능한 경우 루프 조건을 작성하지 않고 값의 길이를 찾고 싶습니다. 코드는 아래에 나와 있습니다.MRJob- 리듀서 값의 길이 찾기

Error is in reducer_IGPLInit function. Error is "TypeError: object of type 'generator' has no len()"

def mapperDataPartition(self, key, line): 
    p=5 
    (a, b, c, d) = line.split('\t') 
    yield randint(1,p),(a,b,c,d) 

def reducerDataPartition(self, pVal, records): 
    for rec in records: 
     yield pVal, (rec) 

def reducer_IGPLInit(self, pVal, records): 
    yield None, len(records) #### HERE I FACE WITH AN ERROR 

답변

1

우리는 나열 발전기를 변환 할 수 있습니다 그리고 우리는 목록

length = len(list(records)) 

의 크기를 찾을 수 있습니다 당신이 그것을 또한 변환합니다. 그런 다음 발전기를 목록으로 사용할 수 있습니다