s-u / RJDBC

R interface to databases using JDBC
Other
52 stars 47 forks source link

R JDBC Kerberos #57

Open darshanpandya-kogentix opened 6 years ago

darshanpandya-kogentix commented 6 years ago

Hello ,

I am trying to connect R to Hive (kerberos enabled) .. Please let me know if the following is the right approach. If yes, I am running into an issue which is not giving enough information to debug.

Thank you for your help in advance.

hadoop.class.path = list.files(path=c("/usr/hdp/2.6.2.0-205/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) .jinit(classpath=cp, parameters="-DRJDBC.debug=true") drv <- JDBC("org.apache.hive.jdbc.HiveDriver","hive-jdbc.jar",identifier.quote="`") conn <- dbConnect(drv, "jdbc:hive2://myserver.corp.server.com:10000/default;principal=hive/_HOST@CORP.server.COM","","") Error in .jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1], : java.lang.NoClassDefFoundError: Could not initialize class org.apache.hive.jdbc.HiveConnection

adamsma commented 5 years ago

I know this is a bit of an old issue, but I recently had to set up a connection using Kerberos. To get it to work before creating the driver, I had to create a UserGroupInformation class and use the loginUserFromKeytab method. Something along the lines of:

  conf <- rJava::.jnew("org.apache.hadoop.conf.Configuration")
  conf$set("hadoop.security.authentication", "kerberos")

  ugi <- rJava::J("org.apache.hadoop.security.UserGroupInformation")
  ugi$setConfiguration(conf)
  ugi$loginUserFromKeytab("<PRINCIPAL>", "<PATH_TO_KEYTAB>")

Then set up the Hive driver and connect.