Reputation: 69
I am trying to run below python udf in Pig
@outputSchema("word:chararray")
def get(s):
out = s.lower()
return out;
I am getting below error :
File "/home/test.py", line 3, in get
out = s.lower()
AttributeError: 'NoneType' object has no attribute 'lower'
Upvotes: 1
Views: 362
Reputation: 16240
You should handle the case when s
is none. In most of the examples such as:
from pig_util import outputSchema
@outputSchema('decade:chararray')
def decade(year):
"""
Get the decade, given a year.
e.g. for 1998 -> '1990s'
"""
try:
base_decade_year = int(year) - (int(year) % 10)
decade_str = '%ss' % base_decade_year
print 'input year: %s, decade: %s' % (year, decade_str)
return decade_str
except ValueError:
return None
You need to handle the case when the value is None
. So, one possible fix would be to try:
@outputSchema("word:chararray")
def get(s):
if s is None:
return None
return str(s).lower()
Upvotes: 2