darwin-eu / CDMConnector

A pipe friendly way to interact with an OMOP Common Data Model
https://darwin-eu.github.io/CDMConnector/
Apache License 2.0
12 stars 9 forks source link

DatabaseConnector connections fail when used with CDMConnector #10

Open Gaelle-R opened 9 months ago

Gaelle-R commented 9 months ago

Hello !

I'm using the package CDMConnector in the context of CDMOnboarding and DrugExposureDiagnostics packages, and I always get the following error that I don't understand with cdm_from_con() method :

error

I'm using R version : 4.1.0.

Thanks for your help !

ablack3 commented 9 months ago

Hi @Gaelle-R,

Thanks for the error report. The package currently does not support DatabaseConnector as a driver although I'd like to add that. It works sometimes for some database but I have not fully tested it. I'll work on it.

In the meantime would you try connecting with the RPostgres package instead?

Your connection would look something like this.

con <- DBI::dbConnect(RPostgres::Postgres(),
                      dbname = Sys.getenv("CDM5_POSTGRESQL_DBNAME"),
                      host = Sys.getenv("CDM5_POSTGRESQL_HOST"),
                      user = Sys.getenv("CDM5_POSTGRESQL_USER"),
                      password = Sys.getenv("CDM5_POSTGRESQL_PASSWORD"))

cdm <- cdm_from_con(con, cdm_schema = Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA"))
DBI::dbDisconnect(con)
Gaelle-R commented 9 months ago

Hi @ablack3,

Thanks for your reply, it works fine with RPostgres !

siirsu commented 9 months ago

Hello @ablack3,

I would like to test the IncidencePrevalence package and encountered a similar problem described above when attempting to use DatabaseConnector. I see in the thread that the package currently does not support DatabaseConnector, do you have any timelines on when do you think this can be added? I am working with Snowflake and installing ODBC drivers as a workaround for using the DBI connection does not seem to work. Do you have any recommendations for my case to be able to use this package?

Thank you in advance :)

ablack3 commented 6 months ago

So you would like to used DatabaseConnector + CDMConnector on a spark database correct? I can try to add this for the next release in the next month or two.

rfherrerac commented 1 month ago

@ablack3 Hi Adam, I was trying to use IncidencePrevalence in Snowflake using DatabaseConnector. But I got this error: Error in CDMConnector::datediff(): , do you have a work around way?

Backtrace: ▆

  1. ├─DrugUtilisation::generateDrugUtilisationCohortSet(...)
  2. │ ├─DrugUtilisation:::applyLimit(...)
  3. │ │ └─DrugUtilisation:::sumcounts(cohort)
  4. │ │ ├─dplyr::pull(cohortCount(cohort), "number_records")
  5. │ │ └─omopgenerics::cohortCount(cohort)
  6. │ │ └─omopgenerics:::assertClass(cohort, "cohort_table")
  7. │ │ ├─base::paste0(...)
  8. │ │ └─base::paste0(base::class(x), collapse = ", ")
  9. │ ├─DrugUtilisation:::trimEndDate(...)
    1. │ │ └─DrugUtilisation:::sumcounts(cohort)
    2. │ │ ├─dplyr::pull(cohortCount(cohort), "number_records")
    3. │ │ └─omopgenerics::cohortCount(cohort)
    4. │ │ └─omopgenerics:::assertClass(cohort, "cohort_table")
    5. │ │ ├─base::paste0(...)
    6. │ │ └─base::paste0(base::class(x), collapse = ", ")
    7. │ ├─DrugUtilisation:::trimStartDate(...)
    8. │ │ └─DrugUtilisation:::sumcounts(cohort)
    9. │ │ ├─dplyr::pull(cohortCount(cohort), "number_records")
    10. │ │ └─omopgenerics::cohortCount(cohort)
    11. │ │ └─omopgenerics:::assertClass(cohort, "cohort_table")
    12. │ │ ├─base::paste0(...)
    13. │ │ └─base::paste0(base::class(x), collapse = ", ")
    14. │ ├─DrugUtilisation:::requirePriorObservation(...)
    15. │ │ └─DrugUtilisation:::sumcounts(cohort)
    16. │ │ ├─dplyr::pull(cohortCount(cohort), "number_records")
    17. │ │ └─omopgenerics::cohortCount(cohort)
    18. │ │ └─omopgenerics:::assertClass(cohort, "cohort_table")
    19. │ │ ├─base::paste0(...)
    20. │ │ └─base::paste0(base::class(x), collapse = ", ")
    21. │ ├─DrugUtilisation:::requirePriorUseWashout(...)
    22. │ │ └─DrugUtilisation:::sumcounts(cohort)
    23. │ │ ├─dplyr::pull(cohortCount(cohort), "number_records")
    24. │ │ └─omopgenerics::cohortCount(cohort)
    25. │ │ └─omopgenerics:::assertClass(cohort, "cohort_table")
    26. │ │ ├─base::paste0(...)
    27. │ │ └─base::paste0(base::class(x), collapse = ", ")
    28. │ ├─DrugUtilisation:::erafyCohort(...)
    29. │ │ └─DrugUtilisation:::sumcounts(cohort)
    30. │ │ ├─dplyr::pull(cohortCount(cohort), "number_records")
    31. │ │ └─omopgenerics::cohortCount(cohort)
    32. │ │ └─omopgenerics:::assertClass(cohort, "cohort_table")
    33. │ │ ├─base::paste0(...)
    34. │ │ └─base::paste0(base::class(x), collapse = ", ")
    35. │ ├─omopgenerics::newCohortTable(...)
    36. │ │ └─omopgenerics:::assertClass(table, "cdm_table")
    37. │ │ ├─base::paste0(...)
    38. │ │ └─base::paste0(base::class(x), collapse = ", ")
    39. │ └─DrugUtilisation:::subsetTables(...)
    40. │ ├─dplyr::compute(...)
    41. │ ├─... %>% ...
    42. │ ├─dplyr::filter(...)
    43. │ └─PatientProfiles::addDemographics(cohort, sex = FALSE, age = FALSE)
    44. │ └─x %>% dplyr::compute()
    45. ├─dplyr::select(...)
    46. ├─dplyr::mutate(...)
    47. ├─dplyr::mutate(...)
    48. ├─dplyr::compute(.)
    49. ├─omopgenerics:::compute.cdm_table(.)
    50. │ ├─dplyr::compute(...)
    51. │ └─CDMConnector:::compute.db_cdm(...)
    52. │ └─CDMConnector:::.computeQuery(...)
    53. │ └─dbplyr::sql_render(x)
    54. │ ├─dbplyr::sql_render(...)
    55. │ └─dbplyr:::sql_render.tbl_lazy(...)
    56. │ ├─dbplyr::sql_render(...)
    57. │ └─dbplyr:::sql_render.lazy_query(...)
    58. │ ├─dbplyr::sql_build(query, con = con, sql_options = sql_options)
    59. │ └─dbplyr:::sql_build.lazy_select_query(query, con = con, sql_options = sql_options)
    60. │ └─dbplyr:::get_select_sql(...)
    61. │ └─dbplyr:::translate_select_sql(con, select)
    62. │ └─dbplyr::translatesql(...)
    63. │ └─base::lapply(...)
    64. │ └─dbplyr (local) FUN(X[[i]], ...)
    65. │ ├─dbplyr::escape(eval_tidy(x, mask), con = con)
    66. │ └─rlang::eval_tidy(x, mask)
    67. └─CDMConnector::datediff Run rlang::last_trace(drop = FALSE) to see 2 hidden frames.
ablack3 commented 1 month ago

@rfherrerac,

You can try using odbc instead of DatabaseConnector. I'm working on getting DatabaseConnector working with IncidencePrevalence but until that is done you can try using the odbc driver. It should work.