使用Pandas抛出错误在Python中编写UDF

时间:2018-12-20 07:26:30

标签: python pandas hive hive-udf

我们正在尝试用Python编写Hive的UDF来清理数据。我们尝试过的UDF使用的是Pandas,并且抛出了错误。

当我们尝试使用另一个没有Pandas的python代码时,它工作正常。请帮助理解问题。在下面提供熊猫代码:

我们已经尝试过各种熊猫方法,但不幸的是没有运气。由于其他没有Pandas的Python代码运行正常,我们感到困惑,为什么它失败了?

import sys
import pandas as pd
import numpy as np
for line in sys.stdin:
    df = line.split('\t')
    df1 = pd.DataFrame(df)
    df2=df1.T
    df2[0] = np.where(df2[0].str.isalpha(), df2[0], np.nan)
    df2[1] = np.where(df2[1].astype(str).str.isdigit(), df2[1], np.nan)
    df2[2] = np.where(df2[2].astype(str).str.len() != 10, np.nan, 
    df2[2].astype(str))
    #df2[3] = np.where(df2[3].astype(str).str.isdigit(), df2[3], np.nan)
    df2 = df2.dropna()
    print(df2)

我收到此错误:

FAILED: Execution Error, return code 20003 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask. An error occurred when trying to close the Operator running your custom script.
MapReduce Jobs Launched: 
Stage-Stage-1: Map: 1   HDFS Read: 0 HDFS Write: 0 FAIL
Total MapReduce CPU Time Spent: 0 msec

1 个答案:

答案 0 :(得分:0)

我认为您需要查看详细的作业日志以获取更多信息。 我的第一个猜测是Pandas没有安装在数据节点上。

如果您打算将依赖项与工作捆绑在一起,则此答案对您来说很合适:https://stackoverflow.com/a/2869974/7379644

相关问题