![](/img/trans.png)
[英]How to configure hive-jdbc-uber-jar in JDBC Sink Connector
[英]Hadoop Hive - How can I 'add jar' for use with the Hive JDBC client?
所以,我有hdfs和hive一起工作。 我還有用於Hive功能的jdbc驅動程序,以便我可以進行遠程jdbc調用。
現在,我添加了一個Hive用戶定義函數(UDF)。 它在CLI中運行良好...我甚至通過.hiverc文件自動加載jar和相關函數。 但是,我無法使用hive jdbc驅動程序來實現此功能。 我認為它也會使用.hiverc文件(默認情況下,位於/ usr / lib / hive / bin /),但它似乎不起作用。 我也嘗試通過'add jar'SQL命令添加它作為第一件事,但無論我把jar文件放在哪里,我在hive.log中都遇到錯誤,無法找到該文件。
有人知道怎么做嗎? 我正在使用Cloudera Distribution(CDH3u2),它使用Hive-0.7.1。
提前致謝。
根據Hive開發人員郵件列表,在當前的Hive版本(0.9)中,沒有針對此問題的解決方案。 為了解決這個問題,我使用了一個連接工廠類,每次啟動連接會話時都能正確注冊jar和函數。 下面的代碼非常有用:
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();
}
}
}
我也使用JDBC驅動程序連接到Hive。 我將jar壓縮到集群的主節點上,這也是安裝Hive的地方,然后在我的add jar命令中使用文件的絕對路徑(在主節點上)。 我通過JDBC驅動程序發出add jar命令,就像任何其他HQL命令一樣。
我認為JDBC驅動程序使用Thrift,這意味着JAR可能需要在Thrift服務器(您在conn字符串中連接到的hive服務器)和hive類路徑中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.