Access and Query Amazon Athena via DBI/JDBC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
2.9 KiB

6 years ago
---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
6 years ago
---
5 years ago
# metis
6 years ago
Access and Query Amazon Athena via DBI/JDBC
6 years ago
5 years ago
## Description
4 years ago
In Greek mythology, Metis was Athena's "helper" so...
6 years ago
4 years ago
Methods are provided to connect to 'Amazon' 'Athena', lookup schemas/tables,
perform queries and retrieve query results via the included JDBC DBI driver.
4 years ago
5 years ago
## What's Inside The Tin?
6 years ago
The following functions are implemented:
5 years ago
Easy-interface connection helper:
- `athena_connect` Simplified Athena JDBC connection helper
5 years ago
Custom JDBC Classes:
- `Athena`: AthenaJDBC (make a new Athena con obj)
6 years ago
- `AthenaConnection-class`: AthenaJDBC
- `AthenaDriver-class`: AthenaJDBC
- `AthenaResult-class`: AthenaJDBC
5 years ago
Custom JDBC Class Methods:
- `dbConnect-method`
- `dbExistsTable-method`
- `dbGetQuery-method`
- `dbListFields-method`
- `dbListTables-method`
- `dbReadTable-method`
- `dbSendQuery-method`
6 years ago
5 years ago
Pulled in from other `cloudyr` pkgs:
5 years ago
- `read_credentials`: Use Credentials from .aws/credentials File
- `use_credentials`: Use Credentials from .aws/credentials File
5 years ago
## Installation
6 years ago
```{r eval=FALSE}
4 years ago
devtools::install_git("https://git.sr.ht/~hrbrmstr/metis")
# OR
4 years ago
devtools::install_gitlab("hrbrmstr/metis")
# OR
4 years ago
devtools::install_github("hrbrmstr/metis")
6 years ago
```
```{r message=FALSE, warning=FALSE, include=FALSE}
6 years ago
options(width=120)
```
5 years ago
## Usage
6 years ago
```{r message=FALSE, warning=FALSE}
4 years ago
library(metis)
6 years ago
# current verison
4 years ago
packageVersion("metis")
6 years ago
```
```{r message=FALSE, warning=FALSE}
library(rJava)
library(RJDBC)
4 years ago
library(metis)
library(magrittr)
dbConnect(
4 years ago
drv = metis::Athena(),
schema_name = "sampledb",
provider = "com.simba.athena.amazonaws.auth.PropertiesFileCredentialsProvider",
AwsCredentialsProviderArguments = path.expand("~/.aws/athenaCredentials.props"),
s3_staging_dir = "s3://aws-athena-query-results-569593279821-us-east-1",
) -> con
dbListTables(con, schema="sampledb")
5 years ago
dbExistsTable(con, "elb_logs", schema="sampledb")
5 years ago
dbListFields(con, "elb_logs", "sampledb")
dbGetQuery(con, "SELECT * FROM sampledb.elb_logs LIMIT 10") %>%
4 years ago
dplyr::glimpse()
```
### Check types
```{r}
dbGetQuery(con, "
SELECT
CAST('chr' AS CHAR(4)) achar,
CAST('varchr' AS VARCHAR) avarchr,
CAST(SUBSTR(timestamp, 1, 10) AS DATE) AS tsday,
CAST(100.1 AS DOUBLE) AS justadbl,
CAST(127 AS TINYINT) AS asmallint,
CAST(100 AS INTEGER) AS justanint,
CAST(100000000000000000 AS BIGINT) AS abigint,
CAST(('GET' = 'GET') AS BOOLEAN) AS is_get,
ARRAY[1, 2, 3] AS arr1,
ARRAY['1', '2, 3', '4'] AS arr2,
MAP(ARRAY['foo', 'bar'], ARRAY[1, 2]) AS mp,
CAST(ROW(1, 2.0) AS ROW(x BIGINT, y DOUBLE)) AS rw,
CAST('{\"a\":1}' AS JSON) js
FROM elb_logs
LIMIT 1
") %>%
4 years ago
dplyr::glimpse()
```
4 years ago
```{r cloc}
cloc::cloc_pkg_md()
6 years ago
```
5 years ago
## Code of Conduct
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.