无法连接到hive java

uwopmtnx  于 2021-06-01  发布在  Hadoop
关注(0)|答案(1)|浏览(393)

我想用 org.apache.hadoop.hive 使用metastore。
hive(1.1)和hadoop(2.6版)安装在linux服务器上。我的电脑有windows操作系统。在这里,我试图创建Hive形态。

import org.apache.hadoop.hive.conf.HiveConf;

    public class Main {
        public static void main(String[] args){

            HiveConf hiveConf = new HiveConf();
            hiveConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 3);
            hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://server:port");

            HiveMetastore hiveMetaStoreConnector = new HiveMetastore(hiveConf);
            if(hiveMetaStoreConnector != null){
                System.out.print(hiveMetaStoreConnector.getAllPartitionInfo("tablename"));
            }
        }
    }

但是我遇到了一个问题 HiveConf hiveConf = new HiveConf(); 严重:在hadoop二进制文件路径java.io中找不到winutils二进制文件。ioexception:在hadoop二进制文件中找不到可执行文件null\bin\winutils.exe。在
org.apache.hadoop.util.shell.getqualifiedbinpath(shell。java:379)在
org.apache.hadoop.util.shell.getwinutilspath(shell。java:394)在org.apache.hadoop.util.shell。java:387)在
org.apache.hadoop.hive.conf.hiveconf$confvars.findhadoopbinary(hiveconf。java:2065)
在org.apache.hadoop.hive.conf.hiveconf$confvars。java:332)
在org.apache.hadoop.hive.conf.hiveconf.(hiveconf。java:95)在main.main(main。java:11)在sun.reflect.nativemethodaccessorimpl.invoke0(本机方法)
在sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl。java:62)
在sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl。java:43)
在java.lang.reflect.method.invoke(方法。java:497)在com.intellij.rt.execution.application.appmain.main(appmain。java:144)
线程“main”java.lang.ExceptionInInitializeError中出现异常
在org.apache.hadoop.hive.conf.hiveconf.(hiveconf。java:95)在main.main(main。java:11)在sun.reflect.nativemethodaccessorimpl.invoke0(本机方法)
在sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl。java:62)
在sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl。java:43)
在java.lang.reflect.method.invoke(方法。java:497)在com.intellij.rt.execution.application.appmain.main(appmain。java:144)原因:java.lang.runtimeexception:无法在类null中加载垫片
在org.apache.hadoop.hive.shimmes.shimloader.loadshimmes(shimloader。java:86)
在org.apache.hadoop.hive.shimmers.shimloader.gethadoopshimmers(shimloader。java:62)在org.apache.hadoop.hive.conf.hiveconf$confvars。java:335) ... 7更多原因:java.lang.class.forname(类)中的java.lang.nullpointerexception位于java.lang.class.forname0(本机方法)。java:264)在org.apache.hadoop.hive.shimmes.shimloader.loadshimmes(shimloader。java:83) ... 9个以上
我应该在windows(winutils.exe)上安装hadoop客户端吗?或者我应该包括更多的图书馆?
另外,我只需要设置conf hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://server:port") ?
还是和设置smth有关?
如有任何建议,我们将不胜感激。

sf6xfgos

sf6xfgos1#

我不知道你想实现什么,但是你的代码不能在windows机器上运行,因为windows机器缺少hadoop库。我认为在裸机上进行真正的设置是不可能的。您需要某种vmware软件才能使窗口机作为配置单元客户端工作。
如果您试图通过程序连接到配置单元,那么应该尝试使用配置单元api,它公开了jdbc连接到配置单元的方式。
jdbc公司
hiveserver2有一个jdbc驱动程序。它支持对hiveserver2的嵌入式和远程访问。建议在生产环境中使用远程hiveserver2模式,因为它更安全,并且不需要为用户授予直接的hdfs/metastore访问权限。
hiveserver2 url是具有以下语法的字符串:

jdbc:hive2://<host1>:<port1>,<host2>:<port2>/dbName;initFile=<file>;sess_var_list?hive_conf_list#hive_var_list

哪里 <host1>:<port1>,<host2>:<port2> 是要连接到的服务器示例或以逗号分隔的服务器示例列表(如果启用了动态服务发现)。如果为空,将使用嵌入式服务器。 dbName 初始数据库的名称。 <file> 初始化脚本文件的路径(配置单元2.2.0及更高版本)。这个脚本文件是用sql语句编写的,连接后会自动执行。此选项可以为空。 sess_var_list 是以分号分隔的 key=value 会话变量对(例如。, user=foo;password=bar ). hive_conf_list 是以分号分隔的 key=value 此会话的配置单元配置变量对 hive_var_list 是以分号分隔的 key=value 此会话的配置单元变量对。

相关问题