0

I'm using RJDBC package for connecting to an Oracle DB. I need to retrieve a huge amount of data, and I would like to distribute the inquiry through different cores. I know that the table has five millions records. Thus I write a SQL Query like:

SqlCMD =   "SELECT * from ( SELECT m.*, rownum r FROM  Table ) WHERE r >= minV AND r < maxV"

points = ceiling(seq(1, rownum, length.out = 20))

 [1]       1  269578  539154  808730 1078306 1347882 1617458 1887034 2156610 2426186 2695762 2965338 3234914 3504490 3774066
[16] 4043642 4313218 4582794 4852370 5121946

sqlCl = NULL
for (i in 1:19){
  sqlCl[i] = gsub("minV", points[i], sqlCMD)
  sqlCl[i] = gsub("maxV", points[i+1], sqlCl[i])
}
sqlCl = sqlCl %>% as.data.frame

group <- rep(1:cl, length.out = 19)
sqlCl <- bind_cols(tibble(group),  sqlCl)
cl <- create_cluster(8) 

Then I distribute to cores and I set env cores

by_group <- sqlCl %>%
  partition(group, cluster = cl)

by_group %>%
  cluster_library("RJDBC") %>%
  cluster_library("dplyr") %>%
  cluster_assign_value("sqlCl", sqlCl) %>%
  cluster_assign_value("pathOjdbc", pathOjdbc)%>% #path to ojdbc8.jar
  cluster_assign_value("dbName", dbName) %>%
  cluster_assign_value("user", user)%>%
  cluster_assign_value("password", password) %>% 
  cluster_assign_value("dbGetQuery", dbGetQuery)


by_group %>%
  cluster_assign_value("conn", 
dbConnect(JDBC(driverClass="oracle.jdbc.OracleDriver", classPath = pathOjdbc), 
dbName, user , password))

Then I try to do the inquiry:

ws3_processed_in_parallel <- 
  by_group %>% 
  do({
    df = RJDBC::dbGetQuery(conn, sqlCl)
  })

I got this error and I really do not know what i can do.

Error in checkForRemoteErrors(lapply(cl, recvResult)) : 
  8 nodes produced errors; first error: unable to find an inherited method for function ‘dbGetQuery’ for signature ‘"JDBCConnection", "tbl_df"’

I'm trying also with "tbl" but I get this:

  Error in (function (classes, fdef, mtable)  : 
      unable to find an inherited method for function ‘dbBegin’ for signature ‘"JDBCConnection"’

1 Answers1

0

dbGetQuery expects its statement argument to be of class character, whereas you seem to be using the whole thing that you have from cluster_assign_value("sqlCl", sqlCl).
You are also using cl in creating group and sqlCl and I am not sure what sqlCl looks like in the end.

Maybe you want to use cluster_assign_each(... instead of cluster_assign_value("sqlCl", sqlCl).

I am also not sure why you have by_group %>% cluster_library(... and not cl %>% cluster_library(....

RolandASc
  • 3,863
  • 1
  • 11
  • 30