首页 > 解决方案 > 使用 Pandas 抛出错误在 Python 中编写 UDF

问题描述

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

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

我们已经尝试了 Pandas 的各种方式,但不幸的是没有运气。由于其他没有 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

标签: pythonpandashivehive-udf

解决方案


I think you'll need to look at the detailed job logs for more information. My first guess is that Pandas is not installed on a data node.

This answer looks appropriate for you if you intend to bundle dependencies with your job: https://stackoverflow.com/a/2869974/7379644


推荐阅读