

{"id":13958,"date":"2018-04-19T12:24:52","date_gmt":"2018-04-19T12:24:52","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=13958"},"modified":"2018-04-19T12:24:52","modified_gmt":"2018-04-19T12:24:52","slug":"apache-pig-built-in-functions","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/","title":{"rendered":"Apache Pig Built in Functions Cheat Sheet"},"content":{"rendered":"<p><span style=\"font-weight: 400\">In this article &#8220;Apache Pig Built in Functions&#8221;, we will discuss all the <strong>Apache Pig<\/strong> Built-in Functions in detail. It includes eval, load\/store, math, bag and tuple functions and many more. Also, we will see their syntax along with their functions and descriptions to understand them well.<\/span><\/p>\n<p>So, let&#8217;s start Pig Built in Functions.<\/p>\n<h2><span style=\"font-weight: 400\">Pig Functions<\/span><\/h2>\n<p><span style=\"font-weight: 400\">There is a huge set of Apache Pig Built in Functions available. Such as the eval, load\/store, math, string, date and time, bag and tuple functions. Basically, there are two main properties which differentiate built in functions from user-defined functions (UDFs) such as:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">We do not need to register built in functions since Pig knows where they are. <\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Also, we do not need to qualify built in functions, while using them, because again Pig knows where to find them.<\/span><\/li>\n<\/ul>\n<h2><span style=\"font-weight: 400\">List of Apache Pig Built in Functions<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Let\u2019s discuss various Apache Pig Built in Functions namely eval, load, store, math, string, bag, and tuple, one by one in depth. <\/span><\/p>\n<h3><span style=\"font-weight: 400\">a. Eval Functions<\/span><\/h3>\n<p>Eval Functions is the first types of Pig Built in Functions.\u00a0<span style=\"font-weight: 400\">Here are the Pig Eval functions, offered by Apache Pig.<\/span><br \/>\n<strong>i. AVG()<\/strong><\/p>\n<ul>\n<li><strong>AVG Syntax<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">AVG(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">We use AVG(), to compute the average of the numerical values within a bag.<\/span><\/p>\n<ul>\n<li><strong>AVG Example<\/strong><\/li>\n<\/ul>\n<p>In this example, the average GPA for each Employee is computed<br \/>\nA = LOAD &#8216;Employee.txt&#8217; AS (name:chararray, term:chararray, gpa:float);<br \/>\nDUMP A;<br \/>\n(johny,fl,3.9F)<br \/>\n(johny,wt,3.7F)<br \/>\n(johny,sp,4.0F)<br \/>\n(johny,sm,3.8F)<br \/>\n(Mariya,fl,3.8F)<br \/>\n(Mariya,wt,3.9F)<br \/>\n(Mariya,sp,4.0F)<br \/>\n(Mariya,sm,4.0F)<br \/>\nB = GROUP A BY name;<br \/>\nDUMP B;<br \/>\n(johny,{(johny,fl,3.9F),(johny,wt,3.7F),(johny,sp,4.0F),(johny,sm,3.8F)})<br \/>\n(Mariya,{(Mariya,fl,3.8F),(Mariya,wt,3.9F),(Mariya,sp,4.0F),(Mariya,sm,4.0F)})<br \/>\nC = FOREACH B GENERATE A.name, AVG(A.gpa);<br \/>\nDUMP C;<br \/>\n({(johny),(johny),(johny),(johny)},3.850000023841858)<br \/>\n({(Mariya),(Mariya),(Mariya),(Mariya)},3.925000011920929)<\/p>\n<p><strong>ii. BagToString()<\/strong><br \/>\n<span style=\"font-weight: 400\">This function is used to concatenate the elements of a bag into a string. We can place a delimiter between these values (optional) while concatenating.<\/span><\/p>\n<p><strong>iii. CONCAT()<\/strong><\/p>\n<ul>\n<li><strong>The syntax of CONCAT()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">CONCAT (expression, expression)<\/span><br \/>\n<span style=\"font-weight: 400\">We use this Pig Function to concatenate two or more expressions of the same type.<\/span><\/p>\n<ul>\n<li><strong>Example of\u00a0CONCAT()<\/strong><\/li>\n<\/ul>\n<p>In this example, fields f1, an underscore string literal, f2 and f3 are concatenated.<br \/>\nX = LOAD &#8216;data&#8217; as (f1:chararray, f2:chararray, f3:chararray);<br \/>\nDUMP X;<br \/>\n(apache,open,source)<br \/>\n(hadoop,map,reduce)<br \/>\n(pig,pig,latin)<br \/>\nY = FOREACH X GENERATE CONCAT(f1, &#8216;_&#8217;, f2,f3);<br \/>\nDUMP Y;<br \/>\n(apache_opensource)<br \/>\n(hadoop_mapreduce)<br \/>\n(pig_piglatin)<\/p>\n<p><strong>iv. COUNT()<\/strong><\/p>\n<ul>\n<li><span style=\"font-weight: 400\"><strong>The syntax of COUNT()<\/strong>\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">COUNT(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">While counting the number of tuples in a bag, we use it to get the number of elements in a bag.<\/span><\/p>\n<ul>\n<li><strong>Example of COUNT()<\/strong><\/li>\n<\/ul>\n<p>In this example, we count the tuples in the bag:<br \/>\nX = LOAD &#8216;data&#8217; AS (f1:int,f2:int,f3:int);<br \/>\nDUMP X;<br \/>\n(1,2,3)<br \/>\n(4,2,1)<br \/>\n(8,3,4)<br \/>\n(4,3,3)<br \/>\n(7,2,5)<br \/>\n(8,4,3)<br \/>\nY = GROUP X BY f1;<br \/>\nDUMP B;<br \/>\n(1,{(1,2,3)})<br \/>\n(4,{(4,2,1),(4,3,3)})<br \/>\n(7,{(7,2,5)})<br \/>\n(8,{(8,3,4),(8,4,3)})<br \/>\nA = FOREACH Y GENERATE COUNT(X);<br \/>\nDUMP A;<br \/>\n(1L)<br \/>\n(2L)<br \/>\n(1L)<br \/>\n(2L)<\/p>\n<p><strong>v. COUNT_STAR()<\/strong><\/p>\n<ul>\n<li><strong>The syntax of COUNT_STAR()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">COUNT_STAR(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">We can say it is similar to the COUNT() function. To get the number of elements in a bag, we use it.<\/span><\/p>\n<ul>\n<li><strong>Example of COUNT_STAR()<\/strong><\/li>\n<\/ul>\n<p>To count the tuples in a bag.<br \/>\nA = FOREACH Y GENERATE COUNT_STAR(X);<br \/>\n<strong>vi. DIFF()<\/strong><\/p>\n<ul>\n<li><strong>The syntax of DIFF()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">DIFF (expression, expression)<\/span><br \/>\n<span style=\"font-weight: 400\">In order to compare two bags (fields) in a tuple.<\/span><\/p>\n<ul>\n<li><strong>Example of DIFF()<\/strong><\/li>\n<\/ul>\n<p>Here, compares the tuples in two bags.<br \/>\nA = LOAD &#8216;bag_data&#8217; AS (B1:bag{T1:tuple(t1:int,t2:int)},B2:bag{T2:tuple(f1:int,f2:int)});<br \/>\nDUMP A;<br \/>\n({(8,9),(0,1)},{(8,9),(1,1)})<br \/>\n({(2,3),(4,5)},{(2,3),(4,5)})<br \/>\n({(6,7),(3,7)},{(2,2),(3,7)})<br \/>\nDESCRIBE A;<br \/>\na: {B1: {T1: (t1: int,t2: int)},B2: {T2: (f1: int,f2: int)}}<br \/>\nX = FOREACH A GENERATE DIFF(B1,B2);<br \/>\ngrunt&gt; dump x;<br \/>\n({(0,1),(1,1)})<br \/>\n({})<br \/>\n({(6,7),(2,2)})<\/p>\n<p><strong>vii. IsEmpty()<\/strong><\/p>\n<ul>\n<li><strong>The Syntax of IsEmpty ()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">IsEmpty(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">We use this Apache Pig function to check if a bag or map is empty.<\/span><\/p>\n<ul>\n<li><strong>Example of IsEmpty ()<\/strong><\/li>\n<\/ul>\n<p>Here, all Employees with an SSN but no name are located.<br \/>\nSSN = load &#8216;ssn.txt&#8217; using PigStorage() as (ssn:long);<br \/>\nSSN_NAME = load &#8216;Employees.txt&#8217; using PigStorage() as (ssn:long, name:chararray);<br \/>\n\/* do a cogroup of SSN with SSN_Name *\/<br \/>\nX = COGROUP SSN by ssn, SSN_NAME by ssn;<br \/>\n\/* Keep ssn&#8217;s for which there is no name only *\/<br \/>\nY = filter X by IsEmpty(SSN_NAME);<\/p>\n<p><strong>viii. MAX()<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>The Syntax of MAX()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">MAX(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">Basically, to calculate the highest value for a column (numeric values or chararrays) in a single-column bag.<\/span><\/p>\n<ul>\n<li><strong>Example of\u00a0<\/strong><strong>MAX()<\/strong><\/li>\n<\/ul>\n<p>A = LOAD &#8216;Employee&#8217; AS (name:chararray, session:chararray, gpa:float);<br \/>\nDUMP A;<br \/>\n(Johny,fl,3.9F)<br \/>\n(Johny,wt,3.7F)<br \/>\n(Johny,sp,4.0F)<br \/>\n(Johny,sm,3.8F)<br \/>\n(Mariya,fl,3.8F)<br \/>\n(Mariya,wt,3.9F)<br \/>\n(Mariya,sp,4.0F)<br \/>\n(Mariya,sm,4.0F)<br \/>\nB = GROUP A BY name;<br \/>\nDUMP B;<br \/>\n(Johny,{(Johny,fl,3.9F),(Johny,wt,3.7F),(Johny,sp,4.0F),(Johny,sm,3.8F)})<br \/>\n(Mariya,{(Mariya,fl,3.8F),(Mariya,wt,3.9F),(Mariya,sp,4.0F),(Mariya,sm,4.0F)})<br \/>\nX = FOREACH B GENERATE group, MAX(A.gpa);<br \/>\nDUMP X;<br \/>\n(Johny,4.0F)<br \/>\n(Mariya,4.0F)<\/p>\n<p><strong>ix. MIN()<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>The Syntax of MIN()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">MIN(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">In order to get the minimum (lowest) value (numeric or chararray) for a certain column in a single-column bag.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>Example of MIN()<\/strong><\/li>\n<\/ul>\n<p>A = LOAD &#8216;Employee&#8217; AS (name:chararray, session:chararray, gpa:float);<br \/>\nDUMP A;<br \/>\n(Johny,fl,3.9F)<br \/>\n(Johny,wt,3.7F)<br \/>\n(Johny,sp,4.0F)<br \/>\n(Johny,sm,3.8F)<br \/>\n(Mariya,fl,3.8F)<br \/>\n(Mariya,wt,3.9F)<br \/>\n(Mariya,sp,4.0F)<br \/>\n(Mariya,sm,4.0F)<br \/>\nB = GROUP A BY name;<br \/>\nDUMP B;<br \/>\n(Johny,{(Johny,fl,3.9F),(Johny,wt,3.7F),(Johny,sp,4.0F),(Johny,sm,3.8F)})<br \/>\n(Mariya,{(Mariya,fl,3.8F),(Mariya,wt,3.9F),(Mariya,sp,4.0F),(Mariya,sm,4.0F)})<br \/>\nX = FOREACH B GENERATE group, MIN(A.gpa);<br \/>\nDUMP X;<br \/>\n(Johny,3.7F)<br \/>\n(Mariya,3.8F)<\/p>\n<p><strong>x. PluckTuple()<\/strong><br \/>\n<span style=\"font-weight: 400\">We can define a string prefix and filter the columns in a relation that begin with the given prefix, using the Pig Latin PluckTuple() function.<\/span><\/p>\n<ul>\n<li><strong>Example of PluckTuple<\/strong><\/li>\n<\/ul>\n<p>a = load &#8216;a&#8217; as (x, y);<br \/>\nb = load &#8216;b&#8217; as (x, y);<br \/>\nc = join a by x, b by x;<br \/>\nDEFINE pluck PluckTuple(&#8216;a::&#8217;);<br \/>\nd = foreach c generate FLATTEN(pluck(*));<br \/>\ndescribe c;<br \/>\nc: {a::x: bytearray,a::y: bytearray,b::x: bytearray,b::y: bytearray}<br \/>\ndescribe d;<br \/>\nd: {plucked::a::x: bytearray,plucked::a::y: bytearray}<br \/>\nDEFINE pluckNegative PluckTuple(&#8216;a::&#8217;,&#8217;false&#8217;);<br \/>\nd = foreach c generate FLATTEN(pluckNegative(*));<br \/>\ndescribe d;<br \/>\nd: {plucked::b::x: bytearray,plucked::b::y: bytearray}<\/p>\n<p><strong>xi. SIZE()<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>The Syntax of SIZE()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">SIZE(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">We use this Pig Function in order to compute the number of elements based on any Pig data type.<\/span><\/p>\n<ul>\n<li><strong>Example of SIZE()<\/strong><\/li>\n<\/ul>\n<p>Here, we are computing the number of characters in the first field<br \/>\nA = LOAD &#8216;data&#8217; as (f1:chararray, f2:chararray, f3:chararray);<br \/>\n(apache,open,source)<br \/>\n(hadoop,map,reduce)<br \/>\n(pig,pig,latin)<br \/>\nX = FOREACH A GENERATE SIZE(f1);<br \/>\nDUMP X;<br \/>\n(6L)<br \/>\n(6L)<br \/>\n(3L)<\/p>\n<p><strong>xii. SUBTRACT()<\/strong><br \/>\n<span style=\"font-weight: 400\">Basically, to subtract two bags. As a process, it takes two bags as inputs. Then returns a bag which contains the tuples of the first bag that are not in the second bag.<\/span><\/p>\n<ul>\n<li><strong>Example of\u00a0SUBTRACT()<\/strong><\/li>\n<\/ul>\n<p>It creates a new bag composed of B1 elements that are not in B2.<br \/>\nA = LOAD &#8216;bag_data&#8217; AS (B1:bag{T1:tuple(t1:int,t2:int)},B2:bag{T2:tuple(f1:int,f2:int)});<br \/>\nDUMP A;<br \/>\n({(8,9),(0,1),(1,2)},{(8,9),(1,1)})<br \/>\n({(2,3),(4,5)},{(2,3),(4,5)})<br \/>\n({(6,7),(3,7),(3,7)},{(2,2),(3,7)})<br \/>\nDESCRIBE A;<br \/>\nA: {B1: {T1: (t1: int,t2: int)},B2: {T2: (f1: int,f2: int)}}<br \/>\nX = FOREACH A GENERATE SUBTRACT(B1,B2);<br \/>\nDUMP X;<br \/>\n({(0,1),(1,2)})<br \/>\n({})<br \/>\n({(6,7)})<\/p>\n<p><strong>xiii. SUM()<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>Syntax of SUM()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">SUM(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">This Function in Pig is to get the total of the numeric values of a column in a single-column bag.<\/span><\/p>\n<ul>\n<li><strong>Example of SUM()<\/strong><\/li>\n<\/ul>\n<p>It creates a new bag composed of B1 elements that are not in B2.<br \/>\nA = LOAD &#8216;bag_data&#8217; AS (B1:bag{T1:tuple(t1:int,t2:int)},B2:bag{T2:tuple(f1:int,f2:int)});<br \/>\nDUMP A;<br \/>\n({(8,9),(0,1),(1,2)},{(8,9),(1,1)})<br \/>\n({(2,3),(4,5)},{(2,3),(4,5)})<br \/>\n({(6,7),(3,7),(3,7)},{(2,2),(3,7)})<br \/>\nDESCRIBE A;<br \/>\nA: {B1: {T1: (t1: int,t2: int)},B2: {T2: (f1: int,f2: int)}}<br \/>\nX = FOREACH A GENERATE SUBTRACT(B1,B2);<br \/>\nDUMP X;<br \/>\n({(0,1),(1,2)})<br \/>\n({})<br \/>\n({(6,7)})<br \/>\nB = GROUP A BY owner;<br \/>\nDUMP B;<br \/>\n(Alice,{(Alice,turtle,1),(Alice,goldfish,5),(Alice,cat,2)})<br \/>\n(Bob,{(Bob,dog,2),(Bob,cat,2)})<br \/>\nX = FOREACH B GENERATE group, SUM(A.pet_num);<br \/>\nDUMP X;<br \/>\n(Alice,8L)<br \/>\n(Bob,4L)<\/p>\n<p><strong>xiv. TOKENIZE()<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>Syntax of TOKENIZE()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">TOKENIZE(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">For splitting a string (which contains a group of words) in a single tuple. Then return a bag which contains the output of the split operation.<\/span><\/p>\n<ul>\n<li><strong>Example of TOKENIZE()<\/strong><\/li>\n<\/ul>\n<p>The strings in each row are split.<br \/>\nA = LOAD &#8216;data&#8217; AS (f1:chararray);<br \/>\nDUMP A;<br \/>\n(It is the first string.)<br \/>\n(It is the second string.)<br \/>\n(It is the third string.)<br \/>\nX = FOREACH A GENERATE TOKENIZE(f1);<br \/>\nDUMP X;<br \/>\n({(It),(is),(the),(first),(string.)})<br \/>\n({(It),(is),(the),(second),(string.)})<br \/>\n({(It),(is),(the),(third),(string.)})<br \/>\nHere, a field delimiter is specified.<br \/>\n{code}<br \/>\nA = LOAD &#8216;data&#8217; AS (f1:chararray);<br \/>\nB = FOREACH A GENERATE TOKENIZE (f1,&#8217;||&#8217;);<br \/>\nDUMP B;<br \/>\n{code}<\/p>\n<h3><span style=\"font-weight: 400\">b. Load and Store Functions<\/span><\/h3>\n<p><span style=\"font-weight: 400\">To determine, how data goes into Pig and comes out of Pig we use Load\/store functions &#8211; Pig Built in Functions. Also, we can write your own load\/store functions. There is a set of built-in load\/store functions such as:<\/span><\/p>\n<p><strong>i. PigStorage()<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>Syntax of PigStorage()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">PigStorage(field_delimiter)<\/span><br \/>\n<span style=\"font-weight: 400\">In order to load and store structured files.<\/span><\/p>\n<ul>\n<li><strong>Example of\u00a0PigStorage()<\/strong><\/li>\n<\/ul>\n<p>Here, PigStorage expects input.txt to contain tab-separated fields as well as newline-separated records. So, statements are equivalent.<br \/>\nA = LOAD &#8216;Employee&#8217; USING PigStorage(&#8216;\\t&#8217;) AS (name: chararray, age:int, gpa: float);<br \/>\nA = LOAD &#8216;Employee&#8217; AS (name: chararray, age:int, gpa: float);<br \/>\nAlso, here, PigStorage stores the contents of X into files along with fields that are delimited with an asterisk ( * ). And, the STORE statement specifies that the files will be located in a directory named output and that the files will be named part-nnnnn (for example, part-00000).<br \/>\nSTORE X INTO &#8216;output&#8217; USING PigStorage(&#8216;*&#8217;);<br \/>\nHere, PigStorage loads data with complex data type, a bag of map and double.<br \/>\na = load &#8216;1.txt&#8217; as (a0:{t:(m:map[int],d:double)});<br \/>\n{([foo#1,bar#2],34.0),([white#3,yellow#4],45.0)} : valid<br \/>\n{([foo#badint],baddouble)} : conversion fail for badint\/baddouble, get {([foo#],)}<br \/>\n{} : valid, empty bag<\/p>\n<p><strong>ii. TextLoader()<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>TextLoader() Syntax\u00a0<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">TextLoader()<\/span><br \/>\n<span style=\"font-weight: 400\">This Pig Function is used for loading unstructured data into Pig.<\/span><\/p>\n<ul>\n<li><strong>Example of\u00a0TextLoader()<\/strong><\/li>\n<\/ul>\n<p>Here, TextLoader is used with the LOAD function.<br \/>\nA = LOAD &#8216;data&#8217; USING TextLoader();<\/p>\n<p><strong>iii. BinStorage()<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>BinStorage() Syntax\u00a0<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">BinStorage()<br \/>\n<\/span><br \/>\n<span style=\"font-weight: 400\">By using machine-readable format, for loading and storing data into Pig.<\/span><\/p>\n<ul>\n<li><strong>Example of BinStorage()<\/strong><\/li>\n<\/ul>\n<p>Here BinStorage is used with the LOAD and STORE functions.<br \/>\nA = LOAD &#8216;data&#8217; USING BinStorage();<br \/>\nSTORE X into &#8216;output&#8217; USING BinStorage();<br \/>\nHere BinStorage is used to load multiple locations.<br \/>\nA = LOAD &#8216;input1.bin, input2.bin&#8217; USING BinStorage();<br \/>\nraw = load &#8216;sampledata&#8217; using BinStorage() as (col1,col2, col3);<br \/>\n&#8211;filter out null columns<br \/>\nA = filter raw by col1#&#8217;bcookie&#8217; is not null;<br \/>\nB = foreach A generate col1#&#8217;bcookie&#8217; as reqcolumn;<br \/>\ndescribe B;<br \/>\n&#8211;B: {regcolumn: bytearray}<br \/>\nX = limit B 5;<br \/>\ndump X;<br \/>\n(36co9b55onr8s)<br \/>\n(36co9b55onr8s)<br \/>\n(36hilul5oo1q1)<br \/>\n(36hilul5oo1q1)<br \/>\n(36l4cj15ooa8a)<br \/>\nB = foreach A generate (chararray)col1#&#8217;bcookie&#8217; as convertedcol;<br \/>\ndescribe B;<br \/>\n&#8211;B: {convertedcol: chararray}<br \/>\nX = limit B 5;<br \/>\ndump X;<br \/>\n()<br \/>\n()<br \/>\n()<br \/>\n()<br \/>\n()<\/p>\n<p><strong>iv. Handling Compression<\/strong><br \/>\n<span style=\"font-weight: 400\"> We can load and store compressed data in Pig Latin.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">c. Bag and Tuple Functions<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Here is the list of Bag and Tuple &#8211; Pig Built in functions. Such as:<\/span><\/p>\n<p><strong>i. TOBAG()<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>Syntax of TOBAG()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">TOBAG(expression [, expression &#8230;])<\/span><br \/>\n<span style=\"font-weight: 400\">This Pig Built in function is used in order to convert two or more expressions into a bag.<\/span><\/p>\n<ul>\n<li><strong>Example of\u00a0TOBAG()<\/strong><\/li>\n<\/ul>\n<p>Here, fields f1 and f3 are converted to tuples that are then placed in a bag.<br \/>\na = LOAD &#8216;Employee&#8217; AS (f1:chararray, f2:int, f3:float);<br \/>\nDUMP a;<br \/>\n(Johny,18,4.0)<br \/>\n(Mariya,19,3.8)<br \/>\n(Billy,20,3.9)<br \/>\n(joey,18,3.8)<br \/>\nb = FOREACH a GENERATE TOBAG(f1,f3);<br \/>\nDUMP b;<br \/>\n({(Johny),(4.0)})<br \/>\n({(Mariya),(3.8)})<br \/>\n({(Billy),(3.9)})<br \/>\n({(joey),(3.8)})<\/p>\n<p><strong>ii. TOP()<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>The syntax of Top()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">TOP(topN,column,relation)<\/span><br \/>\n<span style=\"font-weight: 400\">Forgetting the top N tuples of a relation.<\/span><\/p>\n<ul>\n<li><strong>Example of TOP()<\/strong><\/li>\n<\/ul>\n<p>Here the top 10 occurrences are returned.<br \/>\nDEFINE asc TOP(&#8216;ASC&#8217;); &#8212; ascending order<br \/>\nDEFINE desc TOP(&#8216;DESC&#8217;); &#8212; descending order<br \/>\nA = LOAD &#8216;data&#8217; as (first: chararray, second: chararray);<br \/>\nB = GROUP A BY (first, second);<br \/>\nC = FOREACH B generate FLATTEN(group), COUNT(A) as count;<br \/>\nD = GROUP C BY first; &#8212; again group by first<br \/>\ntopResults = FOREACH D {<br \/>\nresult = asc(10, 1, C); &#8212; and retain top 10 (in ascending order) occurrences of &#8216;second&#8217; in first<br \/>\nGENERATE FLATTEN(result);<br \/>\n}<br \/>\nbottomResults = FOREACH D {<br \/>\nresult = desc(10, 1, C); &#8212; and retain top 10 (in descending order) occurrences of &#8216;second&#8217; in first<br \/>\nGENERATE FLATTEN(result);<br \/>\n}<\/p>\n<p><strong>iii. TOTUPLE()<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>The Syntax of TOTUPLE()<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">TOTUPLE(expression [, expression &#8230;])<\/span><br \/>\n<span style=\"font-weight: 400\">In order to convert one or more expressions into a tuple.<\/span><\/p>\n<ul>\n<li><strong>Example of TOTUPLE()<\/strong><\/li>\n<\/ul>\n<p>Here, fields f1, f2 and f3 are converted to a tuple.<br \/>\na = LOAD &#8216;Employee&#8217; AS (f1:chararray, f2:int, f3:float);<br \/>\nDUMP a;<br \/>\n(Johny,18,4.0)<br \/>\n(Mariya,19,3.8)<br \/>\n(Billy,20,3.9)<br \/>\n(joey,18,3.8)<br \/>\nb = FOREACH a GENERATE TOTUPLE(f1,f2,f3);<br \/>\nDUMP b;<br \/>\n((Johny,18,4.0))<br \/>\n((Mariya,19,3.8))<br \/>\n((Billy,20,3.9))<br \/>\n((joey,18,3.8))<\/p>\n<p><strong>iv. TOMAP()<\/strong><br \/>\n<span style=\"font-weight: 400\">Forgetting to convert the key-value pairs into a Map.<\/span><\/p>\n<ul>\n<li><strong>Example of TOMAP()<\/strong><\/li>\n<\/ul>\n<p>Here, Employee names (type chararray) and Employee GPAs (type float) are used to create three maps.<br \/>\nA = load &#8216;Employees&#8217; as (name:chararray, age:int, gpa:float);<br \/>\nB = foreach A generate TOMAP(name, gpa);<br \/>\nstore B into &#8216;results&#8217;;<br \/>\nInput (Employees)<br \/>\njoey smith 20 3.5<br \/>\namy chen 22 3.2<br \/>\nleo allen 18 2.1<br \/>\nOutput (results)<br \/>\n[joey smith#3.5]<br \/>\n[amy chen#3.2]<br \/>\n[leo allen#2.1]<\/p>\n<h3><span style=\"font-weight: 400\">d. String Functions<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Here, is the list of String &#8211; Pig Built in functions. Such as:<\/span><\/p>\n<p><strong>i. ENDSWITH(string, testAgainst)<\/strong><br \/>\n<span style=\"font-weight: 400\">For verifying whether a given string ends with a particular substring.<\/span><\/p>\n<p><strong>ii. STARTSWITH(string, substring)<\/strong><br \/>\n<span style=\"font-weight: 400\">This Pig Function verifies whether the first string starts with the second, after accepting two string parameters.<\/span><\/p>\n<p><strong>iii. SUBSTRING(string, startIndex, stopIndex)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">SUBSTRING(string, startIndex, stopIndex)<\/span><br \/>\n<span style=\"font-weight: 400\">It returns a substring from a given string.<\/span><\/p>\n<p><strong>iv. EqualsIgnoreCase(string1, string2)<\/strong><br \/>\n<span style=\"font-weight: 400\">In order to compare two strings ignoring the case.<\/span><\/p>\n<p><strong>v. INDEXOF(string, \u2018character\u2019, startIndex)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">INDEXOF(string, &#8216;character&#8217;, startIndex)<\/span><br \/>\n<span style=\"font-weight: 400\">It returns the first occurrence of a character in a string, searching forward from a start index.<\/span><\/p>\n<p><strong>vi. LAST_INDEX_OF(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">LAST_INDEX_OF(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">To return the index of the last occurrence of a character in a string, searching backward from a start index.<\/span><\/p>\n<p><strong>vi. LCFIRST(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">LCFIRST(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">This Pig Function is used for conversion of the first character in a string to lowercase.<\/span><\/p>\n<p><strong>vii. UCFIRST(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">UCFIRST(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">It returns a string with the first character converted to uppercase.<\/span><\/p>\n<p><strong>viii. UPPER(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">UPPER(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">In order to get a string converted to upper case.<\/span><\/p>\n<p><strong>ix. LOWER(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">LOWER(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">This function in Pig converts all characters in a string to lower case.<\/span><\/p>\n<p><strong>x. REPLACE(string, \u2018oldChar\u2019, \u2018newChar\u2019);<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">REPLACE(string, &#8216;oldChar&#8217;, &#8216;newChar&#8217;);<\/span><br \/>\n<span style=\"font-weight: 400\">For replacing existing characters in a string with new characters.<\/span><\/p>\n<p><strong>xi. STRSPLIT(string, regex, limit)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">STRSPLIT(string, regex, limit)<\/span><br \/>\n<span style=\"font-weight: 400\">In order to split a string around matches of a given regular expression.<\/span><\/p>\n<p><strong>xii. STRSPLITTOBAG(string, regex, limit)<\/strong><br \/>\n<span style=\"font-weight: 400\">It splits the string by given delimiter and returns the result in a bag.<\/span><\/p>\n<p><strong>xiii. TRIM(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">TRIM(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">This Pig Built in Function is used to return a copy of a string with leading and trailing whitespaces removed.<\/span><\/p>\n<p><strong>xiv. LTRIM(expression)<\/strong><br \/>\n<span style=\"font-weight: 400\">It returns a copy of a string with leading whitespaces removed.<\/span><\/p>\n<p><strong>xv. RTRIM(expression)<\/strong><br \/>\n<span style=\"font-weight: 400\">For returning a copy of a string with trailing whitespaces removed.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">e. Date and Time Functions<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Here is the list of Date and Time &#8211; Pig Built in functions. <\/span><\/p>\n<p><strong>i. ToDate(milliseconds)<\/strong><br \/>\n<span style=\"font-weight: 400\">According to the given parameters, it returns a date-time object. There are more alternative for this functions. Such as ToDate(iosstring), ToDate(userstring, format), ToDate(userstring, format, timezone)<\/span><\/p>\n<p><strong>ii. CurrentTime()<\/strong><br \/>\n<span style=\"font-weight: 400\">It returns the date-time object of the current time.<\/span><\/p>\n<p><strong>iii. GetDay(datetime)<\/strong><br \/>\n<span style=\"font-weight: 400\">To get the day of a month as a return from the date-time object, we use it.<\/span><\/p>\n<p><strong>iv. GetHour(datetime)<\/strong><br \/>\n<span style=\"font-weight: 400\"> GetHour returns the hour of a day from the date-time object.<\/span><\/p>\n<p><strong>v. GetMilliSecond(datetime)<\/strong><br \/>\n<span style=\"font-weight: 400\">It returns the millisecond of a second from the date-time object.<\/span><\/p>\n<p><strong>vi. GetMinute(datetime)<\/strong><br \/>\n<span style=\"font-weight: 400\">To get the minute of an hour in return from the date-time object, we use it.<\/span><\/p>\n<p><strong>vii. GetMonth(datetime)<\/strong><br \/>\n<span style=\"font-weight: 400\">GetMonth returns the month of a year from the date-time object.<\/span><\/p>\n<p><strong>viii. GetSecond(datetime)<\/strong><br \/>\n<span style=\"font-weight: 400\">It returns the second of a minute from the date-time object.<\/span><\/p>\n<p><strong>ix. GetWeek(datetime)<\/strong><br \/>\n<span style=\"font-weight: 400\">To get the week of a year as a return from the date-time object, we use it.<\/span><\/p>\n<p><strong>x. GetWeekYear(datetime)<\/strong><br \/>\n<span style=\"font-weight: 400\">GetWeekYear returns the week year from the date-time object.<\/span><\/p>\n<p><strong>xi. GetYear(datetime)<\/strong><br \/>\n<span style=\"font-weight: 400\">It returns the year from the date-time object.<\/span><\/p>\n<p><strong>xii. AddDuration(datetime, duration)<\/strong><br \/>\n<span style=\"font-weight: 400\">To get the result of a date-time object as a result along with the duration object, we use it.<\/span><\/p>\n<p><strong>xiii. SubtractDuration(datetime, duration)<\/strong><br \/>\n<span style=\"font-weight: 400\">SubtractDuration<\/span><span style=\"font-weight: 400\">\u00a0subtracts the duration object from the Date-Time object and returns the result.<\/span><\/p>\n<p><strong>xiv. DaysBetween(datetime1, datetime2)<\/strong><br \/>\n<span style=\"font-weight: 400\">DaysBetween r<\/span><span style=\"font-weight: 400\">eturns the number of days between the two date-time objects.<\/span><\/p>\n<p><strong>xv. HoursBetween(datetime1, datetime2)<\/strong><br \/>\n<span style=\"font-weight: 400\">It returns the number of hours between two date-time objects.<\/span><\/p>\n<p><strong>xvi. MilliSecondsBetween(datetime1, datetime2)<\/strong><br \/>\n<span style=\"font-weight: 400\">To get the number of milliseconds as result between two date-time objects, we use it.<\/span><\/p>\n<p><strong>xvii. MinutesBetween(datetime1, datetime2)<\/strong><br \/>\n<span style=\"font-weight: 400\">MinutesBetween returns the number of minutes between two date-time objects.<\/span><\/p>\n<p><strong>xviii. MonthsBetween(datetime1, datetime2)<\/strong><br \/>\n<span style=\"font-weight: 400\">To get the number of months as a return between two date-time objects, we use it.<\/span><\/p>\n<p><strong>xix. SecondsBetween(datetime1, datetime2)<\/strong><br \/>\n<span style=\"font-weight: 400\">It returns the number of seconds between two date-time objects.<\/span><\/p>\n<p><strong>xx. WeeksBetween(datetime1, datetime2)<\/strong><br \/>\n<span style=\"font-weight: 400\">WeeksBetween returns the number of weeks between two date-time objects.<\/span><\/p>\n<p><strong>xxi. YearsBetween(datetime1, datetime2)<\/strong><br \/>\n<span style=\"font-weight: 400\">To get the number of years as a return between two date-time objects, we use it.<\/span><br \/>\nAny doubt yet in Pig Built in functions? Please Comment.<\/p>\n<h3><span style=\"font-weight: 400\">f. Math Functions<\/span><\/h3>\n<p><span style=\"font-weight: 400\">We have the following Math &#8211; Pig Built in functions\u2212<\/span><\/p>\n<p><strong>i. ABS(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">ABS(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">In order to get the absolute value of an expression.<\/span><\/p>\n<p><strong>ii. ACOS(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">ACOS(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">It gives the arc cosine of an expression.<\/span><\/p>\n<p><strong>iii. ASIN(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">ASIN(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">ASIN gives<\/span><span style=\"font-weight: 400\"> the arc sine of an expression.<\/span><\/p>\n<p><strong>iv. ATAN(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">ATAN(expression<\/span><br \/>\n<span style=\"font-weight: 400\">To get the arc tangent of an expression, we use it.<\/span><\/p>\n<p><strong>v. CBRT(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">CBRT(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">It gives the cube root of an expression.<\/span><\/p>\n<p><strong>vi. CEIL(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">CEIL(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">CEIL<\/span><span style=\"font-weight: 400\"> is used to get the value of an expression rounded up to the nearest integer.<\/span><\/p>\n<p><strong>vii. COS(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">COS(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">In order to get the trigonometric cosine of an expression.<\/span><\/p>\n<p><strong>viii. COSH(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">COSH(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">COSH gives<\/span><span style=\"font-weight: 400\"> the hyperbolic cosine of an expression.<\/span><\/p>\n<p><strong>ix. EXP(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">EXP(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">To get the Euler\u2019s number e raised to the power of x.<\/span><\/p>\n<p><strong>x. FLOOR(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">FLOOR(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">In order to get the value of an expression rounded down to the nearest integer.<\/span><\/p>\n<p><strong>xi. LOG(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">LOG(expression)<\/span><br \/>\nLOG gives the<span style=\"font-weight: 400\"> natural logarithm (base e) of an expression.<\/span><\/p>\n<p><strong>xii. LOG10(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">LOG10(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">It gives the base 10 logarithms of an expression.<\/span><\/p>\n<p><strong>xiii. RANDOM( )<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">RANDOM( )<\/span><br \/>\n<span style=\"font-weight: 400\">In order to get a pseudo random number (type double) greater than or equal to 0.0 and less than 1.0.<\/span><\/p>\n<p><strong>xiv. ROUND(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">ROUND(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">ROUND gives the value of an expression rounded to an integer (if the result type is float) or rounded to a long (if the result type is double).<\/span><\/p>\n<p><strong>xv. SIN(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">SIN(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">In order to get the sine of an expression.<\/span><\/p>\n<p><strong>xvi. SINH(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">SINH(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">It gives the hyperbolic sine of an expression.<\/span><\/p>\n<p><strong>xvii. SQRT(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">SQRT(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">SQRT<\/span><span style=\"font-weight: 400\"> gives the positive square root of an expression.<\/span><\/p>\n<p><strong>xviii. TAN(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">TAN(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">In order to get the trigonometric tangent of an angle.<\/span><\/p>\n<p><strong>xix. TANH(expression)<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Syntax<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">TANH(expression)<\/span><br \/>\n<span style=\"font-weight: 400\">It gives the hyperbolic tangent of an expression.<\/span><br \/>\nSo, this was all about Pig Built in Functions. Hope you like our explanation.<\/p>\n<h2><span style=\"font-weight: 400\">Conclusion: Apache Pig Built in Functions<\/span><\/h2>\n<p><span style=\"font-weight: 400\">As a result, we have seen all the Apache Pig Built in Functions in detail. Moreover, we discussed string functions, math functions, load &amp; store, bag &amp; tuple, and eval functions. Still, if any doubt occurs, feel free to ask in the comments.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article &#8220;Apache Pig Built in Functions&#8221;, we will discuss all the Apache Pig Built-in Functions in detail. It includes eval, load\/store, math, bag and tuple functions and many more. Also, we will&#46;&#46;&#46;<\/p>\n","protected":false},"author":7,"featured_media":25781,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[4219,8348,8595,9503,13901],"class_list":["post-13958","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pig","tag-eval-functions","tag-load-and-store-functions","tag-math-functions","tag-pig-functions","tag-string-functions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Apache Pig Built in Functions Cheat Sheet - DataFlair<\/title>\n<meta name=\"description\" content=\"Pig Built in Functions tutorial - what is Pig functions, Apache Pig tutorial, Eval Functions, Load &amp; Store Functions,Bag &amp; Tuple Functions, String Functions\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apache Pig Built in Functions Cheat Sheet - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Pig Built in Functions tutorial - what is Pig functions, Apache Pig tutorial, Eval Functions, Load &amp; Store Functions,Bag &amp; Tuple Functions, String Functions\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-19T12:24:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Pig-Built-in-Functions-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apache Pig Built in Functions Cheat Sheet - DataFlair","description":"Pig Built in Functions tutorial - what is Pig functions, Apache Pig tutorial, Eval Functions, Load & Store Functions,Bag & Tuple Functions, String Functions","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/","og_locale":"en_US","og_type":"article","og_title":"Apache Pig Built in Functions Cheat Sheet - DataFlair","og_description":"Pig Built in Functions tutorial - what is Pig functions, Apache Pig tutorial, Eval Functions, Load & Store Functions,Bag & Tuple Functions, String Functions","og_url":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-04-19T12:24:52+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Pig-Built-in-Functions-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd"},"headline":"Apache Pig Built in Functions Cheat Sheet","datePublished":"2018-04-19T12:24:52+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/"},"wordCount":3293,"commentCount":1,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Pig-Built-in-Functions-01.jpg","keywords":["Eval Functions","Load and store Functions","Math functions","Pig Functions","String Functions"],"articleSection":["Pig Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/","url":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/","name":"Apache Pig Built in Functions Cheat Sheet - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Pig-Built-in-Functions-01.jpg","datePublished":"2018-04-19T12:24:52+00:00","description":"Pig Built in Functions tutorial - what is Pig functions, Apache Pig tutorial, Eval Functions, Load & Store Functions,Bag & Tuple Functions, String Functions","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Pig-Built-in-Functions-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Pig-Built-in-Functions-01.jpg","width":1200,"height":628,"caption":"Apache Pig Built in Functions Cheat Sheet"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/apache-pig-built-in-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Pig Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/pig\/"},{"@type":"ListItem","position":3,"name":"Apache Pig Built in Functions Cheat Sheet"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team specializes in creating clear, actionable content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Backed by industry expertise, we make learning easy and career-oriented for beginners and pros alike.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam3\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/13958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=13958"}],"version-history":[{"count":0,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/13958\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/25781"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=13958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=13958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=13958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}