大家好,我使用的是Hive jdbc,但是在那之后我才知道,这里有Hive Metastore Java api(这里),您可以通过它再次连接到Hive并操作Hive数据库
但是我想知道这两种方式到底有什么区别
抱歉,如果有人提出任何明显的要求,我们将不胜感激
据我了解,有两种方法可以连接到Hive
现在,在较早的hive版本中,hiveserver2以前并不那么稳定,实际上,它对多线程的支持也受到限制。我想,那个领域的情况可能会有所改善。
因此,对于JDBC API-是的,它将允许您使用JDBC和sql进行通信。
对于metastore连接,似乎有2个功能。
DDL-
对于DDL,可以使用metastore API,org.apache.hadoop.hive.metastore.HiveMetaStoreClient HiveMetaStoreClient类可用于此目的。
DML-
我发现在这方面有用的是org.apache.hadoop.hive.ql.Driver https://hive.apache.org/javadocs/r0.13.1/api/ql/org/apache/hadoop/hive/ql /Driver.html hive.ql.Driver类此类具有一种名为的方法run()
,该方法使您可以执行SQL语句并将结果返回。例如,您可以执行以下操作
Driver driver = new Driver(hiveConf);
HiveMetaStoreClient client = new HiveMetaStoreClient(hiveConf);
SessionState.start(new CliSessionState(hiveConf));
driver.run("select * from employee);
// DDL example
client.dropTable(db, table);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句