pig-user  

Re: BinCond related parse exceptions.

Alan Gates
Fri, 28 Mar 2008 09:54:20 -0700

Rewriting your query as:
C = FOREACH B {
        D1 = FILTER A by  ( $0 eq 'val1' ) ;
        D2 = FILTER A by  ( $1 eq 'val2' ) ;
        D3 = FILTER A by  ( $2 eq 'val3' ) ;
GENERATE (((COUNT(D1) > '0') and (COUNT(D2) > '0') and (COUNT(D3) > '0')) ? $1 : $0);
};

seems to work. I'm not sure why it doesn't like it in the form you wrote it.

Alan.

On Mar 27, 2008, at 3:31 PM, Mridul Muralidharan wrote:

Hi,

I am trying to execute the attached pig script - and run into parse exceptions. Removing the outer BinCond does not result in parse errors ( cond == 3 ) - but is not the functionality I require : essentially, if all constraints are satisfied by some arbitrary set of tuples in A, then generate $1 else $0.

Thanks in advance for any pointers, suggestions or help.
Regards,
Mridul


A = load './a' USING PigStorage('\t');

B = GROUP A by $0;

C = FOREACH B {
  D1 = FILTER A by  ( $0 eq 'val1' ) ;
  D2 = FILTER A by  ( $1 eq 'val2' ) ;
  D3 = FILTER A by  ( $2 eq 'val3' ) ;
GENERATE ( ( ( COUNT (D1) > 0 ? '1' : '0' ) + ( COUNT (D2) > 0 ? '1' : '0' ) + ( COUNT (D3) > 0 ? '1' : '0' ) ) == '3' ? $1 : $0 ) };

DUMP C;