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.

141 lines
3.3 KiB

7 years ago
---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
7 years ago
---
5 years ago
```{r include=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
message = FALSE,
warning = FALSE,
fig.retina = 2
)
Sys.setenv(
AWS_S3_STAGING_DIR = "s3://aws-athena-query-results-569593279821-us-east-1"
)
options(width=120)
```
6 years ago
5 years ago
[![Travis-CI Build Status](https://travis-ci.org/hrbrmstr/metis.svg?branch=master)](https://travis-ci.org/hrbrmstr/metis)
[![Coverage Status](https://codecov.io/gh/hrbrmstr/metis/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/metis
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/metis)](https://cran.r-project.org/package=metis)
# metis
7 years ago
Access and Query Amazon Athena via DBI/JDBC
7 years ago
6 years ago
## Description
5 years ago
In Greek mythology, Metis was Athena's "helper" so...
7 years ago
5 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.
5 years ago
6 years ago
## What's Inside The Tin?
7 years ago
The following functions are implemented:
6 years ago
Easy-interface connection helper:
- `athena_connect` Simplified Athena JDBC connection helper
6 years ago
Custom JDBC Classes:
- `Athena`: AthenaJDBC (make a new Athena con obj)
7 years ago
- `AthenaConnection-class`: AthenaJDBC
- `AthenaDriver-class`: AthenaJDBC
- `AthenaResult-class`: AthenaJDBC
6 years ago
Custom JDBC Class Methods:
- `dbConnect-method`
- `dbExistsTable-method`
- `dbGetQuery-method`
- `dbListFields-method`
- `dbListTables-method`
- `dbReadTable-method`
- `dbSendQuery-method`
7 years ago
6 years ago
Pulled in from other `cloudyr` pkgs:
6 years ago
- `read_credentials`: Use Credentials from .aws/credentials File
- `use_credentials`: Use Credentials from .aws/credentials File
6 years ago
## Installation
7 years ago
```{r eval=FALSE}
5 years ago
devtools::install_git("https://git.sr.ht/~hrbrmstr/metis")
# OR
5 years ago
devtools::install_gitlab("hrbrmstr/metis")
# OR
5 years ago
devtools::install_github("hrbrmstr/metis")
7 years ago
```
6 years ago
## Usage
7 years ago
5 years ago
```{r}
5 years ago
library(metis)
7 years ago
# current verison
5 years ago
packageVersion("metis")
7 years ago
```
5 years ago
```{r cache=FALSE}
library(rJava)
library(RJDBC)
5 years ago
library(metis)
5 years ago
library(magrittr) # for piping b/c I'm addicted
```
5 years ago
```{r}
dbConnect(
5 years ago
metis::Athena(),
Schema = "sampledb",
AwsCredentialsProviderClass = "com.simba.athena.amazonaws.auth.PropertiesFileCredentialsProvider",
AwsCredentialsProviderArguments = path.expand("~/.aws/athenaCredentials.props")
) -> con
dbListTables(con, schema="sampledb")
6 years ago
dbExistsTable(con, "elb_logs", schema="sampledb")
6 years ago
dbListFields(con, "elb_logs", "sampledb")
dbGetQuery(con, "SELECT * FROM sampledb.elb_logs LIMIT 10") %>%
5 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
") %>%
5 years ago
dplyr::glimpse()
```
5 years ago
```{r cloc}
cloc::cloc_pkg_md()
7 years ago
```
6 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.