<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Apache PIG - If Statement based on a count value in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Apache-PIG-If-Statement-based-on-a-count-value/m-p/135100#M39670</link>
    <description>&lt;P&gt;Hi experts,

I've this statment in Apache PIG:

...
Count = FOREACH data GENERATE SUM(Field);

...

How can do a IF Statement like this:

IF(SUM(Field) &amp;gt; 10)&lt;/P&gt;&lt;P&gt;Store into X;
ELSE
STORE into Y;


Is possible to do this? 

Many thanks!&lt;/P&gt;</description>
    <pubDate>Sun, 04 Sep 2016 21:53:54 GMT</pubDate>
    <dc:creator>prodgers125</dc:creator>
    <dc:date>2016-09-04T21:53:54Z</dc:date>
    <item>
      <title>Apache PIG - If Statement based on a count value</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Apache-PIG-If-Statement-based-on-a-count-value/m-p/135100#M39670</link>
      <description>&lt;P&gt;Hi experts,

I've this statment in Apache PIG:

...
Count = FOREACH data GENERATE SUM(Field);

...

How can do a IF Statement like this:

IF(SUM(Field) &amp;gt; 10)&lt;/P&gt;&lt;P&gt;Store into X;
ELSE
STORE into Y;


Is possible to do this? 

Many thanks!&lt;/P&gt;</description>
      <pubDate>Sun, 04 Sep 2016 21:53:54 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Apache-PIG-If-Statement-based-on-a-count-value/m-p/135100#M39670</guid>
      <dc:creator>prodgers125</dc:creator>
      <dc:date>2016-09-04T21:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Apache PIG - If Statement based on a count value</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Apache-PIG-If-Statement-based-on-a-count-value/m-p/135101#M39671</link>
      <description>&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/2985/antonio-scp125.html"&gt;@João Souza&lt;/A&gt;&lt;/P&gt;&lt;P&gt;This requirement is based around FILTER, which retrieves records that satisfy one or more conditions.&lt;/P&gt;&lt;P&gt;There are two ways to do this.&lt;/P&gt;&lt;P&gt;This first is using FILTER as below:&lt;/P&gt;&lt;PRE&gt;X = FILTER Count by Field &amp;gt;10; 
Y = FILTER Count by Field &amp;lt;=10; &lt;/PRE&gt;&lt;P&gt;The second way achieves the same result but using different grammar.&lt;/P&gt;&lt;PRE&gt;SPLIT Count into X if Field &amp;gt;10, Y if Field &amp;lt;=10;&lt;/PRE&gt;&lt;P&gt;Please note that the use of SUM requires a GROUP operation beforehand.  In your case, you would have needed to GROUP data before you summed it as shown in your first line of code.  &lt;/P&gt;&lt;P&gt;It would have to look something like the following. &lt;/P&gt;&lt;PRE&gt;data = LOAD ... as (amt:int, name:chararray);
grouped_data = GROUP data by name;
summed_data = FOREACH grouped_data GENERATE SUM(data.amt) amtSum, name; 
X = FILTER summed_data by amtSum &amp;gt;10; 
Y = FILTER summed_data by amtSum &amp;lt;=10; 
&lt;/PRE&gt;&lt;P&gt;See:&lt;/P&gt;&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://pig.apache.org/docs/r0.7.0/piglatin_ref2.html#SUM"&gt;https://pig.apache.org/docs/r0.7.0/piglatin_ref2.html#SUM&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="http://www.thomashenson.com/sum-field-apache-pig/"&gt;http://www.thomashenson.com/sum-field-apache-pig/&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;(Let me know if this is what you are looking for by accepting the answer).&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2016 02:24:20 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Apache-PIG-If-Statement-based-on-a-count-value/m-p/135101#M39671</guid>
      <dc:creator>gkeys</dc:creator>
      <dc:date>2016-09-05T02:24:20Z</dc:date>
    </item>
  </channel>
</rss>

