我正在使用 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"’