【Hive】new HiveConf()时加载的配置浅析

简单看下源码:
org.apache.hadoop.hive.conf.HiveConf

HiveConf中有静态代码块,内容就是调用findConfigFile方法,尝试读取hive-default.xmlhive-site.xmlhivemetastore-site.xmlhiveserver2-site.xml。四个文件的内容。

java 复制代码
    static {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader == null) {
            classLoader = HiveConf.class.getClassLoader();
        }

        hiveDefaultURL = classLoader.getResource("hive-default.xml");
        hiveSiteURL = findConfigFile(classLoader, "hive-site.xml", true);
        hivemetastoreSiteUrl = findConfigFile(classLoader, "hivemetastore-site.xml", false);
        hiveServer2SiteUrl = findConfigFile(classLoader, "hiveserver2-site.xml", false);
省略... 
}

findConfigFile方法就更简单了
System.getenv("...")就是查找系统环境变量HIVE_CONF_DIRHIVE_HOME,显然HIVE_CONF_DIRHIVE_HOME优先级更高。然后组装成路径,并读取文件内容。

java 复制代码
    private static URL findConfigFile(ClassLoader classLoader, String name, boolean doLog) {
        URL result = classLoader.getResource(name);
        if (result == null) {
            String confPath = System.getenv("HIVE_CONF_DIR");
            result = checkConfigFile(new File(confPath, name));
            if (result == null) {
                String homePath = System.getenv("HIVE_HOME");
                String nameInConf = "conf" + File.separator + name;
                result = checkConfigFile(new File(homePath, nameInConf));
                省略...

总结:

使用HiveConf特别简单额,设置好环境变量HIVE_CONF_DIRHIVE_HOME后就可以在代码中用了。
注意:是环境变量,不是java系统变量,即System.setProperty()和-D是不行的,这两项都是设置java变量,不是操作系统变量

相关推荐
是阿威啊10 小时前
【第二站】本地hadoop集群配置yarn模式
大数据·linux·hadoop·yarn
好大哥呀15 小时前
Hadoop yarn
大数据·hadoop·分布式
红队it16 小时前
【数据分析】基于Spark链家网租房数据分析可视化大屏(完整系统源码+数据库+开发笔记+详细部署教程+虚拟机分布式启动教程)✅
java·数据库·hadoop·分布式·python·数据分析·spark
本旺2 天前
【数据开发离谱场景记录】Hive + ES 复杂查询场景处理
hive·hadoop·elasticsearch
莫叫石榴姐2 天前
Doris为2.1版本,但json_each不可以用解决方法
数据仓库·json
无泪无花月隐星沉2 天前
uos server 1070e部署Hadoop
大数据·运维·服务器·hadoop·分布式·uos·国产化os
悟能不能悟2 天前
springboot全局异常
大数据·hive·spring boot
是阿威啊2 天前
【第一站】本地虚拟机部署Hadoop分布式集群
大数据·linux·hadoop·分布式
lightningyang2 天前
Hadoop 分布式集群配置(OpenEuler 1主2)
hadoop·openeuler·天枢一体化虚拟仿真靶场平台
是阿威啊3 天前
【第六站】测试本地项目连接虚拟机上的大数据集群
大数据·linux·hive·hadoop·spark·yarn