use can use this ..
http://svn.apache.org/repos/asf/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/Over.java

 * DEFINE IOver org.apache.pig.piggybank.evaluation.Over('state_rk:int');
 * cities = LOAD 'cities' AS (city:chararray, state:chararray, pop:int);
 * -- Decorate each city with its population rank within the state it
belongs to:
 * ranked = FOREACH(GROUP cities BY state) {
 *   c_ord = ORDER cities BY pop DESC;
 *   GENERATE FLATTEN(Stitch(c_ord,
 *     IOver(c_ord, 'rank', -1, -1, 2))); -- beginning (-1) to end
(-1) on third field (2)
 * };
 * DESCRIBE ranked;
 * -- ranked: {stitched::city: chararray,stitched::state:
chararray,stitched::pop: int,stitched::state_rk: int}
 * DUMP ranked;
 * -- ...
 * -- (Nashville,Tennessee,609644,2)
 * -- (Houston,Texas,2145146,1)
 * -- (San Antonio,Texas,1359758,2)
 * -- (Dallas,Texas,1223229,3)
 * -- (Austin,Texas,820611,4)
 * -- ...


*Cheers !!*
Arvind

On Mon, Jan 26, 2015 at 4:27 PM, srinivas yaddanapudi <
[email protected]> wrote:

> > Hi Guys,
> >
> >
> >
> > I have a query that needs to compare previous value of a tuple to that of
> current value, and mark if there is change in the value.
> >
> >
> >
> > input:
> > year, AccNo
> > 1991 ,1234
> > 1992 ,1234
> > 1993 ,1234
> > 1991 ,1235
> > 1992 ,1235
> > 1991 ,1236
> > 1991 ,1237
> >
> >
> >
> > Output:-
> >
> > recyear ,AccNo, firstrec
> > 1991, 1234, 1
> > 1992, 1234, 0
> > 1993, 1234, 0
> > 1991,1235, 1
> > 1992, 1235, 0
> > 1991, 1236, 1
> > 1991, 1237, 1
> >
> >
> >
> > My Aprroch:-
> >
> >
> >
> > --adding two ranks
> > rank1 = rank input BY Accno,recyear;
> > rank2 = rank rank1 by Accno;
> >
> > --create first_rec
> > output = foreach rank2 generate *, ($0==$1?1:0) as first_rec;
> >
> >
> >
> >
> >
> > It doesn't seem to be working great , please can anyone give some idea if
> we have any anylytical fucntions to crack this.
> >
> >
> >
> > Thanks a lot
> >
> > Srinivas
>

Reply via email to