Unable to call rJava library from within a R UDTF

I am writing in the hopes that someone may have encountered this issue and may be able to help. In one of our projects, I need to access Vertica database from within a Vertica R UDTF. This requires calling library RJDBC and rJava from within R UDTF. rJava is the pre-requisite for RJDBC package. When rJava library is called from within R UDTF, it gives the following error:

ERROR 3399: Failure in UDx RPC call InvokeProcessPartition(): Error calling processPartition() in User Defined Object [testv1p] at [/scratch_a/release/svrtar19690/vbuild/vertica/OSS/UDxFence/RInterface.cpp:1387], error code: 0, message: Exception in processPartitionForR: [package or namespace load failed for ‘rJava’]

The interesting thing is that it works just fine if I try to call the rJava library from regular R session but not from within R UDTF.

Has anyone encountered this before? Or have you attempted to connect to Vertica database from within R UDTF or R UDX? If so, would you provide some tips to resolve this? I have tried a lot of things discussed in the net but unfortunately none worked. From all the research that I have done, I feel this has to do with the system level R UDTF and how it interacts with JAVA JDK and rJava.

Any information you can provide would be appreciated.

Below is my code for R UDTF:

Main Function

testv1 <- function(y)
{
setwd("/path to the code")
.libPaths("/opt/vertica/R/library")
Sys.setenv(JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre")
Sys.setenv(PATH="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/bin")
Sys.setenv(LD_LIBRARY_PATH="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/amd64/server")
library(rJava)
library(RJDBC)
vDriver <- JDBC(driverClass="com.vertica.jdbc.Driver", classPath="/home/userid/vertica-jdbc-8.1.1-7.jar")
vertica<-dbConnect(vDriver,"jdbc:vertica://path_to_the_server:5433/db","uid","pwd")
myresults<-dbGetQuery(vertica,"select 1,2 from dual")
return(myresults)
}

Factory function

testv1Factory <- function()
{
list(
name=testv1
,udxtype=c("transform")
,intype=c("varchar","varchar")
,outtype=c("varchar","varchar")
,outnames=c("Segment","Probability")
)

Any information is appreciated. I have put a lot of hours in researching but I have exhausted my search.

Regards,
Shree

Comments

  • HibikiHibiki Vertica Employee Employee

    Hi Shree,

    Can you add the following to /etc/bashrc and try to run this function?

    export LD_LIBRARY_PATH=/opt/vertica/R/lib:/data/qb_workspaces/jenkins2/ReleaseBuilds/Grader/REL-9_2_0-x_grader/build/third-party/install/lib:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/lib/amd64/server

    Please change the directory of JAVA_HOME according to your environment.

    Best regards,

    Hibiki

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file