您的位置:首页 > 运维架构 > Linux

【R】CentOS7下Rstudio实践初探及遇到的问题 二(连接hive)

2017-01-12 13:21 351 查看

缘起

连接hive,似乎在网络上已经找不到正确的配置和下载了。

因此只能根据官方的来。

分析

首先直接install package的时候,编译RHive,提示找不到。但提示找到一个HiveR的包。

那然后直接安装HiveR的包,则提示make jpeg和png的时候出错。

那么我估计要么在配置configure的时候出问题,要么就是没有支持对应格式的包。

实操

configure的问题,我重新配置,且配置的时候基本都是true,没有按照最简配置的false来。

configure问题解决后,那么就是安装配置jpeg和png了。

安装make不能,那么就是缺少make的对应环境。

这里环境给出两个。不过最好是在安装R之前配置好比较推荐。

yum install -y  libpng-devel
yum install -y  libjpeg-devel


这两个配置完毕后,就能在R中直接install了。

install.packages("jpeg")
install.packages("png")
install.packages("Rserve")


配置完这三个,就准备开始进行安装RHive。

但是,直接进行install,还是提示不能。

那么只能根据官方给出的最新tar包进行本地安装了。

关键操作

在官网下载对应包:https://cran.r-project.org/src/contrib/Archive/RHive/

找到最新版本,然后下载到本地。

然后传到本地进行linux上的安装。

R CMD INSTALL RHive_2.0-0.2.tar.gz
#完毕后在R中就可以引用了
> library(RHive)
Loading required package: rJava


连接hive即其他操作

> library(RHive);
Loading required package: rJava
> rhive.connect(host ='114.215.182.147')
2017-01-12 13:47:22,243 INFO  Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(1173)) - fs.default.name is deprecated. Instead, use fs.defaultFS
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/hadoop-2.7.3/share/hadoop/httpfs/tomcat/webapps/webhdfs/WEB-INF/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/hadoop-2.7.3/share/hadoop/kms/tomcat/webapps/kms/WEB-INF/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hive/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
2017-01-12 13:47:23,714 WARN  util.NativeCodeLoader (NativeCodeLoader.java:<clinit>(62)) - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Warning:
+----------------------------------------------------------+
+ / hiveServer2 argument has not been provided correctly.  +
+ / RHive will use a default value: hiveServer2=TRUE.      +
+----------------------------------------------------------+

2017-01-12 13:47:25,390 INFO  jdbc.Utils (Utils.java:parseURL(318)) - Supplied authorities: 114.215.182.147:10000
2017-01-12 13:47:25,392 INFO  jdbc.Utils (Utils.java:parseURL(437)) - Resolved authority: 114.215.182.147:10000
[1] FALSE
>


以上信息表示RHive已经可以工作,接下来,我们就来在R中读取hive中的数据。

Hive数据的R读取

library(RHive)
rhive.connect(host ='114.215.xxx.xxx',port=10000);  #rhive连接hive2
> x <- rhive.query('select id from studentinfo')
> print(x)
id
1   NA
2   NA
3   NA
4   NA
5    1
6    2
7    3
8  100
9    1
10   2
11   3
12 100


可以看到数据已经读取并且在R语言中可以进行图形的绘制。

后记

每一次的配置和尝试都走了数个坑。

也不怪资料不全,还是要自己多试试,根据经验找到错误根源,然后进行对应的方法解决。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息