4

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

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.

Thank you!

YuliaPro
  • 305
  • 1
  • 7
  • 16

1 Answers1

6

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.

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

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

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

and got the following output:

({(2012-08-02),(2012-08-01),(2012-07-31),(2012-07-30),(2012-07-29),(2012-07-28)})
Samuel Kerrien
  • 6,965
  • 2
  • 29
  • 32