My python UDF code, born is a datetime variable from Pig , I tried it as string object but it also gave an error, and treating it as a datetime object also gave an error
from datetime import date
@outputSchema("age_key:chararray")
def agekeyed(born):
today = date.today()
return born[:4]
I get an error :
TypeError: 'org.joda.time.DateTime' object is unsubscriptable
at org.python.core.Py.TypeError(Py.java:235)
at org.python.core.PyObject.__finditem__(PyObject.java:585)
at org.python.core.PyObjectDerived.__finditem__(PyObjectDerived.java:861)
at org.python.core.PyObject.__getitem__(PyObject.java:653)
at org.python.core.PyObjectDerived.__getitem__(PyObjectDerived.java:901)
at org.python.core.PyObject.__getslice__(PyObject.java:740)
at org.python.core.PyObjectDerived.__getslice__(PyObjectDerived.java:924)
at org.python.pycode._pyx3.agekeyed$1(keying.py:6)
at org.python.pycode._pyx3.call_function(keying.py)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
at org.python.core.PyFunction.function___call__(PyFunction.java:376)
at org.python.core.PyFunction.__call__(PyFunction.java:371)
at org.python.core.PyFunction.__call__(PyFunction.java:361)
at org.python.core.PyFunction.__call__(PyFunction.java:356)
at org.apache.pig.scripting.jython.JythonFunction.exec(JythonFunction.java:117)
... 16 more