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

Dbplyr backends #262

Closed
wants to merge 6 commits into from
Closed
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
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 @@ connectUsingJdbcDriver <- function(jdbcDriver,
abort(paste0("Unable to connect JDBC to ", url, " (", rJava::.jcall(x, "S", "getMessage"), ")"))
}
}
ensureDatabaseConnectorConnectionClassExists()
ensureDatabaseConnectorConnectionClassExists(dbms)
class <- getClassDef("DatabaseConnectorJdbcConnection", where = class_cache, inherits = FALSE)
if (is.null(class) || methods::isVirtualClass(class)) {
setClass("DatabaseConnectorJdbcConnection",
Expand All @@ -798,16 +798,30 @@ connectUsingJdbcDriver <- function(jdbcDriver,
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")

class <- getClassDef(dbmsClass, where = class_cache, inherits = FALSE)
if (is.null(class) || methods::isVirtualClass(class)) {
setClass("Microsoft SQL Server",
where = class_cache)
setClass(dbmsClass, where = class_cache)
}
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"),
slots = list(
identifierQuote = "character",
stringQuote = "character",
Expand All @@ -822,7 +836,7 @@ connectUsingDbi <- function(dbiConnectionDetails) {
dbms <- dbiConnectionDetails$dbms
dbiConnectionDetails$dbms <- NULL
dbiConnection <- do.call(DBI::dbConnect, dbiConnectionDetails)
ensureDatabaseConnectorConnectionClassExists()
ensureDatabaseConnectorConnectionClassExists(dbms)
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 @@ dbms <- function(connection) {
"RedshiftConnection" = "redshift",
"BigQueryConnection" = "bigquery",
"SQLiteConnection" = "sqlite",
"duckdb_connection" = "duckdb"
"duckdb_connection" = "duckdb",
"Spark Sql" = "spark",
"Snowflake" = "snowflake",
"Oracle" = "oracle"
# 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.

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.

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

Binary file modified tests/testthat/testthat-problems.rds
Binary file not shown.
Loading