Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethink how dplyr is rendered to sql when using DatabaseConnector #258

Merged
merged 7 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/R_CMD_check_Hades.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,3 @@ jobs:
if: ${{ env.new_version != '' }}
run: |
curl --data "build=true" -X POST https://registry.hub.docker.com/u/ohdsi/broadsea-methodslibrary/trigger/f0b51cec-4027-4781-9383-4b38b42dd4f5/

2 changes: 1 addition & 1 deletion .github/workflows/R_CMD_check_main_weekly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ jobs:
with:
args: 'c("--no-manual", "--as-cran")'
error-on: '"warning"'
check-dir: '"check"'
check-dir: '"check"'
33 changes: 25 additions & 8 deletions R/Connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@
abort(paste0("Unable to connect JDBC to ", url, " (", rJava::.jcall(x, "S", "getMessage"), ")"))
}
}
ensureDatabaseConnectorConnectionClassExists()
ensureDatabaseConnectorConnectionClassExists(dbms)

Check warning on line 781 in R/Connect.R

View check run for this annotation

Codecov / codecov/patch

R/Connect.R#L781

Added line #L781 was not covered by tests
class <- getClassDef("DatabaseConnectorJdbcConnection", where = class_cache, inherits = FALSE)
if (is.null(class) || methods::isVirtualClass(class)) {
setClass("DatabaseConnectorJdbcConnection",
Expand All @@ -798,16 +798,30 @@
return(connection)
}

ensureDatabaseConnectorConnectionClassExists <- function() {
class <- getClassDef("Microsoft SQL Server", where = class_cache, inherits = FALSE)
ensureDatabaseConnectorConnectionClassExists <- function(dbms) {
checkIfDbmsIsSupported(dbms)
dbmsClass <- switch(dbms,
"oracle" = "Oracle",
"postgresql" = "PqConnection",
"redshift" = "RedshiftConnection",
"sql server" = "Microsoft SQL Server",
"bigquery" = "BigQueryConnection",
"sqlite" = "SQLiteConnection",
"sqlite extended" = "SQLiteConnection",
"spark" = "Spark SQL",
"snowflake" = "Snowflake",
"synapse" = "Microsoft SQL Server",
"duckdb" = "duckdb_connection",
"blah")

Check warning on line 815 in R/Connect.R

View check run for this annotation

Codecov / codecov/patch

R/Connect.R#L802-L815

Added lines #L802 - L815 were not covered by tests

class <- getClassDef(dbmsClass, where = class_cache, inherits = FALSE)

Check warning on line 817 in R/Connect.R

View check run for this annotation

Codecov / codecov/patch

R/Connect.R#L817

Added line #L817 was not covered by tests
if (is.null(class) || methods::isVirtualClass(class)) {
setClass("Microsoft SQL Server",
where = class_cache)
setClass(dbmsClass, where = class_cache)

Check warning on line 819 in R/Connect.R

View check run for this annotation

Codecov / codecov/patch

R/Connect.R#L819

Added line #L819 was not covered by tests
}
class <- getClassDef("DatabaseConnectorConnection", where = class_cache, inherits = FALSE)
if (is.null(class) || methods::isVirtualClass(class)) {
setClass("DatabaseConnectorConnection",
contains = c("Microsoft SQL Server", "DBIConnection"),
contains = c(dbmsClass, "DBIConnection"),

Check warning on line 824 in R/Connect.R

View check run for this annotation

Codecov / codecov/patch

R/Connect.R#L824

Added line #L824 was not covered by tests
slots = list(
identifierQuote = "character",
stringQuote = "character",
Expand All @@ -822,7 +836,7 @@
dbms <- dbiConnectionDetails$dbms
dbiConnectionDetails$dbms <- NULL
dbiConnection <- do.call(DBI::dbConnect, dbiConnectionDetails)
ensureDatabaseConnectorConnectionClassExists()
ensureDatabaseConnectorConnectionClassExists(dbms)

Check warning on line 839 in R/Connect.R

View check run for this annotation

Codecov / codecov/patch

R/Connect.R#L839

Added line #L839 was not covered by tests
class <- getClassDef("DatabaseConnectorDbiConnection", where = class_cache, inherits = FALSE)
if (is.null(class) || methods::isVirtualClass(class)) {
setClass("DatabaseConnectorDbiConnection",
Expand Down Expand Up @@ -956,7 +970,10 @@
"RedshiftConnection" = "redshift",
"BigQueryConnection" = "bigquery",
"SQLiteConnection" = "sqlite",
"duckdb_connection" = "duckdb"
"duckdb_connection" = "duckdb",
"Spark Sql" = "spark",
"Snowflake" = "snowflake",
"Oracle" = "oracle"

Check warning on line 976 in R/Connect.R

View check run for this annotation

Codecov / codecov/patch

R/Connect.R#L973-L976

Added lines #L973 - L976 were not covered by tests
# add mappings from various DBI connection classes to SqlRender dbms here
)
}
14 changes: 8 additions & 6 deletions R/DBI.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ setClass("DatabaseConnectorDbiResult",
setMethod(
"dbSendQuery",
signature("DatabaseConnectorJdbcConnection", "character"),
function(conn, statement, translate = TRUE, ...) {
function(conn, statement, translate = FALSE, ...) {
if (rJava::is.jnull(conn@jConnection)) {
abort("Connection is closed")
}
Expand Down Expand Up @@ -258,7 +258,7 @@ setMethod(
setMethod(
"dbSendQuery",
signature("DatabaseConnectorDbiConnection", "character"),
function(conn, statement, translate = TRUE, ...) {
function(conn, statement, translate = FALSE, ...) {
if (translate) {
statement <- translateStatement(
sql = statement,
Expand Down Expand Up @@ -426,7 +426,7 @@ setMethod("dbGetRowsAffected", "DatabaseConnectorDbiResult", function(res, ...)
setMethod(
"dbGetQuery",
signature("DatabaseConnectorConnection", "character"),
function(conn, statement, translate = TRUE, ...) {
function(conn, statement, translate = FALSE, ...) {
if (translate) {
statement <- translateStatement(
sql = statement,
Expand All @@ -447,7 +447,7 @@ setMethod(
setMethod(
"dbSendStatement",
signature("DatabaseConnectorConnection", "character"),
function(conn, statement, translate = TRUE, ...) {
function(conn, statement, translate = FALSE, ...) {
if (translate) {
statement <- translateStatement(
sql = statement,
Expand All @@ -472,7 +472,7 @@ setMethod(
setMethod(
"dbExecute",
signature("DatabaseConnectorConnection", "character"),
function(conn, statement, translate = TRUE, ...) {
function(conn, statement, translate = FALSE, ...) {
if (isDbplyrSql(statement) && dbms(conn) %in% c("oracle", "bigquery", "spark", "hive") && grepl("^UPDATE STATISTICS", statement)) {
# These platforms don't support this, so SqlRender translates to an empty string, which causes errors down the line.
return(0)
Expand Down Expand Up @@ -544,7 +544,9 @@ setMethod(
#' @export
setMethod(
"dbWriteTable",
"DatabaseConnectorConnection",
c(conn = "DatabaseConnectorConnection",
name = "character",
value = "data.frame"),
function(conn,
name, value, databaseSchema = NULL, overwrite = FALSE, append = FALSE, temporary = FALSE, oracleTempSchema = NULL, tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), ...) {
if (!is.null(oracleTempSchema) && oracleTempSchema != "") {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbClearResult-DatabaseConnectorDbiResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbClearResult-DatabaseConnectorJdbcResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbColumnInfo-DatabaseConnectorDbiResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbColumnInfo-DatabaseConnectorJdbcResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbCreateTable-DatabaseConnectorConnection-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbDisconnect-DatabaseConnectorConnection-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbFetch-DatabaseConnectorDbiResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbFetch-DatabaseConnectorJdbcResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbGetInfo-DatabaseConnectorConnection-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbGetInfo-DatabaseConnectorDriver-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbGetRowCount-DatabaseConnectorDbiResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbGetRowCount-DatabaseConnectorJdbcResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbGetRowsAffected-DatabaseConnectorDbiResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbGetStatement-DatabaseConnectorDbiResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbGetStatement-DatabaseConnectorJdbcResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbHasCompleted-DatabaseConnectorDbiResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbHasCompleted-DatabaseConnectorJdbcResult-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbIsValid-DatabaseConnectorDbiConnection-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbIsValid-DatabaseConnectorJdbcConnection-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dbListTables-DatabaseConnectorConnection-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading