<?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 Re: how to handle null or empty scenarios in foreach in pigscript? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-handle-null-or-empty-scenarios-in-foreach-in/m-p/124173#M22624</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/3094/mhdeshmukh22.html" nodeid="3094"&gt;@Mahesh Deshmukh&lt;/A&gt; I'm not sure what your need is, but null values should be filtered first. The general rule of thumb in Pig is to "filter early and often" to minimize the amount of data that gets shuffled and sorted, so before the foreach:&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;PRE&gt;a = "some Pig relation"
b = filter a by $1 is not null;   //filter out tuples where the $1 field is null
c = foreach b generate ...	  //no need to worry about $1 being null&lt;/PRE&gt;&lt;P&gt;The term "empty" refers to bags typically, and in particular you can use the isEmpty function to check if a bag is empty. You normally do this after a GROUP command:&lt;/P&gt;&lt;PRE&gt;a = "some Pig relation"
b = group a by $3;
c = filter b by not IsEmpty(group);&lt;/PRE&gt;&lt;P&gt;What are you trying to accomplish? &lt;/P&gt;</description>
    <pubDate>Sat, 12 Mar 2016 22:52:21 GMT</pubDate>
    <dc:creator>rich1</dc:creator>
    <dc:date>2016-03-12T22:52:21Z</dc:date>
    <item>
      <title>how to handle null or empty scenarios in foreach in pigscript?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-handle-null-or-empty-scenarios-in-foreach-in/m-p/124171#M22622</link>
      <description />
      <pubDate>Sat, 12 Mar 2016 16:35:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-handle-null-or-empty-scenarios-in-foreach-in/m-p/124171#M22622</guid>
      <dc:creator>mhdeshmukh22</dc:creator>
      <dc:date>2016-03-12T16:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to handle null or empty scenarios in foreach in pigscript?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-handle-null-or-empty-scenarios-in-foreach-in/m-p/124172#M22623</link>
      <description>&lt;P&gt;Please see the official docs. Both null and IsEmpty is addressed &lt;A href="https://pig.apache.org/docs/r0.15.0/basic.html#nulls" target="_blank"&gt;https://pig.apache.org/docs/r0.15.0/basic.html#nulls&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Mar 2016 16:48:37 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-handle-null-or-empty-scenarios-in-foreach-in/m-p/124172#M22623</guid>
      <dc:creator>aervits</dc:creator>
      <dc:date>2016-03-12T16:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to handle null or empty scenarios in foreach in pigscript?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-handle-null-or-empty-scenarios-in-foreach-in/m-p/124173#M22624</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/3094/mhdeshmukh22.html" nodeid="3094"&gt;@Mahesh Deshmukh&lt;/A&gt; I'm not sure what your need is, but null values should be filtered first. The general rule of thumb in Pig is to "filter early and often" to minimize the amount of data that gets shuffled and sorted, so before the foreach:&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;PRE&gt;a = "some Pig relation"
b = filter a by $1 is not null;   //filter out tuples where the $1 field is null
c = foreach b generate ...	  //no need to worry about $1 being null&lt;/PRE&gt;&lt;P&gt;The term "empty" refers to bags typically, and in particular you can use the isEmpty function to check if a bag is empty. You normally do this after a GROUP command:&lt;/P&gt;&lt;PRE&gt;a = "some Pig relation"
b = group a by $3;
c = filter b by not IsEmpty(group);&lt;/PRE&gt;&lt;P&gt;What are you trying to accomplish? &lt;/P&gt;</description>
      <pubDate>Sat, 12 Mar 2016 22:52:21 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-handle-null-or-empty-scenarios-in-foreach-in/m-p/124173#M22624</guid>
      <dc:creator>rich1</dc:creator>
      <dc:date>2016-03-12T22:52:21Z</dc:date>
    </item>
  </channel>
</rss>

