I have a working solution, but not as optimized as you like, in fact, I canβt get Pig to execute a complex shell statement in the declaration.
First I wrote a shell script (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 the pig script as follows (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 one line of text, in order to display our variable
I called the script as follows:
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)})
source share