Javatpoint Logo
Javatpoint Logo

Pig UDF (User Defined Functions)

To specify custom processing, Pig provides support for user-defined functions (UDFs). Thus, Pig allows us to create our own functions. Currently, Pig UDFs can be implemented using the following programming languages: -

  • Java
  • Python
  • Jython
  • JavaScript
  • Ruby
  • Groovy

Among all the languages, Pig provides the most extensive support for Java functions. However, limited support is provided to languages like Python, Jython, JavaScript, Ruby, and Groovy.

Example of Pig UDF

In Pig,

  • All UDFs must extend "org.apache.pig.EvalFunc"
  • All functions must override the "exec" method.

Let's see an example of a simple EVAL Function to convert the provided string to uppercase.

  • Create the jar file and export it into the specific directory. For that ,right click on project - Export - Java - JAR file - Next.
Apache Pig UDF
  • Now, provide a specific name to the jar file and save it in a local system directory.
Apache Pig UDF
  • Create a text file in your local machine and insert the list of tuples.
Apache Pig UDF
  • Upload the text files on HDFS in the specific directory.
  • Create a pig file in your local machine and write the script.
Apache Pig UDF
  • Now, run the script in the terminal to get the output.
Apache Pig UDF

Here, we got the desired output.

Next TopicLOAD Operator

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA