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

Dbplyr2 #293

Draft
wants to merge 20 commits into
base: develop
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: DatabaseConnector
Type: Package
Title: Connecting to Various Database Platforms
Version: 6.3.3
Version: 6.3.3.9000
Date: 2024-06-13
Authors@R: c(
person("Martijn", "Schuemie", email = "[email protected]", role = c("aut", "cre")),
Expand Down Expand Up @@ -54,6 +54,6 @@ VignetteBuilder: knitr
URL: https://ohdsi.github.io/DatabaseConnector/, https://github.com/OHDSI/DatabaseConnector
BugReports: https://github.com/OHDSI/DatabaseConnector/issues
Copyright: See file COPYRIGHTS
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
Encoding: UTF-8
11 changes: 4 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(dbplyr_edition,DatabaseConnectorConnection)
S3method(disconnect,DatabaseConnectorDbiConnection)
S3method(disconnect,default)
S3method(insertTable,DatabaseConnectorDbiConnection)
Expand All @@ -12,22 +13,18 @@ S3method(lowLevelQuerySqlToAndromeda,DatabaseConnectorDbiConnection)
S3method(lowLevelQuerySqlToAndromeda,default)
S3method(renderTranslateQueryApplyBatched,DatabaseConnectorDbiConnection)
S3method(renderTranslateQueryApplyBatched,default)
S3method(sql_translation,DatabaseConnectorJdbcConnection)
export(DatabaseConnectorDriver)
export(assertTempEmulationSchemaSet)
export(computeDataHash)
export(connect)
export(createConnectionDetails)
export(createDbiConnectionDetails)
export(createZipFile)
export(dateAdd)
export(dateDiff)
export(dateFromParts)
export(day)
export(dbms)
export(disconnect)
export(downloadJdbcDrivers)
export(dropEmulatedTempTables)
export(eoMonth)
export(executeSql)
export(existsTable)
export(extractQueryTimes)
Expand All @@ -39,15 +36,13 @@ export(isSqlReservedWord)
export(lowLevelExecuteSql)
export(lowLevelQuerySql)
export(lowLevelQuerySqlToAndromeda)
export(month)
export(querySql)
export(querySqlToAndromeda)
export(renderTranslateExecuteSql)
export(renderTranslateQueryApplyBatched)
export(renderTranslateQuerySql)
export(renderTranslateQuerySqlToAndromeda)
export(requiresTempEmulation)
export(year)
exportClasses(DatabaseConnectorDbiResult)
exportClasses(DatabaseConnectorDriver)
exportClasses(DatabaseConnectorJdbcResult)
Expand Down Expand Up @@ -81,6 +76,8 @@ import(DBI)
import(methods)
import(rJava)
importFrom(bit64,integer64)
importFrom(dbplyr,dbplyr_edition)
importFrom(dbplyr,sql_translation)
importFrom(rlang,abort)
importFrom(rlang,inform)
importFrom(rlang,warn)
Expand Down
8 changes: 0 additions & 8 deletions R/Andromeda.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ renderTranslateQuerySqlToAndromeda <- function(connection,
),
snakeCaseToCamelCase = FALSE,
appendToTable = FALSE,
oracleTempSchema = NULL,
tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"),
integerAsNumeric = getOption("databaseConnectorIntegerAsNumeric",
default = TRUE
Expand All @@ -337,13 +336,6 @@ renderTranslateQuerySqlToAndromeda <- function(connection,
connection <- pool::poolCheckout(connection)
on.exit(pool::poolReturn(connection))
}
if (!is.null(oracleTempSchema) && oracleTempSchema != "") {
warn("The 'oracleTempSchema' argument is deprecated. Use 'tempEmulationSchema' instead.",
.frequency = "regularly",
.frequency_id = "oracleTempSchema"
)
tempEmulationSchema <- oracleTempSchema
}
sql <- SqlRender::render(sql, ...)
sql <- SqlRender::translate(sql,
targetDialect = dbms(connection),
Expand Down
139 changes: 2 additions & 137 deletions R/Connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@
checkIfDbmsIsSupported <- function(dbms) {
supportedDbmss <- c(
"oracle",
"hive",
"postgresql",
"redshift",
"sql server",
"pdw",
"netezza",
"impala",
"bigquery",
"sqlite",
"sqlite extended",
Expand Down Expand Up @@ -312,20 +308,14 @@ connectUsingJdbc <- function(connectionDetails) {
connectionDetails$pathToDriver <- path.expand(connectionDetails$pathToDriver)
checkPathToDriver(connectionDetails$pathToDriver, dbms)

if (dbms == "sql server" || dbms == "synapse" || dbms == "pdw") {
if (dbms == "sql server") {
return(connectSqlServer(connectionDetails))
} else if (dbms == "oracle") {
return(connectOracle(connectionDetails))
} else if (dbms == "postgresql") {
return(connectPostgreSql(connectionDetails))
} else if (dbms == "redshift") {
return(connectRedShift(connectionDetails))
} else if (dbms == "netezza") {
return(connectNetezza(connectionDetails))
} else if (dbms == "impala") {
return(connectImpala(connectionDetails))
} else if (dbms == "hive") {
return(connectHive(connectionDetails))
} else if (dbms == "bigquery") {
return(connectBigQuery(connectionDetails))
} else if (dbms == "spark") {
Expand Down Expand Up @@ -544,94 +534,6 @@ connectRedShift <- function(connectionDetails) {
return(connection)
}

connectNetezza <- function(connectionDetails) {
inform("Connecting using Netezza driver")
jarPath <- findPathToJar("^nzjdbc\\.jar$", connectionDetails$pathToDriver)
driver <- getJbcDriverSingleton("org.netezza.Driver", jarPath)
if (is.null(connectionDetails$connectionString()) || connectionDetails$connectionString() == "") {
if (!grepl("/", connectionDetails$server())) {
abort("Error: database name not included in server string but is required for Redshift Please specify server as <host>/<database>")
}
parts <- unlist(strsplit(connectionDetails$server(), "/"))
host <- parts[1]
database <- parts[2]
if (is.null(connectionDetails$port())) {
port <- "5480"
} else {
port <- connectionDetails$port()
}
connectionString <- paste0("jdbc:netezza://", host, ":", port, "/", database)
if (!is.null(connectionDetails$extraSettings)) {
connectionString <- paste(connectionString, connectionDetails$extraSettings, sep = "?")
}
} else {
connectionString <- connectionDetails$connectionString()
}
if (is.null(connectionDetails$user())) {
connection <- connectUsingJdbcDriver(driver, connectionString, dbms = connectionDetails$dbms)
} else {
connection <- connectUsingJdbcDriver(driver,
connectionString,
user = connectionDetails$user(),
password = connectionDetails$password(),
dbms = connectionDetails$dbms
)
}
return(connection)
}

connectImpala <- function(connectionDetails) {
inform("Connecting using Impala driver")
jarPath <- findPathToJar("^ImpalaJDBC42\\.jar$", connectionDetails$pathToDriver)
driver <- getJbcDriverSingleton("com.cloudera.impala.jdbc.Driver", jarPath)
if (is.null(connectionDetails$connectionString()) || connectionDetails$connectionString() == "") {
if (is.null(connectionDetails$port())) {
port <- "21050"
} else {
port <- connectionDetails$port()
}
connectionString <- paste0("jdbc:impala://", connectionDetails$server(), ":", port)
if (!is.null(connectionDetails$extraSettings)) {
connectionString <- paste(connectionString, connectionDetails$extraSettings, sep = ";")
}
} else {
connectionString <- connectionDetails$connectionString()
}
if (is.null(connectionDetails$user())) {
connection <- connectUsingJdbcDriver(driver, connectionString, dbms = connectionDetails$dbms)
} else {
connection <- connectUsingJdbcDriver(driver,
connectionString,
user = connectionDetails$user(),
password = connectionDetails$password(),
dbms = connectionDetails$dbms
)
}
return(connection)
}

connectHive <- function(connectionDetails) {
inform("Connecting using Hive driver")
jarPath <- findPathToJar("^hive-jdbc-([.0-9]+-)*standalone\\.jar$", connectionDetails$pathToDriver)
driver <- getJbcDriverSingleton("org.apache.hive.jdbc.HiveDriver", jarPath)

if (is.null(connectionDetails$connectionString()) || connectionDetails$connectionString() == "") {
connectionString <- paste0("jdbc:hive2://", connectionDetails$server(), ":", connectionDetails$port(), "/")
if (!is.null(connectionDetails$extraSettings)) {
connectionString <- paste(connectionString, connectionDetails$extraSettings, sep = ";")
}
} else {
connectionString <- connectionDetails$connectionString()
}
connection <- connectUsingJdbcDriver(driver,
connectionString,
user = connectionDetails$user(),
password = connectionDetails$password(),
dbms = connectionDetails$dbms
)
return(connection)
}

connectBigQuery <- function(connectionDetails) {
inform("Connecting using BigQuery driver")
files <- list.files(path = connectionDetails$pathToDriver, full.names = TRUE)
Expand Down Expand Up @@ -778,14 +680,6 @@ connectUsingJdbcDriver <- function(jdbcDriver,
abort(paste0("Unable to connect JDBC to ", url, " (", rJava::.jcall(x, "S", "getMessage"), ")"))
}
}
ensureDatabaseConnectorConnectionClassExists()
class <- getClassDef("DatabaseConnectorJdbcConnection", where = class_cache, inherits = FALSE)
if (is.null(class) || methods::isVirtualClass(class)) {
setClass("DatabaseConnectorJdbcConnection",
contains = "DatabaseConnectorConnection",
slots = list(jConnection = "jobjRef"),
where = class_cache)
}
connection <- new("DatabaseConnectorJdbcConnection",
jConnection = jConnection,
identifierQuote = "",
Expand All @@ -798,41 +692,12 @@ connectUsingJdbcDriver <- function(jdbcDriver,
return(connection)
}

ensureDatabaseConnectorConnectionClassExists <- function() {
class <- getClassDef("Microsoft SQL Server", where = class_cache, inherits = FALSE)
if (is.null(class) || methods::isVirtualClass(class)) {
setClass("Microsoft SQL Server",
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"),
slots = list(
identifierQuote = "character",
stringQuote = "character",
dbms = "character",
uuid = "character"
),
where = class_cache)
}
}

connectUsingDbi <- function(dbiConnectionDetails) {
dbms <- dbiConnectionDetails$dbms
dbiConnectionDetails$dbms <- NULL
dbiConnection <- do.call(DBI::dbConnect, dbiConnectionDetails)
ensureDatabaseConnectorConnectionClassExists()
class <- getClassDef("DatabaseConnectorDbiConnection", where = class_cache, inherits = FALSE)
if (is.null(class) || methods::isVirtualClass(class)) {
setClass("DatabaseConnectorDbiConnection",
contains = "DatabaseConnectorConnection",
slots = list(
dbiConnection = "DBIConnection",
server = "character"
),
where = class_cache)
}

connection <- new("DatabaseConnectorDbiConnection",
server = dbms,
dbiConnection = dbiConnection,
Expand Down
Loading
Loading