简体   繁体   English

使用Java在Hive中显示创建表

[英]show create table in hive using java

I am trying to execute show create table statement thru a JDBC hive connection. 我正在尝试通过JDBC配置单元连接执行show create table语句。 The aim is to get the location of the file containing the data of hive table. 目的是获取包含配置单元表数据的文件的位置。

I tried the following code but got following exception: 我尝试了以下代码,但出现以下异常:

ResultSet rs = stmt.executeQuery(hiveTable);

    System.out.println("Resultset not null"+(rs != null));
    int i = 0;
    while(rs.next()){
        System.out.println(rs.getString(i));
        i++;
}

Exception: 例外:

Exception in thread "main" java.sql.SQLException: Error while compiling statement: FAILED: ParseException line 1:4 cannot recognize input near 'show' '<EOF>' '<EOF>' in ddl statement
        at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:120)
        at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:108)
        at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:233)
        at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:376)
        at com.capitalone.def.impl.TestClass.main(TestClass.java:33)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:212)

Please help me resolve this. 请帮我解决这个问题。

Using following code you can get table location 使用以下代码可以获取表的位置

HiveConf conf = new HiveConf();
conf.set(HiveConf.ConfVars.METASTOREURIS.varname, <metaStoreURI>);
HiveMetaStoreClient hiveMetaStoreClient = new HiveMetaStoreClient(conf);
Table tab = hiveMetaStoreClient.getTable(<db name>, <tab name>);
tab.getSd().getLocation()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM