Skip to content

Commit

Permalink
fix merge confict
Browse files Browse the repository at this point in the history
  • Loading branch information
ablack3 committed Jun 25, 2024
2 parents 0983717 + 5169a00 commit f94e817
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 37 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/R_CMD_check_Hades.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ jobs:
fail-fast: false
matrix:
config:
<<<<<<< HEAD
# - {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
# - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
=======
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
>>>>>>> 5169a00ba285048383752184cba4e379d59ba801

env:
GITHUB_PAT: ${{ secrets.GH_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
CDM5_ORACLE_CDM54_SCHEMA: ${{ secrets.CDM5_ORACLE_CDM54_SCHEMA }}
Expand Down Expand Up @@ -65,6 +70,13 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Setup Java
if: runner.os != 'Linux'
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '8'

- uses: r-lib/actions/setup-r@v2
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/R_CMD_check_main_weekly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '8'

- uses: r-lib/actions/setup-r@v2
with:
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: DatabaseConnector
Type: Package
Title: Connecting to Various Database Platforms
Version: 6.3.2
Date: 2023-12-11
Version: 6.3.3
Date: 2024-06-13
Authors@R: c(
person("Martijn", "Schuemie", email = "schuemie@ohdsi.org", role = c("aut", "cre")),
person("Marc", "Suchard", role = c("aut")),
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.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
Encoding: UTF-8
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
DatabaseConnector 6.3.3
=======================

Changes:

- Updated Snowflake driver to 3.16.1.

- Updated Databricks driver to 2.6.36.


DatabaseConnector 6.3.2
=======================

Expand Down
59 changes: 35 additions & 24 deletions R/Drivers.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ jdbcDrivers <- new.env()
#' - RedShift: V2.1.0.9
#' - SQL Server: V9.2.0
#' - Oracle: V19.8
#' - Spark: V2.6.21
#' - Snowflake: V3.13.22
#' - Spark (Databricks): V2.6.36
#' - Snowflake: V3.16.01
#' - BigQuery: v1.3.2.1003
#'
#' @return Invisibly returns the destination if the download was successful.
Expand All @@ -60,7 +60,7 @@ downloadJdbcDrivers <- function(dbms, pathToDriver = Sys.getenv("DATABASECONNECT
if (is.null(pathToDriver) || is.na(pathToDriver) || pathToDriver == "") {
abort("The pathToDriver argument must be specified. Consider setting the DATABASECONNECTOR_JAR_FOLDER environment variable, for example in the .Renviron file.")
}

if (pathToDriver != Sys.getenv("DATABASECONNECTOR_JAR_FOLDER")) {
if (Sys.getenv("DATABASECONNECTOR_JAR_FOLDER") != pathToDriver) {
inform(paste0(
Expand All @@ -71,31 +71,31 @@ downloadJdbcDrivers <- function(dbms, pathToDriver = Sys.getenv("DATABASECONNECT
))
}
}

pathToDriver <- path.expand(pathToDriver)

if (!dir.exists(pathToDriver)) {
if (file.exists(pathToDriver)) {
abort(paste0("The folder location pathToDriver = '", pathToDriver, "' points to a file, but should point to a folder."))
}
warn(paste0("The folder location '", pathToDriver, "' does not exist. Attempting to create."))
dir.create(pathToDriver, recursive = TRUE)
}

stopifnot(is.character(dbms), length(dbms) == 1, dbms %in% c("all", "postgresql", "redshift", "sql server", "oracle", "pdw", "snowflake", "spark", "bigquery"))

if (dbms == "pdw" || dbms == "synapse") {
dbms <- "sql server"
}

jdbcDriverSources <- utils::read.csv(text =
"row,dbms, fileName, baseUrl
"row,dbms, fileName, baseUrl
1,postgresql,postgresqlV42.2.18.zip,https://ohdsi.github.io/DatabaseConnectorJars/
2,redshift,redshift-jdbc42-2.1.0.20.zip,https://s3.amazonaws.com/redshift-downloads/drivers/jdbc/2.1.0.20/
3,sql server,sqlServerV9.2.0.zip,https://ohdsi.github.io/DatabaseConnectorJars/
4,oracle,oracleV19.8.zip,https://ohdsi.github.io/DatabaseConnectorJars/
5,spark,DatabricksJDBC42-2.6.32.1054.zip,https://databricks-bi-artifacts.s3.us-east-2.amazonaws.com/simbaspark-drivers/jdbc/2.6.32/
6,snowflake,SnowflakeV3.13.22.zip,https://ohdsi.github.io/DatabaseConnectorJars/
5,spark,DatabricksJDBC42-2.6.36.1062.zip,https://databricks-bi-artifacts.s3.us-east-2.amazonaws.com/simbaspark-drivers/jdbc/2.6.36/
6,snowflake,snowflake-jdbc-3.16.1.jar,https://repo1.maven.org/maven2/net/snowflake/snowflake-jdbc/3.16.1/
7,bigquery,SimbaBigQueryJDBC42-1.3.2.1003.zip,https://storage.googleapis.com/simba-bq-release/jdbc/"
)
if (dbms == "all") {
Expand All @@ -112,26 +112,37 @@ downloadJdbcDrivers <- function(dbms, pathToDriver = Sys.getenv("DATABASECONNECT
}
}
driverSource <- jdbcDriverSources[jdbcDriverSources$dbms == db, ]

result <- download.file(
url = paste0(driverSource$baseUrl, driverSource$fileName),
destfile = file.path(pathToDriver, driverSource$fileName),
method = method
)

extractedFilename <- unzip(file.path(pathToDriver, driverSource$fileName), exdir = pathToDriver)
unzipSuccess <- is.character(extractedFilename)

if (unzipSuccess) {
file.remove(file.path(pathToDriver, driverSource$fileName))
if (grepl("\\.zip$", driverSource$fileName)) {
# Zip file. Download and unzip
result <- download.file(
url = paste0(driverSource$baseUrl, driverSource$fileName),
destfile = file.path(pathToDriver, driverSource$fileName),
method = method
)

extractedFilename <- unzip(file.path(pathToDriver, driverSource$fileName),
exdir = pathToDriver,
junkpaths = TRUE)
unzipSuccess <- is.character(extractedFilename)

if (unzipSuccess) {
file.remove(file.path(pathToDriver, driverSource$fileName))
}
} else {
# Jar file. Download directly to jar folder
unzipSuccess <- TRUE
result <- download.file(
url = paste0(driverSource$baseUrl, driverSource$fileName),
destfile = file.path(pathToDriver, driverSource$fileName),
method = method
)
}
if (unzipSuccess && result == 0) {
inform(paste0("DatabaseConnector ", db, " JDBC driver downloaded to '", pathToDriver, "'."))
} else {
abort(paste0("Downloading and unzipping of ", db, " JDBC driver to '", pathToDriver, "' has failed."))
}
}
}

invisible(pathToDriver)
}

Expand Down
15 changes: 8 additions & 7 deletions tests/testthat/dbplyrTestFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,14 @@ testDbplyrFunctions <- function(connectionDetails, cdmDatabaseSchema) {
collect()
expect_gt(personTwice$n, 1)

tripleJoin <- person %>%
left_join(observationPeriod, by = join_by(person_id)) %>%
left_join(observationPeriod %>%
select(person_id, dummy = observation_period_start_date),
by = join_by(person_id)) %>%
collect()
expect_gt(nrow(tripleJoin), 0)
# Skipping until DatabaseConnector 7 or a new dbplyr version. See #271
# tripleJoin <- person %>%
# left_join(observationPeriod, by = join_by(person_id)) %>%
# left_join(observationPeriod %>%
# select(person_id, dummy = observation_period_start_date),
# by = join_by(person_id)) %>%
# collect()
# expect_gt(nrow(tripleJoin), 0)

# Test row_number ------------------------------------------------------------
top10PersonsHardWay <- person %>%
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ if (Sys.getenv("DONT_DOWNLOAD_JDBC_DRIVERS", "") != "TRUE") {
downloadJdbcDrivers("redshift")
downloadJdbcDrivers("spark")
downloadJdbcDrivers("snowflake")
downloadJdbcDrivers("bigquery")
if (.Platform$OS.type == "windows") {
downloadJdbcDrivers("bigquery")
}

if (testthat::is_testing()) {
withr::defer({
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-fetchResults.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test_that("Logging query times", {
skip_if_not_installed("ParallelLogger")

queryTimes <- extractQueryTimes(logFileName)
expect_gt(nrow(queryTimes), 16)
expect_gt(nrow(queryTimes), 3)
ParallelLogger::unregisterLogger("TEST_LOGGER")
unlink(logFileName)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-insertTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ test_that("Logging insertTable times", {
skip_if_not_installed("ParallelLogger")
log <- readLines(logFileName)
insertCount <- sum(grepl("Inserting [0-9]+ rows", log))
expect_gt(insertCount, 4)
expect_gt(insertCount, 0)
# writeLines(log)
ParallelLogger::unregisterLogger("TEST_LOGGER")
unlink(logFileName)
Expand Down
42 changes: 42 additions & 0 deletions vignettes/Connecting.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,45 @@ querySql(conn, "SELECT COUNT(*) FROM main.cars;")
disconnect(conn)
```

# Connecting with Windows authentication from a non-windows machine

Kerberos is used by Active Directory, you need to have the appropriate packages installed on your client machine. For MacOS, the Kerberos packages are usually already installed. On Linux, you’ll have to install `krb5-user`. Most of this setup comes from [this site](https://github.com/Microsoft/vscode-mssql/wiki/How-to-enable-Integrated-Authentication-on-macOS-and-Linux-using-Kerberos).

1. On the non-windows client machine, create or update `/etc/krb5.conf` so that it points to your AD server. Here’s an example of `krb5.conf`:

```
[libdefaults]
default_realm = DOMAIN.COMPANY.COM
[realms]
DOMAIN.COMPANY.COM = {
kdc = dc-33.domain.company.com
}
```

2. Run `kinit <username>@DOMAIN.COMPANY.COM` to get a ticket granting ticket from the kerberos domain controller (KDC). (NOTE: you want to make sure your KDC is accessible from your machine)

3. Download the latest [MSSql JDBC driver](https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15).

4. Try to connect to the database with the following code in RStudio:

```{r eval=FALSE}
library(devtools)
library(DatabaseConnector)
connectionDetails <- createConnectionDetails(
dbms="sql server",
...
extraSettings="authenticationScheme=JavaKerberos")
c <- connect(connectionDetails = connectionDetails)
```
In RStudio, you should see that the variable c has a value and the new connection in the connections tab as well.

Note: If you are getting the below error on Mac:

> Error in rJava::.jcall(jdbcDriver, "Ljava/sql/Connection;", "connect", : com.microsoft.sqlserver.jdbc.SQLServerException: Kerberos Login failed: Integrated authentication failed. ClientConnectionId:13fb0d4e-4822-4de2-a125-8408334cb3ed due to javax.security.auth.login.LoginException (Cannot get any of properties: [user, USER] from con properties not available to garner authentication information from the user)
Instead of kinit you can also try `/System/Library/CoreServices` and find 'Ticket Viewer'
Click 'Add Identity', then enter your user name.
After you click 'Continue', a Kerberos ticket should have been generated.

0 comments on commit f94e817

Please sign in to comment.