Reputation: 87
I'm trying to connect R and Hive (Spark). On my desktop (Windows 10, R-3.4.2) it works good, but on R-server (Linux, R - 3.4.4) I receive the error:
library(rJava)
library(RJDBC)
driver <- JDBC("org.apache.hive.jdbc.HiveDriver", "~/Drivers/Spark/hive-jdbc-1.2.1-spark2-amzn-0.jar",identifier.quote="`")
url <- "jdbc:hive2://<MyIP>:10001"
conn <- dbConnect(driver, url)
Error in .jcall(drv@jdrv,"Ljava/sql/Connection;", "connect", as.character(url)[1], : java.lang.NoClassDefFoundError: org/apache/http/client/CookieStore
What's wrong?
Upvotes: 0
Views: 690
Reputation: 87
I found the solution:
library(rJava)
library(RJDBC)
options(java.parameters = '-Xmx256m')
hadoop_jar_dirs <- c('//home//ubuntu//spark-jdbc//')
clpath <- c()
for (d in hadoop_jar_dirs) {
clpath <- c(clpath, list.files(d, pattern = 'jar', full.names = TRUE))
}
.jinit(classpath = clpath)
.jaddClassPath(clpath)
hive_jdbc_jar <- 'hive-jdbc-1.2.1-spark2-amzn-0.jar'
hive_driver <- 'org.apache.hive.jdbc.HiveDriver'
hive_url <- 'jdbc:hive2://<MyIP>:10001'
drv <- JDBC(hive_driver, hive_jdbc_jar)
conn <- dbConnect(drv, hive_url)
show_databases <- dbGetQuery(conn, "show databases")
show_databases
Upvotes: 2