Implementation of hiverc file loading

Source: Internet
Author: User


All hive users know that You can specify the-I parameter or configure. hiverc to set some commands initially executed during hive startup. For example, you can write the UDF definition to the. hiverc file. The process of loading. hiverc is defined in the clidriver class.

Specific method call sequence:

Main ---> RUN ---> executedriver -----> processinitfiles ----> processfile ----> processreader ----> processline ---> processcmd, there are more specific implementations in processcmd.

1) In executedriver, process the call part of the initialization file:

// Execute-I init files (always in silent mode) cli. processinitfiles (SS); // load the initial file if (ss. execstring! = NULL) {int processing processstatus = CLI. processline (ss. execstring); // ss.exe cstring = CommandLine in case of-e. getoptionvalue ('E'); return response processstatus;} Try {If (ss. filename! = NULL) {return CLI. processfile (ss. filename); // The case of-F ss. filename = CommandLine. getoptionvalue ('F') ;}} catch (filenotfoundexception e) {system. err. println ("cocould not open input file for reading. ("+ E. getmessage () + ")"); return 3 ;}


2) processreader defines the comments in the. hiverc file (starts)

 public int processReader(BufferedReader r) throws IOException {    String line;    StringBuilder qsb = new StringBuilder();    while ((line = r.readLine()) != null) {      // Skipping through comments      if (! line.startsWith( "--")) {        qsb.append(line + "\n");      }    }    return (processLine(qsb.toString()));  }

3) processinitfiles defines the loading sequence:

-I specified or

$HIVE_HOME/bin/.hiverc--->$HIVE_CONF_DIR/.hiverc--->${user.home}/.hiverc

Code implementation:

Public void processinitfiles (clisessionstate SS) throws ioexception {Boolean savesilent = ss. getissilent (); SS. setissilent (true); For (string initfile: Ss. initfiles) {// ss. initfiles indicates the file path int rc = processfile (initfile) passed in by the hive-I parameter; If (RC! = 0) {system. exit (RC) ;}} if (ss. initfiles. size () = 0) {// If the-I parameter is not specified, load if (system. getenv ("hive_home ")! = NULL) {// $ hive_home/bin /. hiverc string hivercdefault = system. getenv ("hive_home") + file. separator + "bin" + file. separator + hivercfile; If (new file (hivercdefault ). exists () {int rc = processfile (hivercdefault); If (RC! = 0) {system. exit (RC);} console. printerror ("putting the global hiverc in" + "$ hive_home/bin /. hiverc is deprecated. please "+" use $ hive_conf_dir /. hiverc instead. ") ;}} if (system. getenv ("hive_conf_dir ")! = NULL) {// $ hive_conf_dir /. hiverc string hivercdefault = system. getenv ("hive_conf_dir") + file. separator + hivercfile; If (new file (hivercdefault ). exists () {int rc = processfile (hivercdefault); If (RC! = 0) {system. Exit (RC) ;}} if (system. getproperty ("user. Home ")! = NULL) {// $ {user. home }/. hiverc string hivercuser = system. getproperty ("user. home ") + file. separator + hivercfile; If (new file (hivercuser ). exists () {int rc = processfile (hivercuser); If (RC! = 0) {system. Exit (RC) ;}}} ss. setissilent (savesilent );}

This article from the "Food light blog" blog, please be sure to keep this source http://caiguangguang.blog.51cto.com/1652935/1542269

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.