根据Hive开发者邮件列表,在当前的Hive版本(0.9)中,这个问题没有解决方案。为了解决这个问题,我使用了一个连接工厂类,在每次启动连接会话时正确注册罐子和函数。代码波纹管工作奇妙:
package com.rapidminer.operator.bigdata.runner.helpers;
import java.sql.*;
/** A Hive connection factory utility
@author Marcelo Beckmann
*/
public class ConnectionFactory {
private static ConnectionFactory instance;
/** Basic attributes to make the connection*/
public String url = "jdbc:hive://localhost:10000/default";
public final String DRIVER = "org.apache.hadoop.hive.jdbc.HiveDriver";
public static ConnectionFactory getInstance(){
if (instance==null)
instance = new ConnectionFactory();
return instance;
}
private ConnectionFactory()
{}
/**
* Obtains a hive connection.
* Warning! To use simultaneous connection from the Thrift server, you must change the
* Hive metadata server from Derby to other database (MySQL for example).
* @return
* @throws Exception
*/
public Connection getConnection() throws Exception {
Class.forName(DRIVER);
Connection connection = DriverManager.getConnection(url,"","");
runInitializationQueries(connection);
return connection;
}
/**
* Run initialization queries after the connection be obtained. This initialization was done in order
* to workaround a known Hive bug (HIVE-657).
* @throws SQLException
*/
private void runInitializationQueries(Connection connection) throws SQLException
{
Statement stmt = null;
try {
//TODO Get the queries from a .hiverc file
String[] args= new String[3];
args[0]="add jar /home/hadoop-user/hive-0.9.0-bin/lib/hive-beckmann-functions.jar";
args[1]="create temporary function row_number as 'com.beckmann.hive.RowNumber'";
args[2]="create temporary function sequence as 'com.beckmann.hive.Sequence'";
for (String query:args)
{
stmt.execute(query);
}
}
finally {
if (stmt!=null)
stmt.close();
}
}
}
感谢您的快速反应。然而,我不确定我会在哪里做到这一点。我试图将这些jar添加到服务器的hadoop-env.sh文件(CLASSPATH)以及hive-env.sh文件(CLASSPATH)。这些似乎都没有工作。 – Wanderer 2012-01-17 17:59:21