---
output: rmarkdown::github_document
---

[`metis`](https://en.wikipedia.org/wiki/Metis_(mythology)) : Helpers for Accessing and Querying Amazon Athena

Including a lightweight RJDBC shim.

![](https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Winged_goddess_Louvre_F32.jpg/300px-Winged_goddess_Louvre_F32.jpg)

THIS IS SUPER ALPHA QUALITY. NOTHING TO SEE HERE. MOVE ALONG.

The goal will be to get around enough of the "gotchas" that are preventing raw RJDBC Athena
connections from "just working" with `dplyr` v0.6.0+ and also get around the [`fetchSize` problem](https://www.reddit.com/r/aws/comments/6aq22b/fetchsize_limit/) without having to not use `dbGetQuery()`.

It will also support more than the vanilla id/secret auth mechism (it currently support the default basic auth and temp token auth, the latter via environment variables).

This package includes the `AthenaJDBC41-1.1.0.jar` JAR file out of convenience but that will likely move to a separate package as this gets closer to prime time.

See the **Usage** section for an example.

The following functions are implemented:

- `athena_connect`:	Make a JDBC connection to Athena (this returns an `AthenaConnection` object which is a super-class of it's RJDBC vanilla counterpart)
- `read_credentials`:	Use Credentials from .aws/credentials File
- `use_credentials`:	Use Credentials from .aws/credentials File
- `Athena`:	AthenaJDBC`
- `AthenaConnection-class`:	AthenaJDBC
- `AthenaDriver-class`:	AthenaJDBC
- `AthenaResult-class`:	AthenaJDBC
- `dbConnect-method`:	AthenaJDBC
- `dbGetQuery-method`:	AthenaJDBC
- `dbSendQuery-method`:	AthenaJDBC

### Installation

```{r eval=FALSE}
devtools::install_github("hrbrmstr/metis")
```

```{r message=FALSE, warning=FALSE, error=FALSE, include=FALSE}
options(width=120)
```

### Usage

```{r message=FALSE, warning=FALSE, error=FALSE}
library(metis)
library(tidyverse)

# current verison
packageVersion("metis")
```

```{r message=FALSE, warning=FALSE, error=FALSE}
use_credentials("personal")

ath <- athena_connect(default_schema = "sampledb", 
                      s3_staging_dir = "s3://accessible-bucket",
                      log_path = "/tmp/athena.log",
                      log_level = "DEBUG")

dbListTables(ath)

dbGetQuery(ath, "SELECT * FROM sampledb.elb_logs LIMIT 10") %>% 
  type_convert() %>% 
  glimpse()
```
