我一直在尝试使用RHive连接R和Hive,并且已经安装了所需的软件包(Rhive,rJava,Rserve)并设置了环境变量。在R我尝试以下,不知道连接hiveserver的原因是什么,谢谢:
启动R
> R
加载Rhive包
>库(RHive)
设置环境变量
> Sys.setenv(HIVE_HOME = “/ USR /本地/ Apache-蜂房-0.14.0槽”)
> Sys.setenv(HADOOP_HOME = “/ USR /本地/ Hadoop的2.5.1”)
初始化数据库
> rhive.init()
检查环境变量
> rhive.env()
hadoop home: /usr/local/hadoop-2.5.1
fs: file:///
hive home: /usr/local/apache-hive-0.14.0-bin
user name: hadoop
user home: /home/hadoop
temp dir: /tmp/hadoop>**
建立连接
> rhive.connect()
错误:
2015-06-10 15:19:48,060 INFO jdbc.Utils (Utils.java:parseURL(285)) - Supplied authorities: 127.0.0.1:10000
2015-06-10 15:19:48,060 INFO jdbc.Utils (Utils.java:parseURL(372)) - Resolved authority: 127.0.0.1:10000
2015-06-10 15:19:48,061 INFO jdbc.HiveConnection (HiveConnection.java:openTransport(189)) - Will try to open client transport with JDBC Uri: jdbc:hive2://127.0.0.1:10000/default
2015-06-10 15:19:48,061 INFO jdbc.HiveConnection (HiveConnection.java:openTransport(194)) - Could not open client transport with JDBC Uri: jdbc:hive2://127.0.0.1:10000/default
Exception in thread "Thread-39" java.lang.RuntimeException: java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://127.0.0.1:10000/default: java.net.ConnectException: Connection refused
at com.nexr.rhive.hive.HiveJdbcClient$HiveJdbcConnector.connect(HiveJdbcClient.java:337)
at com.nexr.rhive.hive.HiveJdbcClient$HiveJdbcConnector.run(HiveJdbcClient.java:322)
Caused by: java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://127.0.0.1:10000/default: java.net.ConnectException: Connection refused
at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:215)
at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:163)
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at com.nexr.rhive.hive.DatabaseConnection.connect(DatabaseConnection.java:51)
at com.nexr.rhive.hive.HiveJdbcClient$HiveJdbcConnector.connect(HiveJdbcClient.java:330)
... 1 more
Caused by: org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection refused
at org.apache.thrift.transport.TSocket.open(TSocket.java:185)
at org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:248)
at org.apache.thrift.transport.TSaslClientTransport.open(TSaslClientTransport.java:37)
at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:190)
... 7 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.thrift.transport.TSocket.open(TSocket.java:180)
... 10 more
Error: java.lang.IllegalStateException: Not connected to hiveserver
答案 0 :(得分:1)
我解决了连接到“hivevserver”而不是“hivesever2”的连接问题,它运行良好;代码如下所示,如果有人遇到同样的问题,希望可以作为参考:
>R
>Sys.setenv(HIVE_HOME="/usr/local/apache-hive-0.14.0-bin")
>Sys.setenv(HADOOP_HOME="/usr/local/hadoop-2.5.1")
>library(RHive)
>rhive.init
(
hiveLib="/usr/local/apache-hive-0.14.0-bin",
hadoopConf="/usr/local/hadoop-2.5.1/etc/hadoop",
hadoopLib="/usr/local/hadoop-2.5.1/lib",verbose=FALSE
)
>rhive.connect("172.22.25.162",hiveServer2=FALSE,defaultFS="hdfs://master:9000")
>tables_overview<-rhive.query("show tables")
>View(tables_overview)