Using Hive from R

Using Hive from R

We need to install following packages

R CMD INSTALL rJava
R CMD INSTALL RHive

rm(list=ls())
options( java.parameters = "-Xmx8g" )

library(RJDBC)
if (Sys.getenv("JAVA_HOME")!="") Sys.setenv(JAVA_HOME="")
.jinit()
for(l in list.files('/usr/phd/3.0.0.0-249/hadoop',pattern="*.jar",recursive=TRUE)){ .jaddClassPath(paste("/usr/phd/3.0.0.0-249/hadoop/",l,sep=""))}


hivedrv <- JDBC("org.apache.hive.jdbc.HiveDriver", "/usr/phd/3.0.0.0-249/hive/lib/hive-jdbc.jar")
conn <- dbConnect(hivedrv, "jdbc:hive2://hive:10000/default", "myusername")

counter <- dbGetQuery(conn, "select count(*) from default.tablename")

counter

Change the paths for jar above as per your Hadoop distribution

No comments:

Post a Comment

Please share your views and comments below.

Thank You.