在Pig脚本中执行Shell命令时出错 [英] Error executing shell command in pig script

查看:112
本文介绍了在Pig脚本中执行Shell命令时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个猪脚本,在开始时,我想从特定日期生成一串过去7天的日期的字符串(后来用于检索那几天的日志文件). 我尝试使用此行执行此操作: %声明CMD7 input= ; for i in {1..6}; do d=$(date -d "$DATE -i days" "+%Y-%m-%d"); input="\$input\$d,"; done; echo \$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命令时出错:输入=;对于{1..6}中的i;执行d = $(date -d" 2012-07-10 -i days" +%Y-% m-%d); input =" $ input $ d,;完成;退出命令,退出代码为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

我按如下方式调用了脚本:

I called the script as follow:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆