在 pig 脚本中执行 shell 命令时出错 [英] Error executing shell command in pig script
问题描述
我有一个 pig 脚本,一开始我想从某个日期生成过去 7 天的日期字符串(后来用于检索那些天的日志文件).我尝试用这一行来做到这一点:%declare CMD7 input= ;对于 {1..6} 中的 i;do d=$(date -d "$DATE -i 天" "+%Y-%m-%d");input="\$input\$d,";完毕;回声 \$input
I have a pig script where in the beginning I would like to generate a string of the dates of the past 7 days from a certain date (later used to retrieve log files for those days).
I attempt to do this with this line:
%declare CMD7 input= ; for i in {1..6}; do d=$(date -d "$DATE -i days" "+%Y-%m-%d"); input="\$input\$d,"; done; echo \$input
我收到一个错误:" 错误 2999: 意外内部错误.执行 shell 命令时出错: input= ; for i in {1..6}; do d=$(date -d "2012-07-10 -i days" "+%Y-%m-%d"); input="$input$d,"; done;. 命令退出,退出代码为 127"
但是shell命令在pig之外运行得很好.我真的不确定这里出了什么问题.
I get an error :
" ERROR 2999: Unexpected internal error. Error executing shell command: input= ; for i in {1..6}; do d=$(date -d "2012-07-10 -i days" "+%Y-%m-%d"); input="$input$d,"; done;. Command exit with exit code of 127"
however the shell command runs perfectly fine outside of pig. I am really not sure what is going wrong here.
谢谢!
推荐答案
我有一个可行的解决方案,但没有你想要的那么精简,基本上我没有设法让 Pig 在声明中执行复杂的 shell 语句.
I have got a working solution but not as streamlined as you want, essentially I don't manage to get Pig to execute a complex shell statement in the declare.
我首先写了一个 shell 脚本(我们称之为 6-days-back-from.sh):
I first wrote a shell script (let's call it 6-days-back-from.sh):
#!/bin/bash
DATE=$1
for i in {1..6}; do d=$( date -d "$DATE -$i days" +%F ) ; echo -n "$d "; done
然后一个猪脚本如下(我们称之为days.pig):
Then a pig script as follow (let's call it days.pig):
%declare my_date `./6-days-back-from.sh $DATE`
A = LOAD 'dual' USING PigStorage();
B = FOREACH A GENERATE '$my_date';
DUMP B
注意 dual 是一个包含单行文本的文本文件的目录,用于显示我们的变量
note that dual is a directory containing a text file with a single line of text, for the purpose of displaying our variable
我调用脚本如下:
pig -x local -param DATE="2012-08-03" days.pig
并得到以下输出:
({(2012-08-02),(2012-08-01),(2012-07-31),(2012-07-30),(2012-07-29),(2012-07-28)})
这篇关于在 pig 脚本中执行 shell 命令时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!