Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Plain View
Pig >> mail # user >> How to combine muliple group by


+
shan s 2012-05-15, 13:50
Copy link to this message
-
Re: How to combine muliple group by
You can combine multiple relations using the UNION operator. If you're
trying to combine logic, you can use a macro to do e2-e5 below that takes
(e1, empid) or (e1, group). See the example here:

http://hortonworks.com/blog/new-apache-pig-features-part-1-macro/

On Tue, May 15, 2012 at 6:50 AM, shan s <[EMAIL PROTECTED]> wrote:

> How can I combine multiple group by that are performed on essentially same
> relation?
> In the case below, can I do this in single foreach?
>
> e1 =  load 'emp' using PigStorage() as (empid, school, district, score);
>
> e2 = group e1 by empid;
> e3 = foreach e2 generate group, AVG(e1.score) as s;
> e4 = order e3 by s desc;
> e5 = limit e4 3;
> dump e5;
>
> e2 = group e1 by school;
> e3 = foreach e2 generate group, AVG(e1.score) as s;
> e4 = order e3 by s desc;
> e5 = limit e4 3;
> dump e5;
> Thank You,
> Prashant.
>

--
*Note that I'm no longer using my Yahoo! email address. Please email me at
[EMAIL PROTECTED] going forward.*
+
shan s 2012-05-15, 22:11
+
Alan Gates 2012-05-16, 00:39
+
shan s 2012-05-16, 16:50