0
votes

I am aware that this is a similar question. I have gone through some answers and none worked. So here is the thing, I am writing a mapper and reducer for my MapReduce program and I am getting the following error below

Traceback (most recent call last): File "/usr/local/hadoop/./reducer.py", line 10, in desc, count = line.split('\t', 1) ValueError: need more than 1 value to unpack

I am unable to debug the error, as I don't know what is causing the issue. Please find the code for my Mapper and Reducer class below.

Mapper Code:

#!/usr/bin/env python
import sys
for line in sys.stdin:
    line = line.strip('')
    bYear = line.split(',')
    for birthYear in bYear:
        print '%s\t%s' % (bYear[6],1)

Reducer Code:

#!/usr/bin/env python
import sys

current_desc = None
current_count = 0
desc = None

for line in sys.stdin:
    line = line.strip()
    **desc, count = line.split('\t', 1)** . ---> This is where I'm getting an error.
    try:
        count = int(count)
    except ValueError:
        continue

    if current_desc == desc:
        current_count += count
    else:
        if current_desc:
            # write result to STDOUT
            print '%s\t%s' % (current_desc, current_count)
        current_count = count
        current_desc = desc

if current_desc == desc:
    print '%s\t%s' % (current_desc, current_count)

Please help.

1

1 Answers

0
votes

It would seem that there is no '\t' character in that specific line, thus line.split('\t', 1) is returning only 1 element and cannot be assigned to desc, count