Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

R with Hive

R with Hive

New Contributor
 
4 REPLIES 4

Re: R with Hive

Super Collaborator

check the answer here where it is decribed on how to set up a JDBC connection in R to connect to Hive: https://community.hortonworks.com/questions/38071/hi-how-to-integrate-the-r-language-with-hive-hadoo...

Re: R with Hive

Super Collaborator

not sure if I am getting you right?

If you need some starting point for RStudio, I recommend you some online tutorials for RStudio: https://www.rstudio.com/online-learning/ But I am no R programmer, so I can't support on specifics of R.

If you need some help on how to work with Hive: http://hadooptutorial.info/hiveserver2-beeline-introduction/

If you need some help on connecting R to Hive, is recommend you the link i sent in the previous post.

Re: R with Hive

New Contributor

Re: R with Hive

@Gayathri Devi

Sample R script:

library(DBI)
library(rJava)
library(RJDBC)
hadoop.class.path = list.files(path=c("/usr/hdp/2.4.0.0-169/hadoop"),pattern="jar", full.names=T);
hive.class.path = list.files(path=c("/usr/hdp/current/hive-client/lib"),pattern="jar", full.names=T);
hadoop.lib.path = list.files(path=c("/usr/hdp/current/hive-client/lib"),pattern="jar",full.names=T);
mapred.class.path = list.files(path=c("/usr/hdp/current/hadoop-mapreduce-client/lib"),pattern="jar",full.names=T);
cp = c(hive.class.path,hadoop.lib.path,mapred.class.path,hadoop.class.path)
drv <- JDBC("org.apache.hive.jdbc.HiveDriver","hive-jdbc.jar",identifier.quote="`")
conn <- dbConnect(drv, "jdbc:hive2://ixxx:10000/default", "hive", "hive")
show_databases <- dbGetQuery(conn, "show databases")

(OR)

library("DBI")
library("rJava")
library("RJDBC")
hive.class.path = list.files(path=c("/usr/hdp/current/hive-client/lib"), pattern="jar", full.names=T);hadoop.lib.path = list.files(path=c("/usr/hdp/current/hive-client/lib"), pattern="jar", full.names=T);hadoop.class.path = list.files(path=c("/usr/hdp/2.4.0.0-169/hadoop"), pattern="jar", full.names=T);
cp = c(hive.class.path, hadoop.lib.path, hadoop.class.path, "/usr/hdp/2.4.0.0-169/hadoop-mapreduce/hadoop-mapreduce-client-core.jar")
.jinit(classpath=cp)
drv <- JDBC("org.apache.hive.jdbc.HiveDriver","hive-jdbc.jar",identifier.quote="`")
url.dbc <-paste0("jdbc:hive2://xxx:10000/default");
conn <- dbConnect(drv, url.dbc, "hive", “hive");dbListTables(conn);
Don't have an account?
Coming from Hortonworks? Activate your account here