- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
how to handle null or empty scenarios in foreach in pigscript?
- Labels:
-
Apache Pig
Created ‎03-12-2016 08:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Created ‎03-12-2016 02:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Mahesh Deshmukh 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:
For example:
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
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:
a = "some Pig relation" b = group a by $3; c = filter b by not IsEmpty(group);
What are you trying to accomplish?
Created ‎03-12-2016 08:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please see the official docs. Both null and IsEmpty is addressed https://pig.apache.org/docs/r0.15.0/basic.html#nulls
Created ‎03-12-2016 02:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Mahesh Deshmukh 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:
For example:
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
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:
a = "some Pig relation" b = group a by $3; c = filter b by not IsEmpty(group);
What are you trying to accomplish?
