如何将datetime类型的变量从pig传递到python udf

8fsztsew  于 2021-06-21  发布在  Pig
关注(0)|答案(1)|浏览(402)

我的python udf代码born是pig的一个datetime变量,我尝试将它作为string对象,但它也给出了一个错误,将它作为datetime对象也给出了一个错误

from datetime import date

@outputSchema("age_key:chararray")
def agekeyed(born):
    today = date.today()
    return born[:4]

我得到一个错误:
typeerror:'org.joda.time.datetime'对象不可订阅

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
wfveoks0

wfveoks01#

born 是一个 org.joda.time.DateTime 对象和子字符串不能在此处应用。你需要通过考试 chararray 从pig到udf,或者用它的方法处理对象

rightnow.monthOfYear().getAsText()

相关问题