2015-10-31 42 views
2

我使用Hortonworks Hadoop的HDP-2.3.2.0-2950 蜂巢超過TEZ引擎蜂巢超過TEZ通過蜂巢JDBC - 錯誤

低於2個查詢是從Java代碼。

  • select * from ascii - 行之有效
  • select count(*) from ascii or select count(1) from ascii - 失敗,錯誤出

我的代碼:

package com.hadoop.hive; 

import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
/** 
* 
* @author hdpadmin 
* 
*/ 
public class HiveReadJDBCMain { 
     private static String driverName = "org.apache.hive.jdbc.HiveDriver"; 

     /** 
     * @param args 
     * @throws SQLException 
     */ 
     public static void main(String[] args) throws SQLException { 
       Connection con = null; 
       PreparedStatement pst = null; 
       ResultSet res = null; 

       try { 

         // Load Hive Driver Clazz 
         Class.forName(driverName); 
         // No username and password required.(running in a local machine) 
         con = DriverManager.getConnection("jdbc:hive2://localhost:10000/labs"); 
         //Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/labs", "<Username>", "<Password>"); 
         String tableName = "ascii"; 
         // select * query 
         String sql = "select * from " + tableName; 
         System.out.println("Select Query Running: " + sql); 
         pst = con.prepareStatement(sql); 
         res = pst.executeQuery(); 
         while (res.next()) { 
           System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2)); 
         } 
         pst.close(); 
         res.close(); 

         // regular hive query 
         sql = "select count(*) from " + tableName; 
         System.out.println("Count Query Running: " + sql); 
         pst = con.prepareStatement(sql); 
         res = pst.executeQuery(); 
         while (res.next()) { 
           System.out.println(res.getString(1)); 
         } 
       } catch (ClassNotFoundException e) { 
         e.printStackTrace(); 
         System.exit(1); 
       } catch (Exception e) { 
         e.printStackTrace(); 
         System.exit(1); 
       } finally { 
         res.close(); 
         pst.close(); 
         con.close(); 
       } 
     } 
} 

Error 
java.sql.SQLException: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.tez.TezTask 
     at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:282) 
     at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:378) 
     at org.apache.hive.jdbc.HivePreparedStatement.executeQuery(HivePreparedStatement.java:109) 
     at com.hadoop.hive.HiveReadJDBCMain.main(HiveReadJDBCMain.java:48) 

回答

4

是的,我已經通過將固定在下面我的用戶連接對象名稱 謝謝.... :)

con = DriverManager.getConnection("jdbc:hive2://localhost:10000/labs", "hdpadmin",""); 
+0

是否添加用戶名修復了您的錯誤?我陷入了同樣的錯誤。如果您找到解決方案,請給我加標籤。是的,我添加了用戶名,但仍然出現錯誤 – Saurab

1

我也通過在連接字符串中傳遞用戶名來修復。謝謝:)

0

查詢像選擇*從表;工作得很好,因爲他們沒有推出任何MR工作。啓動MR作業時,與其建立JDBC連接的用戶需要具有Job所需的HDFS目錄的正確訪問權限。如果你想看到實際的堆棧跟蹤運行MR模式運行相同的工作。要做到這一點通過在連接字符串或作爲參數如下: -

connection = DriverManager.getConnection("jdbc:hive2://localhost:10000/labs?hive.execution.engine=mr", "hive",""); 

這將打印實際的錯誤,我想TEZ抽象了實際的錯誤。

此答案是對上述答案的Saurab's評論。沒有足夠的回購評論:p。