Add the default database attribute for hive permanent function

Source: Internet
Author: User

Objective

Hive 0.13 starts with the addition of the permanent function, allowing the user-defined function to not add the create temporary function to the. hiverc file. Increased hive startup time (no pre-execution of temporary function commands required), and the UDF jar package can be placed on HDFs for ease of administration without the need to push UDFs to the hive client side, but the permanent function has a problem You need to add the database name before the function name, which is [database]. [function]; If you do not fill in the database, this will take the current database auto-complete function.

Reference to the traditional relational database, there is a default schema, in the search function, the first search default schema, such as Iopostgresql Pg_catalog. So you want to add the default database to hive.

Design

Add two parameters

hive.function.default.function.enabled defaults to False, which means that this attribute is disabled, and set to True to start the attribute, and to search for a function with a preference for the default database.

Hive.function.default.function default is: default; When Hive.function.default.function.enabled=true is in effect;

Realize

To add this function, you need to know when the permanent function will use the current database, complete function.

Functionregistry.java

Private static functioninfo getfunctioninfofrommetastore (String functionname)  {     FunctionInfo ret = null;    try {       String dbName;      String fName;       if  (Functionutils.isqualifiedfunctionname (functionname))  {         string[] parts = functionutils.splitqualifiedfunctionname (FunctionName) ;        dbname = parts[0];         fName = parts[1];      } else {         // otherwise, qualify using current db         dbname = sessionstate.get (). GetCurrentDatabase (). toLowerCase ();         fname = functionname;      }       // try looking up function in the metastore       hiveconf conf = sessionstate.get (). getConf ();       function func = hive.get (conf). GetFunction (Dbname, fname);       if  (func != null)  {         // found udf in metastore - now add it to the  function registry        // at this point  we should add any relevant jars that would be needed  for the udf.        try {           Functiontask.addfunctionresources (Func.getresourceuris ());         }  catch  (exception e)  {           Log.error ("unable to load resources for "  + dbName +  ".")  + fName +  ":"  + e.getmessage (),  e);           return null;        }         class<?> udfclass = class.forname (Func.getClassName (),  true, utilities.getsessionspecifiedclassloader ());         if  (Registertemporaryfunction (functionname, udfclass))  {           ret = mfunctions.get (functionname);         } else {   &Nbsp;      log.error (Func.getclassname ()  +  " is not a  valid udf class and was not registered. ");         }      }     } catch  (hiveexception e)  {      if  (! ( (E.getcause ()  != null)  &amp;&amp;  (E.getcause ()  instanceof metaexception )  &amp;&amp;          (E.getcause (). Getcause ()   != null)  &amp;&amp;  (E.getcause (). Getcause ()  instanceof nosuchobjectexception ))   {         log.info ("Unable to lookup  UDF in metastore:  " + e);      }     } catch  (classnotfoundexception e) &NBSP;{&Nbsp;     // lookup of udf class failed       log.error ("unable to load udf class: "  + e);     }    return ret;  }

 

  public static string getnormalizedfunctionname (STRING&NBSP;FN)  {     // does the same thing as getfunctioninfo, except for  getting the function info.    fn = fn.tolowercase ();     return  (Functionutils.isqualifiedfunctionname (FN)  | |  mfunctions.get (FN)  != null)  ? fn        :  functionutils.qualifyfunctionname (             fn, sessionstate.get (). Getcurrentdatabase (). toLowerCase ());  }  private  Static <t extends commonfunctioninfo> t getfunctioninfo (       map<string, t> mfunctions, string functionname)  {     functionname = functionname.tolowercase ();    t functioninfo = null;    if  ( Functionutils.isqualifiedfunctionname (functionname))  {      functioninfo  = getqualifiedfunctioninfo (Mfunctions, functionname);    } else  {      // first try without qualifiers - would  resolve builtin/temp functions.      // otherwise try  qualifying with current db name.      functioninfo  =  mfunctions.get (functionname);      if  (functionInfo  == null &amp;&amp; ! Functionutils.isqualifiedfunctionname (functionname))  {         String qualifiedname = functionutils.qualifyfunctionname (FUNCTIONNAME,&NBSP;&NBSP;&NBSP;&NBsp;        sessionstate.get (). Getcurrentdatabase (). ToLowerCase ());         functioninfo = getqualifiedfunctioninfo (MFunctions,  qualifiedname);      }    }     return functioninfo;  }

Functionutils.java

public static string[] Getqualifiedfunctionnameparts (String name) throws Hiveexception {if (Isqualifiedfunctionname (NA    Me) {return splitqualifiedfunctionname (name);    } String DbName = Sessionstate.get (). Getcurrentdatabase ();  return new string[] {dbName, name}; }

Add a hive.function.default.function.enabled to the code to determine if true, and if true, the default dbname is adjusted to hive.function.default.function.

Add the default database attribute for hive permanent function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.