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

Add a helper function for connecting to Redshift #879

Merged
merged 1 commit into from
Feb 7, 2025

Conversation

atheriel
Copy link
Collaborator

This commit introduces a new odbc::redshift() function intended to help setting up connections to AWS Redshift, especially when using IAM credentials. It generally follows the pattern established with odbc::databricks() and odbc::snowflake().

Note that finding IAM credentials is outsourced to paws.common. Some Redshift ODBC drivers (there are a few of them) can handle AWS profiles or IAM role assumption, and I did have an earlier version of this commit that did this work manually; unfortunately the supported parameters depend not only on the driver, but also the driver version, and it quickly became a mess.

So: using paws.common here allows us to be very driver version-agnostic, and ensures we support as wide a number of IAM setups as possible.

Note that I also refectored some of automatic driver discover for Databricks and Snowflake into its own helper utility so we could use the same logic for Redshift, and fixed some grammar issues in their respective error messages.

Unit tests are included.

Part of #878.

@atheriel
Copy link
Collaborator Author

Test failures seem unrelated.

@simonpcouch
Copy link
Collaborator

Yup, failures are unrelated and addressed in #876! No worries there.

@atheriel atheriel force-pushed the redshift-helper-v2 branch 2 times, most recently from 029888d to 2af0891 Compare January 13, 2025 17:54
@tnederlof
Copy link

This seems to work as expected with this code.

library(odbc)

con <- DBI::dbConnect(
  odbc::redshift(),
  region = "us-east-2",
  clusterId = "tn-demo-cluster",
  database = "demo_db",
  dbuser = "tnederlof"
)

dbListTables(con)

I do need to specify the region otherwise, I get this error: Error occurred while trying to connect: ClusterNotFound: Cluster tn-demo-cluster not found.

@atheriel
Copy link
Collaborator Author

Some checks are failing due to #882.

@atheriel atheriel requested a review from simonpcouch February 5, 2025 17:10
Copy link
Collaborator

@simonpcouch simonpcouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stellar. Thanks for making this happen!

unname(val)
}

find_default_driver <- function(paths, fallbacks, label, call = caller_env()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Digging this refactor.

R/driver-redshift.R Outdated Show resolved Hide resolved
This commit introduces a new `odbc::redshift()` function intended to
help setting up connections to AWS Redshift, especially when using IAM
credentials. It generally follows the pattern established with
`odbc::databricks()` and `odbc::snowflake()`.

Note that finding IAM credentials is outsourced to `paws.common`. Some
Redshift ODBC drivers (there are a few of them) can handle AWS profiles
or IAM role assumption, and I did have an earlier version of this commit
that did this work manually; unfortunately the supported parameters
depend not only on the driver, but also the driver version, and it
quickly became a mess.

So: using `paws.common` here allows us to be very driver
version-agnostic, and ensures we support as wide a number of IAM setups
as possible.

Note that I also refectored some of automatic driver discover for
Databricks and Snowflake into its own helper utility so we could use the
same logic for Redshift, and fixed some grammar issues in their
respective error messages.

Unit tests are included.

Signed-off-by: Aaron Jacobs <[email protected]>
@simonpcouch simonpcouch merged commit 38d1054 into main Feb 7, 2025
17 checks passed
@simonpcouch simonpcouch deleted the redshift-helper-v2 branch February 7, 2025 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants