使用Python进行Hive转换:无法初始化自定义脚本

时间:2015-02-20 20:25:44

标签: python hadoop hive

我正在尝试通过将Python脚本作为映射器来测试Hive TRANSFORM。我的蜂巢脚本是:

add file  /full/path/to/mapper.py;

set mapred.job.queue.name=queue_name;

use my_database;

select transform(s.year, s.month, s.day, s.hour) 
using 'mapper.py' 
from my_table s limit 10; 

我的Python映射器脚本只是试图回显输入:

#!/usr/local/bin/python
import sys
for line in sys.stdin:
    print line

我尝试使用以下组合运行它:

  1. 移除配置单元脚本中的add file ...并在mapper.py声明中提供select ...的完整路径

  2. 保持add file ...和mapper的完整路径:/path/to/mapper.py

  3. 保持映射器的add file ...和相对路径:./mapper.py

  4. 尝试使用AS子句选择映射器输出(using 'mapper.py' as line

  5. 到目前为止,上述所有尝试都导致Hive报告无法初始化我的自定义脚本:

    FAILED: Execution Error, return code 20000 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask. Unable to initialize custom script.
    

    我无法理解这种“初始化”的本质。 Hive无法

    1. 找到我的脚本(即路径问题)?
    2. 找到python可执行文件(即#! shebang)
    3. 我正在关注Hive tutorial中的“自定义地图/缩小脚本”。

1 个答案:

答案 0 :(得分:6)

通过将我的select...声明修改为

来解决此问题
add file  /full/path/to/mapper.py;
select transform(s.year, s.month, s.day, s.hour) 
using ' python mapper.py' --<--- This line changed
from my_table s limit 10; 

Reference post