You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by soniya B <so...@gmail.com> on 2013/04/27 16:53:01 UTC

BinCond

Hi,

Anyone can explain me about use of BinCond function with an example?  I am
trying a lot but didn't work it.

Regards
Soniya

Re: BinCond

Posted by soniya B <so...@gmail.com>.
Hi Tariq,

Thank you for explanation. I have multiple conditions to verify in a
relation. How can check multiple expressions for one field?

Thanks
Soniya





On Sun, Apr 28, 2013 at 4:20 AM, Mohammad Tariq <do...@gmail.com> wrote:

> Hello Soniya,
>
>        It's like the ternary or the conditional operator available in java
> and works just like that. Here is the example provided in the reference
> manual :
>
> *Suppose we have relation A.*
>
> A = LOAD 'data' AS (f1:int, f2:int, B:bag{T:tuple(t1:int,t2:int)});
>
> DUMP A;
> (10,1,{(2,3),(4,6)})
> (10,3,{(2,3),(4,6)})
> (10,6,{(2,3),(4,6),(5,7)})
>
> *In this example the modulo operator is used with fields f1 and f2.*
>
> X = FOREACH A GENERATE f1, f2, f1%f2;
>
> DUMP X;
> (10,1,0)
> (10,3,1)
> (10,6,4)
>
> *In this example the bincond operator is used with fields f2 and B. The
> condition is "f2 equals 1"; if the condition is true, return 1; if the
> condition is false, return the count of the number of tuples in B.*
>
> X = FOREACH A GENERATE f2, (f2==1?1:COUNT(B));
>
> DUMP X;
> (1,1L)
> (3,2L)
> (6,3L)
>
>
> It clearly shows that when "f2==1", which is the first case the exp
> evaluates to true, hence "1" is returned and count(B) is returned in rest
> of the 2 cases as exp evaluates to false.
>
> What were you trying to do and what exactly is the problem which you are
> facing?
>
> Warm Regards,
> Tariq
> https://mtariq.jux.com/
> cloudfront.blogspot.com
>
>
> On Sat, Apr 27, 2013 at 8:23 PM, soniya B <so...@gmail.com>
> wrote:
>
> > Hi,
> >
> > Anyone can explain me about use of BinCond function with an example?  I
> am
> > trying a lot but didn't work it.
> >
> > Regards
> > Soniya
> >
>

Re: BinCond

Posted by Mohammad Tariq <do...@gmail.com>.
Hello Soniya,

       It's like the ternary or the conditional operator available in java
and works just like that. Here is the example provided in the reference
manual :

*Suppose we have relation A.*

A = LOAD 'data' AS (f1:int, f2:int, B:bag{T:tuple(t1:int,t2:int)});

DUMP A;
(10,1,{(2,3),(4,6)})
(10,3,{(2,3),(4,6)})
(10,6,{(2,3),(4,6),(5,7)})

*In this example the modulo operator is used with fields f1 and f2.*

X = FOREACH A GENERATE f1, f2, f1%f2;

DUMP X;
(10,1,0)
(10,3,1)
(10,6,4)

*In this example the bincond operator is used with fields f2 and B. The
condition is "f2 equals 1"; if the condition is true, return 1; if the
condition is false, return the count of the number of tuples in B.*

X = FOREACH A GENERATE f2, (f2==1?1:COUNT(B));

DUMP X;
(1,1L)
(3,2L)
(6,3L)


It clearly shows that when "f2==1", which is the first case the exp
evaluates to true, hence "1" is returned and count(B) is returned in rest
of the 2 cases as exp evaluates to false.

What were you trying to do and what exactly is the problem which you are
facing?

Warm Regards,
Tariq
https://mtariq.jux.com/
cloudfront.blogspot.com


On Sat, Apr 27, 2013 at 8:23 PM, soniya B <so...@gmail.com> wrote:

> Hi,
>
> Anyone can explain me about use of BinCond function with an example?  I am
> trying a lot but didn't work it.
>
> Regards
> Soniya
>