在将hive client切换到beeline梳理hive上的udf的时候,发现工程中好多工作的代码都是间接注册办法,没有显示的add jar,起初在hive的conf目录下发现了.hiverc文件中有两行add jar的命令,霎时好奇怎么加载的这个文件,一开始认为是在bin/hive脚本中加载的,起初发现不是,是在client启动的时候CliDriver中记录的,加载的代码如下:

public void processInitFiles(CliSessionState ss) throws IOException {    boolean saveSilent = ss.getIsSilent();    ss.setIsSilent(true);    for (String initFile : ss.initFiles) {      int rc = processFile(initFile);      if (rc != 0) {        System.exit(rc);      }    }    if (ss.initFiles.size() == 0) {      if (System.getenv("HIVE_HOME") != null) {        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) {        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) {        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);  }