Marcin
Marcin

Reputation: 8074

Passing additional parameters to dbConnect function for JDBCDriver in R

I am trying to connect to HiveServer2 via JDBC drivers from R using RJDBC package. I have seen a broad explanation on passing additional arguments to dbConnect wrapper for various drivers(What arguments can I pass to dbConnect?), but there appear that situation with JDBCDriver is a bit tricker than for other drivers. I can connect to HiveServer2 under this specific URL adress url = paste0("jdbc:hive2://", host = 'tools-1.hadoop.srv', ":", port = 10000, "/loghost;auth=noSasl") . The correspoding code works and enables me to write statements on Hive from R

library(RJDBC)
dbConnect(drv = JDBC(driverClass = "org.apache.hive.jdbc.HiveDriver",
                     classPath = c("/opt/hive/lib/hive-jdbc-1.0.0-standalone.jar",
                                   "/usr/share/hadoop/share/hadoop/common/lib/commons-configuration-1.6.jar",
                                   "/usr/share/hadoop/share/hadoop/common/hadoop-common-2.4.1.jar"),
                     identifier.quote = "`"), # to juz niekoniecznie jest potrzebne
          url = paste0("jdbc:hive2://", host = 'tools-1.hadoop.srv', ":", port = 10000, "/loghost;auth=noSasl"),
          username = "mkosinski") -> conn

I am wondering if there is a way to pass arguments such as database name (loghost) or a no_authentication_mode (auth=noSasl) to ... in dbConnect such that I could only specify standard URL address (url = paste0("jdbc:hive2://", host = 'tools-1.hadoop.srv', ":", port = 10000)) and somehow pass the rest of parametrs like this

library(RJDBC)
dbConnect(drv = JDBC(driverClass = "org.apache.hive.jdbc.HiveDriver",
                     classPath = c("/opt/hive/lib/hive-jdbc-1.0.0-standalone.jar",
                                   "/usr/share/hadoop/share/hadoop/common/lib/commons-configuration-1.6.jar",
                                   "/usr/share/hadoop/share/hadoop/common/hadoop-common-2.4.1.jar"),
                     identifier.quote = "`"), # to juz niekoniecznie jest potrzebne
          url = paste0("jdbc:hive2://", host = 'tools-1.hadoop.srv', ":", port = 10000),
          username = "mkosinski", dbname = "loghost", auth = "noSasl") -> conn

But the second approach doesn't look to work, despite the various combinations of names and values of additional arguments I try.

Does anyone know how to pass additional arguments to DBI::dbConnect through ... parameter for JDBCDriver?

Upvotes: 8

Views: 1963

Answers (2)

Lychenus
Lychenus

Reputation: 1

there you can use the full url

library(RJDBC)
drv <- JDBC("org.postgresql.Driver","C:/R/postgresql-9.4.1211.jar")
con <- dbConnect(drv, url="jdbc:postgresql://host:port/dbname", user="<user name>", password="<password>")

Upvotes: 0

Marcin
Marcin

Reputation: 8074

According to the author's answer: https://github.com/s-u/RJDBC/issues/31#issuecomment-173934951

Simply anything - all that dbConnect does is to collect whatever you pass (including ...) and collect it all into a property dictionary (java.util.Properties) that is passed to the driver's connect() method. So any named argument you pass is included. So the only special argument is url which is passed directly, everything else is included in the properties. How that gets interpreted is out of RJDBC's hands - it's entirely up to the driver.

Upvotes: 1

Related Questions