hive over tez via hive jdbc-错误

cyej8jka  于 2021-05-29  发布在  Hadoop
关注(0)|答案(3)|浏览(361)

我正在使用hortonworkshadoop-2.3.2.0-2950hiveovertez引擎
下面两个查询来自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)
vmjh9lq9

vmjh9lq91#

是的,我已经用我的用户名通过下面的连接对象修复了,谢谢……)

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

j9per5c42#

我还修复了在连接字符串中传递用户名的问题。谢谢:)

bxjv4tth

bxjv4tth3#

如果您使用aws配置单元jdbc与默认emr集群进行通信,intellij中的以下设置对我很有用

诀窍是使用用户 hadoop

相关问题