R和Hive之间的连通性 [英] Connectivity between R and Hive

查看:50
本文介绍了R和Hive之间的连通性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在RStudio(在我的计算机上)和Hive(在另一台服务器上设置)之间建立连接.这是我的R代码:

I am trying to establish a connection between RStudio (on my machine) and Hive (which is setup on a different server). Here's my R code:

install.packages("RJDBC",dep=TRUE)
require(RJDBC)

drv <- JDBC(driverClass = "org.apache.hive.jdbc.HiveDriver", 
       classPath = list.files("C:/Users/37/Downloads/hive-jdbc-0.10.0.jar",
       pattern="jar$",full.names=T),
       identifier.quote="'")

这是我执行上述命令时遇到的错误:

Here is the error I get while executing the above commands:

.jfindClass(as.character(driverClass)错误 1 ):找不到课程conn<-dbConnect(drv,"jdbc:hive2://65.11.23.453:10000/default","admin","admin")

Error in .jfindClass(as.character(driverClass)1) : class not found conn <- dbConnect(drv, "jdbc:hive2://65.11.23.453:10000/default", "admin", "admin")

我从此处下载了jar文件并将其放在 CLASSPATH .请告知是否做错了什么以及如何使它正常工作.

I downloaded the jar files from here and placed them in the CLASSPATH. Please advise if am doing anything wrong and how I could get this to work.

谢谢.

推荐答案

如果您有cloudera,请检查版本并下载jar.例子CDH 5.9.1hadoop-common-2.6.0-cdh5.9.1.jarhive-jdbc-1.1.1-standalone.jar

If you have a cloudera, check version and download jars for that. Example CDH 5.9.1 hadoop-common-2.6.0-cdh5.9.1.jar hive-jdbc-1.1.1-standalone.jar

将罐子复制到R主机的文件夹中并执行:

copy the jars into a folder into R host and execute:

 library("DBI")

 library("rJava")

 library("RJDBC")

#init of the classpath (works with hadoop 2.6 on CDH 5.4 installation)
cp = c("/home/youruser/rlibs/hadoop-common-2.6.0-cdh5.9.1.jar", "/home/youruser/rlibs/hive-jdbc-1.1.1-standalone.jar")
.jinit(classpath=cp)

#initialisation de la connexion
drv <- JDBC("org.apache.hive.jdbc.HiveDriver", /home/youruser/rlibs/hive-jdbc-1.1.1-standalone.jar", identifier.quote="`")

conn <- dbConnect(drv,"jdbc:hive2://HiveServerHostInYourCluster:10000/default;", "YourUserHive", "xxxx")

#working with the connexion
show_databases <- dbGetQuery(conn, "show databases")
show_databases

这篇关于R和Hive之间的连通性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆