If you have a recent version of Hive (0.13+), you could try registering your UDF as a "permanent" UDF which was added in HIVE-6047:
1) Copy your JAR somewhere on HDFS, say hdfs:///home/nirmal/udf/hiveUDF-1.0-SNAPSHOT.jar. 2) In Hive, run CREATE FUNCTION zeroifnull AS 'com.test.udf.ZeroIfNullUDF' USING JAR 'hdfs:///home/nirmal/udf/hiveUDF-1.0-SNAPSHOT.jar'; The function definition should be saved in the metastore and Hive should remember to pull the JAR from the location you specified in the CREATE FUNCTION call. Jason On Aug 27, 2014, at 8:19 PM, Nirmal Kumar <[email protected]> wrote: > Hi All, > > What is the best way to add custom UDF jar in HiveServer2. > > Currently I am adding it through Java JDBC code : > > Statement stmt = null; > ResultSet res = null; > Connection con = getHiveConnection(host, port, db); > try { > stmt = con.createStatement(); > > String[] args = new String[2]; > args[0] = "add jar /home/nirmal/udf/hiveUDF-1.0-SNAPSHOT.jar"; > args[1] = "CREATE TEMPORARY FUNCTION zeroifnull AS > 'com.test.udf.ZeroIfNullUDF'"; > > for (String queryUDF : args) { > stmt.execute(queryUDF); > } > } > > Is there any other better way ? > > Thanks, > -Nirmal > > > > > > > > > NOTE: This message may contain information that is confidential, proprietary, > privileged or otherwise protected by law. The message is intended solely for > the named addressee. If received in error, please destroy and notify the > sender. Any use of this email is prohibited when received in error. Impetus > does not represent, warrant and/or guarantee, that the integrity of this > communication has been maintained nor that the communication is free of > errors, virus, interception or interference. -- CONFIDENTIALITY NOTICE NOTICE: This message is intended for the use of the individual or entity to which it is addressed and may contain information that is confidential, privileged and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are hereby notified that any printing, copying, dissemination, distribution, disclosure or forwarding of this communication is strictly prohibited. If you have received this communication in error, please contact the sender immediately and delete it from your system. Thank You.
