据我所知,有两种方法可以连接到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);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5086 次 |
最近记录: |