0

I have a relation J2, which looks like (Popp,{(100)}) (Urman,{(100)}) (Sciarra,{(100)}) (Chen,{(100)}) (Faviet,{(100)}) (Gietz,{()}) (Higgins,{()}) (LAST_NAME,{()}) (Grant,{()}).... i have to test whether the bag is empty or not, so tried :S = FILTER J2 BY IsEmpty($1);.. it is getting executed successfully but the output is empty. Can anyone please guide me on this. Is there any prerequisites to use IsEmpty()?

Note:DESCRIBE J2 gives "{AA::LAST_NAME: chararray,{(int)}}"

pam18
  • 33
  • 2

1 Answers1

0

Here's the explanation: You had bags contains tuples, so in the following case: Gietz,{()} the bag itself is not empty has an empty tuple in it. So let's test the following input:

Urman,{(100)}
Gietz,{()}
LAST_NAME,{} 

If you project the SIZE of the bags you'll get the following results:

(Urman,1)
(Gietz,1)
(LAST_NAME,0)

Gietz's bag size is also 1 because it contains a tuple and it doesent matter if the tuple itself is empty.

How to do it: (This is one working solution)

data = LOAD 'SO/name.txt' USING PigStorage(',') AS (name:chararray,b:bag{(val:int)});
DESCRIBE data;
a = FOREACH data GENERATE name AS name, b AS b, FLATTEN($1) AS x;
b = FILTER a BY x IS NULL;
DUMP a;

It dumps:

(Gietz,{()},)
(Higgins,{()},)
(LAST_NAME,{()},)
(Grant,{()},)

Input:

Popp,{(100)} 
Urman,{(100)}
Sciarra,{(100)} 
Chen,{(100)}
Faviet,{(100)} 
Gietz,{()}
Higgins,{()}
LAST_NAME,{()} 
Grant,{()}
kecso
  • 2,387
  • 2
  • 18
  • 29