0
我的python UDF代碼誕生了Pig的日期時間變量 我試過它作爲字符串對象,但它也給出了一個錯誤 並將它當作DateTime對象也給了一個錯誤我怎樣才能將一個類型的日期時間從Pig轉換爲python UDF
from datetime import date
@outputSchema("age_key:chararray")
def agekeyed(born):
today = date.today()
return born[:4]
我得到一個錯誤:
類型錯誤: 'org.joda.time.DateTime' 對象是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
是的,我使用chararray實現的任務,但是,當我使用的日期時間,我不能使用默認python函數就像出生年,出生月? – pratiklodha