分享

hive jdbc方式查询出现: Table not found 错误

checkking_2012 发表于 2013-10-16 13:40:27 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 2 17805
在弄一个项目,需要采用编成的方式从hive中查询数据,但是没有成功,说Table not found.。但我用hive shell 能够查到数据,而且hive的表是存在hdfs中,之前数据是通过hive shell 从hdfs中导入的。
求各位帮我分析原因并提出解决方案,谢谢!
demo代码如下:
package com.checkking.hive;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class HiveJdbcClient {
  private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
  /**
* @param args
* @throws SQLException
   */
  public static void main(String[] args) throws SQLException {
      try {
      Class.forName(driverName);
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      System.exit(1);
    }
   
    Connection con = DriverManager.getConnection("jdbc:hive://", "", "");
    Statement stmt = con.createStatement();
   
   // stmt.executeQuery("use default");
    ResultSet res  = stmt.executeQuery("select count(*) from default.log_hive_table where dt='20130317'");
   
    if (res.next()) {
      System.out.println(res.getInt(1));
    }
      con.close();
  }
}
报错:
13/04/03 20:12:14 ERROR metadata.Hive: NoSuchObjectException(message:default.log_hive_table table not found)
        at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler$17.run(HiveMetaStore.java:1222)
        at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler$17.run(HiveMetaStore.java:1217)
        at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.executeWithRetry(HiveMetaStore.java:360)
        at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.get_table(HiveMetaStore.java:1217)
        at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.getTable(HiveMetaStoreClient.java:734)
        at org.apache.hadoop.hive.ql.metadata.Hive.getTable(Hive.java:901)
        at org.apache.hadoop.hive.ql.metadata.Hive.getTable(Hive.java:843)
        at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.getMetaData(SemanticAnalyzer.java:908)
        at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:7275)
        at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:243)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:430)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:337)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:889)
        at org.apache.hadoop.hive.service.HiveServer$HiveServerHandler.execute(HiveServer.java:191)
        at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:187)
        at com.checkking.hive.HiveJdbcClient.main(HiveJdbcClient.java:29)
13/04/03 20:12:14 ERROR parse.SemanticAnalyzer: org.apache.hadoop.hive.ql.parse.SemanticException: Line 1:21 Table not found 'log_hive_table'
        at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.getMetaData(SemanticAnalyzer.java:910)
        at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:7275)
        at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:243)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:430)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:337)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:889)
        at org.apache.hadoop.hive.service.HiveServer$HiveServerHandler.execute(HiveServer.java:191)
        at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:187)
        at com.checkking.hive.HiveJdbcClient.main(HiveJdbcClient.java:29)
FAILED: Error in semantic analysis: Line 1:21 Table not found 'log_hive_table'
13/04/03 20:12:14 ERROR ql.Driver: FAILED: Error in semantic analysis: Line 1:21 Table not found 'log_hive_table'
org.apache.hadoop.hive.ql.parse.SemanticException: Line 1:21 Table not found 'log_hive_table'
        at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.getMetaData(SemanticAnalyzer.java:1080)
        at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:7275)
        at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:243)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:430)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:337)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:889)
        at org.apache.hadoop.hive.service.HiveServer$HiveServerHandler.execute(HiveServer.java:191)
        at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:187)
        at com.checkking.hive.HiveJdbcClient.main(HiveJdbcClient.java:29)
Caused by: org.apache.hadoop.hive.ql.parse.SemanticException: Line 1:21 Table not found 'log_hive_table'
        at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.getMetaData(SemanticAnalyzer.java:910)
        ... 8 more
              
               
                    hive
                    hadoop
                    hive jdbc
                    hive client
               

已有(2)人评论

跳转到指定楼层
tntzbzc 发表于 2013-10-16 13:41:22

            引用 楼主 checkking_2012 的回复:在弄一个项目,需要采用编成的方式从hive中查询数据,但是没有成功,说Table not found.。但我用hive shell 能够查到数据,而且hive的表是存在hdfs中,之前数据是通过hive shell 从hdfs中导入的。
求各位帮我分析原因并提出解决方案,谢谢!
demo代码如下:
Java code?1234567891011121314151……

Hive Thrift Server 启动了吗?
在HIVE所在的LINUX SHELL中输入
[hadoop@xxx bin]# hive --service hiveserver 50031
Starting Hive Thrift Server //启动成功
Connection con = DriverManager.getConnection("jdbc:hive://", "", "");
//con 改成以下,以便多CLIENT访问
Connection con = DriverManager.getConnection(
                     "jdbc:hive://HiveServier的IP地址:50031/default", "", "");
        
回复

使用道具 举报

bin_1715575332 发表于 2013-10-16 13:42:19

            检查启动了hiveserver服务没,貌似还要检查metastore服务是否开启。
还有,官方wiki的sample看了么?那个是没问题的!!你仔细检查一下!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条