rjdbc与parallelmap的并行查询

时间:2017-07-26 07:44:52

标签: r parallel-processing rjdbc

我正在尝试以平行方式运行查询,但出现00001: Error in .jcheck() : No running JVM detected. Maybe .jinit() would help.错误。 当我逐个运行它们时,查询正在运行

我的剧本:

我知道它不是真正的可再现但我不能给你我的日志/通行证:)

我试图在奴隶中.jinit()Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jdk1.8.0_102')无法正常工作

library(RJDBC)
library(parallelemap)

jdbcDriver <- JDBC(driverClass="oracle.jdbc.OracleDriver",  classPath="ojdbc6.jar" )
jdbcConnection <- dbConnect(jdbcDriver, "jdbc:oracle:thin:@//mybase", "login", "pass")

query_list<- list( "SELECT * FROM table1",
                   "SELECT * FROM table2",
                   "SELECT * FROM table3",
                   "SELECT * FROM table4", 
                   "SELECT * FROM table5")


 import_base_fonction <- function(query) {return(dbGetQuery( jdbcConnection , query))}


parallelStartSocket( 5 ) 

parallelLibrary("RJDBC","rJava")
parallelExport("listquery_list","import_base_fonction" ,"jdbcConnection")

mes_tables <- parallelMap(import_base_fonction,query_list)  

parallelStop() 

我的会话信息

R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server >= 2012 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252 LC_NUMERIC=C                   LC_TIME=French_France.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] parallelMap_1.3      PhViD_1.0.8          MCMCpack_1.4-0       MASS_7.3-47          coda_0.19-1          LBE_1.44.0           dplyr_0.7.1         
 [8] plyr_1.8.4           shiny_1.0.3          DT_0.2               shinydashboard_0.6.1 data.table_1.10.4    RJDBC_0.2-5          rJava_0.9-8         
[15] DBI_0.7             

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.11       compiler_3.4.1     bindr_0.1          tools_3.4.1        digest_0.6.12      checkmate_1.8.3    tibble_1.3.3       lattice_0.20-35   
 [9] pkgconfig_2.0.1    rlang_0.1.1        Matrix_1.2-10      parallel_3.4.1     SparseM_1.77       bindrcpp_0.2       htmlwidgets_0.9    MatrixModels_0.4-1
[17] grid_3.4.1         glue_1.1.1         R6_2.2.2           magrittr_1.5       backports_1.1.0    BBmisc_1.11        htmltools_0.3.6    mcmc_0.9-5        
[25] assertthat_0.2.0   mime_0.5           xtable_1.8-2       httpuv_1.3.5       quantreg_5.33    

基础在Oracle 11.xx服务器上。

请指导。

1 个答案:

答案 0 :(得分:0)

我认为您可以将import_base_fonction更改为

import_base_fonction <- function(query) {
  .jinit("ojdbc6.jar")
  return(dbGetQuery( jdbcConnection , query))
 }