1

I write a program based on MapReduce using MRJob. I have a question about the parameters of reducer. As you know, Reducer function takes two parameters which are key and values. I want to find the length of values without writing any loop condition if it is possible. The code is identified below.

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 
Hamid Rouhani
  • 2,309
  • 2
  • 31
  • 45
ugur
  • 400
  • 6
  • 20

1 Answers1

1

we can convert generator to list and we can find the size of the list

length = len(list(records))

and also if you convert it. Then you can use the generator as list

ugur
  • 400
  • 6
  • 20