Friday, January 26, 2018

Permanent User Defined Function (UDF) in Hive



  • We can create a temporary function in hive and use the function in our query, however this is valid till the current session is alive. 
  • If we want the function to be permanent we need to create a permanent function.


Steps involved to create a permanent function in Hive



1) Store the JAR file in hdfs location instead of local. If we have already created local function we might have to use a new function name enter image description here
2) Create permanent function in hive shell
 hive> CREATE FUNCTION MASK AS 'hiveudf.PI' 
  using JAR 'hdfs://localhost:8020/user/cloudera/Mask.jar'; 
 in the hive shell 
enter image description hereNote: When the function is created, it moves the JAR file from HDFS to local system

2 comments:

  1. Hi Prathap,

    Using same jar and same class not able to create a new function.

    For Example,
    CREATE FUNCTION MASK2 AS 'hiveudf.PI'
    using JAR 'hdfs://localhost:8020/user/cloudera/Mask.jar';

    ReplyDelete
  2. Can you please let me know what is the error message?

    ReplyDelete