0

我正在使用 RJDBC 包连接到 Oracle DB。我需要检索大量数据,我想通过不同的核心分发查询。我知道该表有五百万条记录。因此,我编写了一个 SQL 查询,例如:

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) 

然后我分发到核心并设置环境核心

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))

然后我尝试进行查询:

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

我收到了这个错误,我真的不知道我能做什么。

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"’

我也在尝试“tbl”,但我明白了:

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

1 回答 1

0

dbGetQuery期望它的statement论点是类的character,而你似乎正在使用你所拥有的整个东西cluster_assign_value("sqlCl", sqlCl)
您也在cl创建group中使用,sqlCl我不确定sqlCl最终会是什么样子。

也许您想使用cluster_assign_each(...而不是cluster_assign_value("sqlCl", sqlCl).

我也不确定你为什么有by_group %>% cluster_library(...和没有cl %>% cluster_library(...

于 2018-03-23T13:51:14.253 回答