gpt4 book ai didi

hadoop - Hive ql Driver如何指定默认以外的数据库名称

转载 作者:可可西里 更新时间:2023-11-01 16:49:02 38 4
gpt4 key购买 nike

我正在编写一个示例程序,使用 org.apache.hadoop.hive.ql.Driver 类连接到 Hive Metastore。示例片段如下

String userName = "test";
HiveConf conf = new HiveConf(SessionState.class);
conf.set("fs.default.name", "hdfs://" + hadoopMasterHost + ":8020");
conf.set("hive.metastore.local","false");
conf.set("hive.metastore.warehouse.dir","/user/hive/warehouse");
conf.set("hive.metastore.uris","thrift://" + hadoopMasterHost + ":9083");
conf.set("hadoop.bin.path", "/usr/hdp/2.2.0.0-2041/hadoop/bin");
conf.set("yarn.nodemanager.hostname", hadoopMasterHost);
conf.set("yarn.resourcemanager.hostname", hadoopMasterHost);

ss = new MyCliSessionState(conf);
ss.out = new PrintStream(System.out, true, "UTF-8");
ss.err = new PrintStream(System.err, true, "UTF-8");

SessionState.start(ss);

driver = new Driver(conf);
query = "show tables";

if (userName == null || userName.isEmpty())
return driver.run(query);

UserGroupInformation ugi = createUgi(userName);
CommandProcessorResponse response = ugi.doAs(new PrivilegedExceptionAction<CommandProcessorResponse>() {
public CommandProcessorResponse run() throws Exception {
CliSessionState ss = null;
ss = new MyCliSessionState(conf);
ss.out = new PrintStream(System.out, true, "UTF-8");
ss.err = new PrintStream(System.err, true, "UTF-8");

// refresh thread local SessionState and Hive
SessionState.start(ss);
Hive.get(conf, true);

return driver.run(query);
}
});

return response;

我能够连接到默认 数据库并获取所有表的列表。但是我怎样才能连接到其他数据库(default 除外)?我尝试搜索配置单元配置属性,但找不到指定数据库名称的配置属性。有人可以帮帮我吗。

最佳答案

看起来您想以困难的方式做事,并重新实现 Beeline 实用程序。对于大多数人来说,这似乎是一种受虐狂的尝试,但我有什么资格评判呢?

无论如何,在这一点上你必须执行HQL命令,就像其他人一样......并且任何人都应该知道“使用”命令:

driver.run("use " +argDatabase) ;
// check status
driver.run("show tables") ;
// check status, parse output
driver.run("describe extended " +argTable) ;
// check status, parse output

关于hadoop - Hive ql Driver如何指定默认以外的数据库名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34355691/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com