apache pig - Writing UDF in Python for Pig -
i've struggled on problem several hours. hope can me. input bag structure, such {([1,2]),([3,4])}, , goal output sum of corresponding element of tuples in bag, (4,6). lot.
my code:
@outputschema('aa:chararray') def func(input): aa = map(sum,zip(*,input)) aa = str(aa) return aa typeerror: unsupported operand type(s) +: 'int' , 'unicode'
here guess. message:
typeerror: unsupported operand type(s) +: 'int' , 'unicode' refers fragment:
map(sum,zip(*,input)) and means trying take sum unicode tuple, e.g. [u'1', u'2'] rather tuple of int's, e.g. [1,2] think working with.
if that's case, can wrap zip inside list comprehension conversion unicode int:
[map(int, a) in zip(*,input)] but may have error lurking. judging @outputschema('aa:chararray') want return list of string, not single string; str([1,2]) "[1,2]" , think want ["1", "2"]. if that's case (and might not should check), wrap in list comprehension:
aa = [str(s) s in aa] incorporating these 2 changes, code becomes:
@outputschema('aa:chararray') def func(input): aa = map(sum,[map(int, a) in zip(*,input)]) aa = [map(str, a) in aa] return aa if this, can't solve problem, helpful have more information. example, type error point particular line in code? if so, line?
perhaps can show types of input or * are. example change function from:
... def func(input): aa = map(sum,zip(*,input)) ... to:
def func(input): print(map(type, input)) print(map(type, *)) aa = map(sum,zip(*,input))
Comments
Post a Comment