Hive ql Driver如何指定默认以外的数据库名称
Hive ql Driver how to specify database name other than default
我正在编写示例程序以使用 org.apache.hadoop.hive.ql.Driver class 连接到 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 数据库并获取所有表的列表。但是我如何连接到其他数据库(default 除外)?我尝试搜索配置单元配置 属性,但找不到指定数据库名称的配置。有人可以帮帮我吗
看来您想以艰难的方式做事,并重新实现 Beeline 实用程序。对于大多数人来说,这似乎是一种受虐狂的尝试,但我有什么资格评判呢?
无论如何,此时你必须执行HQL命令,就像其他人一样...而且任何人都应该知道"use"命令:
driver.run("use " +argDatabase) ;
// check status
driver.run("show tables") ;
// check status, parse output
driver.run("describe extended " +argTable) ;
// check status, parse output
我正在编写示例程序以使用 org.apache.hadoop.hive.ql.Driver class 连接到 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 数据库并获取所有表的列表。但是我如何连接到其他数据库(default 除外)?我尝试搜索配置单元配置 属性,但找不到指定数据库名称的配置。有人可以帮帮我吗
看来您想以艰难的方式做事,并重新实现 Beeline 实用程序。对于大多数人来说,这似乎是一种受虐狂的尝试,但我有什么资格评判呢?
无论如何,此时你必须执行HQL命令,就像其他人一样...而且任何人都应该知道"use"命令:
driver.run("use " +argDatabase) ;
// check status
driver.run("show tables") ;
// check status, parse output
driver.run("describe extended " +argTable) ;
// check status, parse output