connect_athena: connect_athena

View source: R/athena_connection.R

connect_athenaR Documentation

connect_athena

Description

Creates a connection object which permits the user to interact with the Athena databases that are hosted on the MoJ's Analytical Platform. It uses the noctua package, with the MoJ's authentication. This returns an object with class MoJAthenaConnection, which inherits methods from noctua's AthenaConnection class, which in turn are DBI methods. In general the expected usage is to run the function with no arguments to get a standard database connection, which should work for most basic data access purposes.

Usage

connect_athena(
  aws_region = NULL,
  staging_dir = NULL,
  rstudio_conn_tab = FALSE,
  session_duration = 3600L,
  role_session_name = NULL,
  schema_name = "default",
  ...
)

Arguments

aws_region

This is the region where the database is held. If unset or NULL then will default to the AP's region.

staging_dir

This the s3 location where outputs of queries can be held. If unset or NULL then will default to a session specific temporary dir.

rstudio_conn_tab

Set this to true to show this connection in you RStudio connections frame (warning: this takes a long time to load because of the number of databases in the AP's Athena)

session_duration

The number of seconds which the session should last before needing new authentication. Minimum of 900.

role_session_name

This is a parameter for authentication, and should be left to NULL in normal operation.

schema_name

This is the default database that tables not specifying a database will be looked in. If this is set to the string ⁠__temp__⁠ then it will use (and create if required) the temporary database based on your username - this is useful for using dbplyr which does not understand the ⁠__temp__⁠ keyword, alongside the DBI commands.

...

Other agruments passed to dbConnect

See Also

See also noctua's documentation for connecting to a database noctua::dbConnect,AthenaDriver-method

Examples

 con <- connect_athena() # creates a connection with sensible defaults
 data <- dbGetQuery(con, "SELECT * FROM database.table") # queries and puts data in R environment
 dbDisconnect(con) # disconnects the connection


moj-analytical-services/Rdbtools documentation built on June 22, 2024, 8:46 p.m.