Browse Source

README

master
boB Rudis 1 year ago
parent
commit
6d888f1499
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
43 changed files with 531 additions and 1326 deletions
  1. +2
    -1
      .Rbuildignore
  2. +12
    -14
      DESCRIPTION
  3. +0
    -2
      LICENSE
  4. +194
    -21
      LICENSE.md
  5. +6
    -25
      NAMESPACE
  6. +2
    -17
      NEWS.md
  7. +0
    -16
      R/a-utils.R
  8. +0
    -223
      R/jdbc.r
  9. +32
    -0
      R/metis-jars-package.R
  10. +0
    -48
      R/metis-lite-package.R
  11. +0
    -68
      R/metis.r
  12. +15
    -0
      R/metis_jar_path.R
  13. +0
    -124
      R/sql_translate_env.R
  14. +15
    -0
      R/types.R
  15. +8
    -0
      R/version.R
  16. +0
    -121
      R/z-dbGetQuery.R
  17. +20
    -7
      R/zzz.R
  18. +26
    -109
      README.Rmd
  19. +35
    -177
      README.md
  20. +69
    -0
      inst/COPYRIGHTS
  21. +0
    -18
      man/Athena.Rd
  22. +0
    -9
      man/AthenaConnection-class.Rd
  23. +0
    -9
      man/AthenaDriver-class.Rd
  24. +0
    -9
      man/AthenaResult-class.Rd
  25. +0
    -57
      man/athena_connect.Rd
  26. +14
    -0
      man/athena_supported_types.Rd
  27. +0
    -48
      man/dbConnect-AthenaDriver-method.Rd
  28. +0
    -22
      man/dbExistsTable-AthenaConnection-character-method.Rd
  29. +0
    -19
      man/dbGetQuery-AthenaConnection-character-method.Rd
  30. +0
    -22
      man/dbListFields-AthenaConnection-character-method.Rd
  31. +0
    -22
      man/dbListTables-AthenaConnection-method.Rd
  32. +0
    -21
      man/dbReadTable-AthenaConnection-character-method.Rd
  33. +0
    -19
      man/dbSendQuery-AthenaConnection-character-method.Rd
  34. +0
    -24
      man/fetch-AthenaResult-numeric-method.Rd
  35. +35
    -0
      man/metis.jars.Rd
  36. +0
    -35
      man/metis.lite.Rd
  37. +14
    -0
      man/metis_jar_path.Rd
  38. +14
    -0
      man/simba_driver_version.Rd
  39. +0
    -12
      man/use_credentials.Rd
  40. +0
    -0
      metis-jars.Rproj
  41. +7
    -1
      tests/test-all.R
  42. +0
    -6
      tests/testthat/test-metis-lite.R
  43. +11
    -0
      tests/testthat/test-metis.jars.R

+ 2
- 1
.Rbuildignore View File

@@ -8,5 +8,6 @@
^NOTES\.*html$
^\.codecov\.yml$
^README_files$
^doc$
^docs$
^CONDUCT\.md$
^\.bash_profile

+ 12
- 14
DESCRIPTION View File

@@ -1,29 +1,27 @@
Package: metis.lite
Package: metis.jars
Type: Package
Title: Access and Query Amazon Athena via DBI/JDBC
Version: 0.3.0
Date: 2019-02-14
Title: Amazon Athena JDBC Driver Wrapper Supporting the 'metis' Package
Version: 2.0.6
Date: 2019-02-17
Authors@R: c(
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5670-2640"))
)
Maintainer: Bob Rudis <bob@rud.is>
Encoding: UTF-8
Description: Methods are provides to connect to 'Amazon' 'Athena', lookup schemas/tables,
perform queries and retrieve query results. A lightweight 'RJDBC' implementation
is included along with additional helpers for 'dplyr'/'dplyr' suppprt.
Description: Contents of the Amazon Athena JDBC Driver
<https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html>
provided to support functions in the 'metis' package. Version number
reflects the version number of the included 'JAR' file.
SystemRequirements: JDK 1.8+
License: MIT + file LICENSE
License: Apache License (>= 2.0)
Copyright: file inst/COPYRIGHTS
Suggests:
testthat,
covr
Depends:
R (>= 3.2.0),
RJDBC
R (>= 3.2.0)
Imports:
rJava,
DBI,
bit64,
dbplyr,
aws.signature
utils
RoxygenNote: 6.1.1

+ 0
- 2
LICENSE View File

@@ -1,2 +0,0 @@
YEAR: 2019
COPYRIGHT HOLDER: Bob Rudis

+ 194
- 21
LICENSE.md View File

@@ -1,21 +1,194 @@
# MIT License

Copyright (c) 2019 Bob Rudis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Apache License
==============

_Version 2.0, January 2004_
_&lt;<http://www.apache.org/licenses/>&gt;_

### Terms and Conditions for use, reproduction, and distribution

#### 1. Definitions

“License” shall mean the terms and conditions for use, reproduction, and
distribution as defined by Sections 1 through 9 of this document.

“Licensor” shall mean the copyright owner or entity authorized by the copyright
owner that is granting the License.

“Legal Entity” shall mean the union of the acting entity and all other entities
that control, are controlled by, or are under common control with that entity.
For the purposes of this definition, “control” means **(i)** the power, direct or
indirect, to cause the direction or management of such entity, whether by
contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
outstanding shares, or **(iii)** beneficial ownership of such entity.

“You” (or “Your”) shall mean an individual or Legal Entity exercising
permissions granted by this License.

“Source” form shall mean the preferred form for making modifications, including
but not limited to software source code, documentation source, and configuration
files.

“Object” form shall mean any form resulting from mechanical transformation or
translation of a Source form, including but not limited to compiled object code,
generated documentation, and conversions to other media types.

“Work” shall mean the work of authorship, whether in Source or Object form, made
available under the License, as indicated by a copyright notice that is included
in or attached to the work (an example is provided in the Appendix below).

“Derivative Works” shall mean any work, whether in Source or Object form, that
is based on (or derived from) the Work and for which the editorial revisions,
annotations, elaborations, or other modifications represent, as a whole, an
original work of authorship. For the purposes of this License, Derivative Works
shall not include works that remain separable from, or merely link (or bind by
name) to the interfaces of, the Work and Derivative Works thereof.

“Contribution” shall mean any work of authorship, including the original version
of the Work and any modifications or additions to that Work or Derivative Works
thereof, that is intentionally submitted to Licensor for inclusion in the Work
by the copyright owner or by an individual or Legal Entity authorized to submit
on behalf of the copyright owner. For the purposes of this definition,
“submitted” means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems, and
issue tracking systems that are managed by, or on behalf of, the Licensor for
the purpose of discussing and improving the Work, but excluding communication
that is conspicuously marked or otherwise designated in writing by the copyright
owner as “Not a Contribution.”

“Contributor” shall mean Licensor and any individual or Legal Entity on behalf
of whom a Contribution has been received by Licensor and subsequently
incorporated within the Work.

#### 2. Grant of Copyright License

Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the Work and such
Derivative Works in Source or Object form.

#### 3. Grant of Patent License

Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to make, have
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
such license applies only to those patent claims licensable by such Contributor
that are necessarily infringed by their Contribution(s) alone or by combination
of their Contribution(s) with the Work to which such Contribution(s) was
submitted. If You institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
Contribution incorporated within the Work constitutes direct or contributory
patent infringement, then any patent licenses granted to You under this License
for that Work shall terminate as of the date such litigation is filed.

#### 4. Redistribution

You may reproduce and distribute copies of the Work or Derivative Works thereof
in any medium, with or without modifications, and in Source or Object form,
provided that You meet the following conditions:

* **(a)** You must give any other recipients of the Work or Derivative Works a copy of
this License; and
* **(b)** You must cause any modified files to carry prominent notices stating that You
changed the files; and
* **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
all copyright, patent, trademark, and attribution notices from the Source form
of the Work, excluding those notices that do not pertain to any part of the
Derivative Works; and
* **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any
Derivative Works that You distribute must include a readable copy of the
attribution notices contained within such NOTICE file, excluding those notices
that do not pertain to any part of the Derivative Works, in at least one of the
following places: within a NOTICE text file distributed as part of the
Derivative Works; within the Source form or documentation, if provided along
with the Derivative Works; or, within a display generated by the Derivative
Works, if and wherever such third-party notices normally appear. The contents of
the NOTICE file are for informational purposes only and do not modify the
License. You may add Your own attribution notices within Derivative Works that
You distribute, alongside or as an addendum to the NOTICE text from the Work,
provided that such additional attribution notices cannot be construed as
modifying the License.

You may add Your own copyright statement to Your modifications and may provide
additional or different license terms and conditions for use, reproduction, or
distribution of Your modifications, or for any such Derivative Works as a whole,
provided Your use, reproduction, and distribution of the Work otherwise complies
with the conditions stated in this License.

#### 5. Submission of Contributions

Unless You explicitly state otherwise, any Contribution intentionally submitted
for inclusion in the Work by You to the Licensor shall be under the terms and
conditions of this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify the terms of
any separate license agreement you may have executed with Licensor regarding
such Contributions.

#### 6. Trademarks

This License does not grant permission to use the trade names, trademarks,
service marks, or product names of the Licensor, except as required for
reasonable and customary use in describing the origin of the Work and
reproducing the content of the NOTICE file.

#### 7. Disclaimer of Warranty

Unless required by applicable law or agreed to in writing, Licensor provides the
Work (and each Contributor provides its Contributions) on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
including, without limitation, any warranties or conditions of TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
solely responsible for determining the appropriateness of using or
redistributing the Work and assume any risks associated with Your exercise of
permissions under this License.

#### 8. Limitation of Liability

In no event and under no legal theory, whether in tort (including negligence),
contract, or otherwise, unless required by applicable law (such as deliberate
and grossly negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special, incidental,
or consequential damages of any character arising as a result of this License or
out of the use or inability to use the Work (including but not limited to
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
any and all other commercial damages or losses), even if such Contributor has
been advised of the possibility of such damages.

#### 9. Accepting Warranty or Additional Liability

While redistributing the Work or Derivative Works thereof, You may choose to
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
other liability obligations and/or rights consistent with this License. However,
in accepting such obligations, You may act only on Your own behalf and on Your
sole responsibility, not on behalf of any other Contributor, and only if You
agree to indemnify, defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason of your
accepting any such warranty or additional liability.

_END OF TERMS AND CONDITIONS_

### APPENDIX: How to apply the Apache License to your work

To apply the Apache License to your work, attach the following boilerplate
notice, with the fields enclosed by brackets `[]` replaced with your own
identifying information. (Don't include the brackets!) The text should be
enclosed in the appropriate comment syntax for the file format. We also
recommend that a file or class name and description of purpose be included on
the same “printed page” as the copyright notice for easier identification within
third-party archives.

Copyright 2019 Bob Rudis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

+ 6
- 25
NAMESPACE View File

@@ -1,27 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(Athena)
export(athena_connect)
export(db_data_type.AthenaConnection)
export(read_credentials)
export(sql_translate_env.AthenaConnection)
export(use_credentials)
exportClasses(AthenaConnection)
exportClasses(AthenaDriver)
exportClasses(AthenaResult)
exportMethods(dbConnect)
exportMethods(dbExistsTable)
exportMethods(dbGetInfo)
exportMethods(dbGetQuery)
exportMethods(dbListFields)
exportMethods(dbListTables)
exportMethods(dbReadTable)
exportMethods(dbSendQuery)
exportMethods(fetch)
import(DBI)
import(RJDBC)
import(bit64)
import(dbplyr)
importFrom(aws.signature,read_credentials)
importFrom(aws.signature,use_credentials)
importFrom(rJava,.jcall)
export(athena_supported_types)
export(metis_jar_path)
export(simba_driver_version)
import(rJava)
importFrom(utils,compareVersion)
importFrom(utils,packageVersion)

+ 2
- 17
NEWS.md View File

@@ -1,19 +1,4 @@
0.3.0
2.0.6
=========

- Added `sql_translate_env.AthenaConnection()`
- Handles Athena JDBC column types!

0.2.0
=========

- Updated authentication provider to be `com.amazonaws.athena.jdbc.shaded.com.amazonaws.auth.DefaultAWSCredentialsProviderChain` (via @dabdine)
- Now supports additional DBI/RJDBC methods including: `dbExistsTable()`,
`dbListFields()`, `dbListTables()`, `dbReadTable()`
- More documentation
- Added code of conduct

0.1.0
=========

- Using the `cloudyr` `aws.signature` package vs DIY
- Refactor

+ 0
- 16
R/a-utils.R View File

@@ -1,16 +0,0 @@
set_names <- function (object = nm, nm) {
names(object) <- nm
object
}

as_logical <- function(x) {
as.logical(as.integer(x))
}

as_date <- function(x) {
as.Date(x, origin = "1970-01-01")
}

as_posixct <- function(x) {
as.POSIXct(x, origin = "1970-01-01 00:00:00")
}

+ 0
- 223
R/jdbc.r View File

@@ -1,223 +0,0 @@
structure(
0:6,
.Names = c(
"OFF", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"
)
)-> .ll_trans

#' AthenaJDBC
#'
#' @export
setClass(

"AthenaDriver",
representation(
"JDBCDriver",
identifier.quote = "character",
jdrv = "jobjRef"
)

)

#' AthenaJDBC
#'
#' @export
Athena <- function(identifier.quote = '`') {

JDBC(
driverClass = "com.simba.athena.jdbc.Driver",
system.file("java", "AthenaJDBC42_2.0.6.jar", package = "metis.lite"),
identifier.quote = identifier.quote
) -> drv

return(as(drv, "AthenaDriver"))

}

#' AthenaJDBC
#'
#' Connect to Athena
#'
#' @section Driver Configuration Options:
#'
#' - `BinaryColumnLength`: <int> The maximum data length for `BINARY` columns. Default `32767L`
#' - `ComplexTypeColumnLength`: <int> The maximum data length for `ARRAY`, `MAP`, and `STRUCT` columns. Default `65535L`
#' - `StringColumnLength`: <int> The maximum data length for `STRING` columns. Default `255L`
#'
#' @param provider JDBC auth provider (ideally leave default)
#' @param region AWS region the Athena tables are in
#' @param s3_staging_dir A write-able bucket on S3 that you have permissions for
#' @param schema_name LOL if only this actually worked with Amazon's hacked Presto driver
#' @param max_error_retries,connection_timeout,socket_timeout
#' technical connection info that you should only muck with if you know what you're doing.
#' @param log_path,log_level The Athena JDBC driver can (shockingly) provide a decent bit
#' of data in logs. Set this to a temporary directory or something log4j can use. For
#' `log_level` use the names ("INFO", "DEBUG", "WARN", "ERROR", "ALL", "OFF", "FATAL", "TRACE") or
#' their corresponding integer values 0-6.
#' @param ... passed on to the driver. See Details.
#' @references [Connect with JDBC](https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html);
#' [Simba Athena JDBC Driver with SQL Connector Installation and Configuration Guide](https://s3.amazonaws.com/athena-downloads/drivers/JDBC/SimbaAthenaJDBC_2.0.6/docs/Simba+Athena+JDBC+Driver+Install+and+Configuration+Guide.pdf)
#' @export
setMethod(

"dbConnect",
"AthenaDriver",

def = function(
drv,
provider = "com.simba.athena.amazonaws.auth.DefaultAWSCredentialsProviderChain",
region = "us-east-1",
s3_staging_dir = Sys.getenv("AWS_S3_STAGING_DIR"),
schema_name = "default",
fetch_size = 1000L,
max_error_retries = 10,
connection_timeout = 10000,
socket_timeout = 10000,
log_path = "",
log_level = 0,
...) {

conn_string = sprintf(
'jdbc:awsathena://athena.%s.amazonaws.com:443/%s', region, schema_name
)

if (!(log_level %in% 0:6)) log_level <- .ll_trans[log_level]

callNextMethod(
drv,
conn_string,
S3OutputLocation = s3_staging_dir,
Schema = schema_name,
MaxErrorRetry = max_error_retries,
ConnectTimeout = connection_timeout,
SocketTimeout = socket_timeout,
LogPath = log_path,
LogLevel = log_level,
AwsCredentialsProviderClass = provider,
...
) -> jc


jc <- as(jc, "AthenaConnection")
jc@fetch_size <- as.integer(fetch_size)

return(jc)

}

)

#' AthenaJDBC
#'
#' @export
setClass("AthenaConnection", representation("JDBCConnection", jc="jobjRef", identifier.quote="character", fetch_size="integer"))

# setClass("AthenaConnection", contains = "JDBCConnection")

#' AthenaJDBC
#'
#' @export
setClass("AthenaResult", contains = "JDBCResult")

#' AthenaJDBC
#'
#' @param conn Athena connection
#' @param statement SQL statement
#' @param ... unused
#' @export
setMethod(

"dbSendQuery",
signature(conn="AthenaConnection", statement="character"),

definition = function(conn, statement, ...) {
return(as(callNextMethod(), "AthenaResult"))
}

)

#' AthenaJDBC
#'
#' @param conn Athena connection
#' @param pattern table name pattern
#' @param schema Athena schema name
#' @param ... unused
#' @export
setMethod(

"dbListTables",
signature(conn="AthenaConnection"),

definition = function(conn, pattern='*', schema, ...) {

if (missing(pattern)) {
dbGetQuery(
conn, sprintf("SHOW TABLES IN %s", schema)
) -> x
} else {
dbGetQuery(
conn, sprintf("SHOW TABLES IN %s %s", schema, dbQuoteString(conn, pattern))
) -> x
}

x$tab_name
}

)

#' AthenaJDBC
#'
#' @param conn Athena connection
#' @param name table name
#' @param schema Athena schema name
#' @param ... unused
#' @export
setMethod(

"dbExistsTable",
signature(conn="AthenaConnection", name="character"),

definition = function(conn, name, schema, ...) {
length(dbListTables(conn, schema=schema, pattern=name)) > 0
}

)

#' AthenaJDBC
#'
#' @param conn Athena connection
#' @param name table name
#' @param schema Athena schema name
#' @param ... unused
#' @export
setMethod(

"dbListFields",
signature(conn="AthenaConnection", name="character"),

definition = function(conn, name, schema, ...) {
query <- sprintf("SELECT * FROM %s.%s LIMIT 1", schema, name)
res <- dbGetQuery(conn, query)
colnames(res)
}

)

#' AthenaJDBC
#'
#' @param conn Athena connection
#' @param name table name
#' @param schema Athena schema name
#' @param ... unused
#' @export
setMethod(

"dbReadTable",
signature(conn="AthenaConnection", name="character"),

definition = function(conn, name, schema, ...) {
query <- sprintf("SELECT * FROM %s.%s LIMIT 1", schema, dbQuoteString(conn, name))
dbGetQuery(conn, query)
}

)

+ 32
- 0
R/metis-jars-package.R View File

@@ -0,0 +1,32 @@
#' Amazon Athena JDBC Driver Wrapper Supporting the 'metis' Package
#'
#' Contents of the Amazon Athena JDBC Driver
#' <https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html>
#' provided to support functions in the 'metis' package. Version number
#' reflects the version number of the included 'JAR' file.
#'
#' @name metis.jars
#'
#' @section IMPORTANT:
#'
#' Until a release of 'rJava' newer than '0.9.10' is on CRAN signals sent
#' from interrupting Athena JDBC calls crash the R interpreter. You therefore
#' need to set the `-Xrs` option to avoid signals being passed on to the JVM
#' owner. That has to be done _before_ `rJava` is loaded so you either need
#' to remember to put it at the top of all scripts _or_ stick this
#' in your local `~/.Rprofile` and/or sitewide `Rprofile`:
#'
#' options(
#' "java.parameters" = c(getOption("java.parameters", default = NULL), "-Xrs")
#' )
#'
#'
#' @md
#' @encoding UTF-8
#' @keywords internal
#' @docType package
#' @author Bob Rudis (bob@@rud.is)
#' @import rJava
#' @importFrom utils packageVersion compareVersion
#' @references [Simba Athena JDBC Driver with SQL Connector Installation and Configuration Guide](https://s3.amazonaws.com/athena-downloads/drivers/JDBC/SimbaAthenaJDBC_2.0.6/docs/Simba+Athena+JDBC+Driver+Install+and+Configuration+Guide.pdf)
NULL

+ 0
- 48
R/metis-lite-package.R View File

@@ -1,48 +0,0 @@
#' Access and Query Amazon Athena via DBI/JDBC
#'
#' Methods are provides to connect to 'Amazon' 'Athena', lookup schemas/tables,
#' perform queries and retrieve query results. A lightweight 'RJDBC' implementation
#' is included along with an interface to the 'AWS' command-line utility.
#'
#' @name metis.lite
#'
#' @section IMPORTANT:
#'
#' Since R 3.5 (I don't remember this happening in R 3.4.x) signals sent from interrupting
#' Athena JDBC calls crash the R #' interpreter. You need to set the `-Xrs` option to avoid
#' signals being passed on to the JVM owner. That has to be done _before_ `rJava` is
#' loaded so you either need to remember to put it at the top of all scripts _or_ stick this
#' in your local #' `~/.Rprofile` and/or sitewide `Rprofile`:
#'
#'
#' if (!grepl("-Xrs", getOption("java.parameters", ""))) {
#' options(
#' "java.parameters" = c(getOption("java.parameters", default = NULL), "-Xrs")
#' )
#' }
#'
#' @md
#' @encoding UTF-8
#' @keywords internal
#' @docType package
#' @author Bob Rudis (bob@@rud.is)
#' @import RJDBC DBI bit64 dbplyr
#' @references [Simba Athena JDBC Driver with SQL Connector Installation and Configuration Guide](https://s3.amazonaws.com/athena-downloads/drivers/JDBC/SimbaAthenaJDBC_2.0.6/docs/Simba+Athena+JDBC+Driver+Install+and+Configuration+Guide.pdf)
NULL


#' Use Credentials from .aws/credentials File
#'
#' @md
#' @importFrom aws.signature use_credentials read_credentials
#' @references [aws.signature::use_credentials()] / [aws.signature::read_credentials()]
#' @name use_credentials
#' @rdname use_credentials
#' @inheritParams aws.signature::use_credentials
#' @export
NULL

#' @name read_credentials
#' @rdname use_credentials
#' @export
NULL

+ 0
- 68
R/metis.r View File

@@ -1,68 +0,0 @@
#' Simplified Athena JDBC connection helper
#'
#' Handles the up-front JDBC config
#'
#' @md
#' @param default_schema default schema (you'll still need to fully qualify non-default schema table names)
#' @param region AWS region (Ref: <http://docs.aws.amazon.com/general/latest/gr/rande.html#athena>)
#' @param s3_staging_dir the Amazon S3 location to which your query output is written. The JDBC driver then asks Athena to read the results and provide rows of data back to the user.
#' @param max_error_retries the maximum number of retries that the JDBC client attempts to make a request to Athena.
#' @param connection_timeout the maximum amount of time, in milliseconds, to make a successful connection to Athena before an attempt is terminated.
#' @param socket_timeout the maximum amount of time, in milliseconds, to wait for a socket in order to send data to Athena.
# @param retry_base_delay minimum delay amount, in milliseconds, between retrying attempts to connect Athena.
# @param retry_max_backoff_time maximum delay amount, in milliseconds, between retrying attempts to connect Athena.
#' @param log_path local path of the Athena JDBC driver logs. If no log path is provided, then no log files are created.
#' @param log_level log level of the Athena JDBC driver logs. Use names
#' "OFF", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE".
#' @param ... passed on to the driver
#' @export
#' @references [Connect with JDBC](https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html);
#' [Simba Athena JDBC Driver with SQL Connector Installation and Configuration Guide](https://s3.amazonaws.com/athena-downloads/drivers/JDBC/SimbaAthenaJDBC_2.0.6/docs/Simba+Athena+JDBC+Driver+Install+and+Configuration+Guide.pdf)
#' @examples \dontrun{
#' use_credentials("personal")
#'
#' athena_connect(
#' default_schema = "sampledb",
#' s3_staging_dir = "s3://accessible-bucket",
#' log_path = "/tmp/athena.log",
#' log_level = "DEBUG"
#' ) -> ath
#'
#' dbListTables(ath)
#'
#' dbGetQuery(ath, "SELECT * FROM sampledb.elb_logs LIMIT 1")
#'
#' }
athena_connect <- function(
default_schema = "default",
region = c("us-east-1", "us-east-2", "us-west-2"),
s3_staging_dir = Sys.getenv("AWS_S3_STAGING_DIR"),
max_error_retries = 10,
connection_timeout = 10000,
socket_timeout = 10000,
log_path = "",
log_level = c("OFF", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"),
...
) {

athena_jdbc <- Athena()

region <- match.arg(region, c("us-east-1", "us-east-2", "us-west-2"))
log_level <- match.arg(log_level, c("OFF", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"))

dbConnect(
athena_jdbc,
schema_name = default_schema,
region = region,
s3_staging_dir = s3_staging_dir,
max_error_retries = max_error_retries,
connection_timeout = connection_timeout,
socket_timeout = socket_timeout,
log_path = log_path,
log_level = log_level,
...
) -> con

con

}

+ 15
- 0
R/metis_jar_path.R View File

@@ -0,0 +1,15 @@
#' Retrieve the fully-qualified path to the included Athena JAR file
#'
#' @export
#' @examples
#' metis_jar_path()
metis_jar_path <- function() {

list.files(
path = system.file("java", package = "metis.jars"),
pattern = "Ath.*jar$",
full.names = TRUE
)[1]

}


+ 0
- 124
R/sql_translate_env.R View File

@@ -1,124 +0,0 @@
#' @rdname Athena
#' @keywords internal
#' @export
db_data_type.AthenaConnection <- function(con, fields, ...) {
print("\n\n\ndb_data_type\n\n\n")
data_type <- function(x) {
switch(
class(x)[1],
integer64 = "BIGINT",
logical = "BOOLEAN",
integer = "INTEGER",
numeric = "DOUBLE",
factor = "CHARACTER",
character = "CHARACTER",
Date = "DATE",
POSIXct = "TIMESTAMP",
stop("Can't map type ", paste(class(x), collapse = "/"),
" to a supported database type.")
)
}
vapply(fields, data_type, character(1))
}

#' @rdname Athena
#' @keywords internal
#' @export
sql_translate_env.AthenaConnection <- function(con) {

x <- con

dbplyr::sql_variant(

scalar = dbplyr::sql_translator(
.parent = dbplyr::base_scalar,
`!=` = dbplyr::sql_infix("<>"),
as.integer64 = function(x) dbplyr::build_sql("CAST(", x, "AS BIGINT)"),
as.numeric = function(x) dbplyr::build_sql("CAST(", x, " AS DOUBLE)"),
as.character = function(x) dbplyr::build_sql("CAST(", x, " AS CHARACTER)"),
as.date = function(x) dbplyr::build_sql("CAST(", x, " AS DATE)"),
as.Date = function(x) dbplyr::build_sql("CAST(", x, " AS DATE)"),
as.POSIXct = function(x) dbplyr::build_sql("CAST(", x, " AS TIMESTAMP)"),
as.posixct = function(x) dbplyr::build_sql("CAST(", x, " AS TIMESTAMP)"),
as.logical = function(x) dbplyr::build_sql("CAST(", x, " AS BOOLEAN)"),
date_part = function(x, y) dbplyr::build_sql("DATE_PART(", x, ",", y ,")"),
grepl = function(x, y) dbplyr::build_sql("CONTAINS(", y, ", ", x, ")"),
gsub = function(x, y, z) dbplyr::build_sql("REGEXP_REPLACE(", z, ", ", x, ",", y ,")"),
trimws = function(x) dbplyr::build_sql("TRIM(both ' ' FROM ", x, ")"),
cbrt = dbplyr::sql_prefix("CBRT", 1),
degrees = dbplyr::sql_prefix("DEGREES", 1),
e = dbplyr::sql_prefix("E", 0),
row_number = dbplyr::sql_prefix("row_number", 0),
lshift = dbplyr::sql_prefix("LSHIFT", 2),
mod = dbplyr::sql_prefix("MOD", 2),
age = dbplyr::sql_prefix("AGE", 1),
negative = dbplyr::sql_prefix("NEGATIVE", 1),
pi = dbplyr::sql_prefix("PI", 0),
pow = dbplyr::sql_prefix("POW", 2),
radians = dbplyr::sql_prefix("RADIANS", 1),
rand = dbplyr::sql_prefix("RAND", 0),
rshift = dbplyr::sql_prefix("RSHIFT", 2),
trunc = dbplyr::sql_prefix("TRUNC", 2),
contains = dbplyr::sql_prefix("CONTAINS", 2),
convert_to = dbplyr::sql_prefix("CONVERT_TO", 2),
convert_from = dbplyr::sql_prefix("CONVERT_FROM", 2),
string_binary = dbplyr::sql_prefix("STRING_BINARY", 1),
binary_string = dbplyr::sql_prefix("BINARY_STRING", 1),
to_char = dbplyr::sql_prefix("TO_CHAR", 2),
to_date = dbplyr::sql_prefix("TO_DATE", 2),
to_number = dbplyr::sql_prefix("TO_NUMBER", 2),
char_to_timestamp = dbplyr::sql_prefix("TO_TIMESTAMP", 2),
double_to_timestamp = dbplyr::sql_prefix("TO_TIMESTAMP", 1),
char_length = dbplyr::sql_prefix("CHAR_LENGTH", 1),
flatten = dbplyr::sql_prefix("FLATTEN", 1),
kvgen = dbplyr::sql_prefix("KVGEN", 1),
repeated_count = dbplyr::sql_prefix("REPEATED_COUNT", 1),
repeated_contains = dbplyr::sql_prefix("REPEATED_CONTAINS", 2),
ilike = dbplyr::sql_prefix("ILIKE", 2),
init_cap = dbplyr::sql_prefix("INIT_CAP", 1),
length = dbplyr::sql_prefix("LENGTH", 1),
lower = dbplyr::sql_prefix("LOWER", 1),
tolower = dbplyr::sql_prefix("LOWER", 1),
ltrim = dbplyr::sql_prefix("LTRIM", 2),
nullif = dbplyr::sql_prefix("NULLIF", 2),
position = function(x, y) dbplyr::build_sql("POSITION(", x, " IN ", y, ")"),
regexp_replace = dbplyr::sql_prefix("REGEXP_REPLACE", 3),
rtrim = dbplyr::sql_prefix("RTRIM", 2),
rpad = dbplyr::sql_prefix("RPAD", 2),
rpad_with = dbplyr::sql_prefix("RPAD", 3),
lpad = dbplyr::sql_prefix("LPAD", 2),
lpad_with = dbplyr::sql_prefix("LPAD", 3),
strpos = dbplyr::sql_prefix("STRPOS", 2),
substr = dbplyr::sql_prefix("SUBSTR", 3),
trim = function(x, y, z) dbplyr::build_sql("TRIM(", x, " ", y, " FROM ", z, ")"),
upper = dbplyr::sql_prefix("UPPER", 1),
toupper = dbplyr::sql_prefix("UPPER", 1)
),

aggregate = dbplyr::sql_translator(
.parent = dbplyr::base_agg,
n = function() dbplyr::sql("COUNT(*)"),
cor = dbplyr::sql_prefix("CORR"),
cov = dbplyr::sql_prefix("COVAR_SAMP"),
sd = dbplyr::sql_prefix("STDDEV_SAMP"),
var = dbplyr::sql_prefix("VAR_SAMP"),
n_distinct = function(x) {
dbplyr::build_sql(dbplyr::sql("COUNT(DISTINCT "), x, dbplyr::sql(")"))
}
),

window = dbplyr::sql_translator(
.parent = dbplyr::base_win,
n = function() { dbplyr::win_over(dbplyr::sql("count(*)"),
partition = dbplyr::win_current_group()) },
cor = dbplyr::win_recycled("corr"),
cov = dbplyr::win_recycled("covar_samp"),
sd = dbplyr::win_recycled("stddev_samp"),
var = dbplyr::win_recycled("var_samp"),
all = dbplyr::win_recycled("bool_and"),
any = dbplyr::win_recycled("bool_or")
)

)

}

+ 15
- 0
R/types.R View File

@@ -0,0 +1,15 @@
#' Retrieve the current supported type names in Athena
#'
#' @export
#' @examples
#' athena_supported_types()
athena_supported_types <- function() {
gsub(
"^AJ_|_TYPE_NAME$", "",
grep(
"^AJ_",
names(rJava::J("com.simba.athena.athena.AthenaTypes")),
value=TRUE
)
)
}

+ 8
- 0
R/version.R View File

@@ -0,0 +1,8 @@
#' Retrieve the version of the Simba Athena JDBC driver included with the package
#'
#' @export
#' @examples
#' simba_driver_version()
simba_driver_version <- function() {
rJava::J("com.simba.athena.athena.core.AJDriver")$AJ_DRIVER_VERSION
}

+ 0
- 121
R/z-dbGetQuery.R View File

@@ -1,121 +0,0 @@
list(
"-7" = as.logical, # BIT
"-6" = as.integer, # TINYINT
"-5" = bit64::as.integer64, # BIGINT
"-4" = as.character, # LONGVARBINARY
"-3" = as.character, # VARBINARY
"-2" = as.character, # BINARY
"-1" = as.character, # LONGVARCHAR
"0" = as.character, # NULL
"1" = as.character, # CHAR
"2" = as.double, # NUMERIC
"3" = as.double, # DECIMAL
"4" = as.integer, # INTEGER
"5" = as.integer, # SMALLINT
"6" = as.double, # FLOAT
"7" = as.double, # REAL
"8" = as.double, # DOUBLE
"12" = as.character, # VARCHAR
"16" = as_logical, # BOOLEAN
"91" = as_date, # DATE
"92" = as.character, # TIME
"93" = as_posixct, # TIMESTAMP
"2003" = as.character, # ARRAY
"1111" = as.character # OTHER
) -> .jdbc_converters

#' @export
#' @keywords internal
setMethod("dbGetInfo", "AthenaDriver", def=function(dbObj, ...)
list(
name = "AthenaJDBC",
driver_version = list.files(system.file("java", package="metis.lite"), "jar$")[1],
package_version = utils::packageVersion("metis.lite")
)
)

#' @export
#' @keywords internal
setMethod("dbGetInfo", "AthenaConnection", def=function(dbObj, ...)
list(
name = "AthenaJDBC",
driver_version = list.files(system.file("java", package="metis.lite"), "jar$")[1],
package_version = utils::packageVersion("metis.lite")
)
)


#' Fetch records from a previously executed query
#'
#' Fetch the next `n` elements (rows) from the result set and return them
#' as a data.frame.
#'
#' @param res An object inheriting from [DBIResult-class], created by
#' [dbSendQuery()].
#' @param n maximum number of records to retrieve per fetch. Use `n = -1`
#' or `n = Inf`
#' to retrieve all pending records. Some implementations may recognize other
#' special values.
#' @param ... Other arguments passed on to methods.
#' @export
setMethod(
"fetch",
signature(res="AthenaResult", n="numeric"),
def = function(res, n, block = 1000L, ...) {

nms <- c()
athena_type_convert <- list()

cols <- .jcall(res@md, "I", "getColumnCount")

for (i in 1:cols) {
ct <- as.character(.jcall(res@md, "I", "getColumnType", i))
athena_type_convert[[i]] <- .jdbc_converters[[ct]]
nms <- c(nms, .jcall(res@md, "S", "getColumnLabel", i))
# message(ct, "|", tail(nms, 1))
}

athena_type_convert <- set_names(athena_type_convert, nms)

out <- callNextMethod(res = res, n = n, block = block, ...)

# print(str(out))

for (nm in names(athena_type_convert)) {
f <- athena_type_convert[[nm]]
if (length(f) == 0) f <- as.character # catchall in case AMZN is tricksy
out[[nm]] <- f(out[[nm]])
}

out

}
)

#' AthenaJDBC
#'
#' @param conn Athena connection
#' @param statement SQL statement
#' @param ... unused
#' @importFrom rJava .jcall
#' @export
setMethod(

"dbGetQuery",
signature(conn="AthenaConnection", statement="character"),

definition = function(conn, statement, ...) {

r <- dbSendQuery(conn, statement, ...)

on.exit(.jcall(r@stat, "V", "close"))

res <- fetch(r, -1, block = conn@fetch_size)

class(res) <- c("tbl_df", "tbl", "data.frame")

res

}

)

+ 20
- 7
R/zzz.R View File

@@ -1,11 +1,24 @@
.onAttach <- function(libname, pkgname) {

if (interactive()) {
jv <- utils::packageVersion("rJava")
if (utils::compareVersion(toString(jv), "0.9.10") < 1) {
o <- getOption("java.parameters", "")
if (!any(grepl("\\-Xrs", o))) {
packageStartupMessage(
"Did not find '-Xrs' in java.parameters option. Until rJava is updated, ",
"please set this up in your/an Rprofile or at the start of scripts. ",
"See the 'IMPORTANT' section under ?`metis.jars-package`."
)
}
}
}

}

.onLoad <- function(libname, pkgname) {

rJava::.jpackage(pkgname, jars = "*", lib.loc = libname)
rJava::.jaddClassPath(dir(file.path(getwd(), "inst/java"), full.names = TRUE))
o <- getOption("java.parameters", "")
if (!any(grepl("-Xrs", o))) {
packageStartupMessage(
"Did not find '-Xrs' in java.parameters option. Until rJava is updated, ",
"please set this up in your/an Rprofile or at the start of scripts."
)
}

}

+ 26
- 109
README.Rmd View File

@@ -4,64 +4,47 @@ editor_options:
chunk_output_type: console
---

# metis
# metis.jars

Access and Query Amazon Athena via DBI/JDBC
Amazon Athena JDBC Driver Wrapper Supporting the 'metis' Package

## Description

In Greek mythology, Metis was Athena's "helper" so methods are provided to help you accessing and querying Amazon Athena via DBI/JDBC and/or `dplyr`.
#' Methods are provides to connect to 'Amazon' 'Athena', lookup schemas/tables,
Contents of the Amazon Athena JDBC Driver
<https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html>
provided to support functions in the 'metis' package. Version number
reflects the version number of the included 'JAR' file.

## IMPORTANT

Since R 3.5 (I don't remember this happening in R 3.4.x) signals sent from interrupting Athena JDBC calls crash the R interpreter. You need to set the `-Xrs` option to avoid signals being passed on to the JVM owner. That has to be done _before_ `rJava` is loaded so you either need to remember to put it at the top of all scripts _or_ stick this in your local `~/.Rprofile` and/or sitewide `Rprofile`:
Until a release of 'rJava' newer than '0.9.10' is on CRAN signals sent
from interrupting Athena JDBC calls crash the R interpreter. You therefore
need to set the `-Xrs` option to avoid signals being passed on to the JVM
owner. That has to be done _before_ `rJava` is loaded so you either need
to remember to put it at the top of all scripts _or_ stick this
in your local `~/.Rprofile` and/or sitewide `Rprofile`:

```r
if (!grepl("-Xrs", getOption("java.parameters", ""))) {
options(
"java.parameters" = c(getOption("java.parameters", default = NULL), "-Xrs")
)
}
options(
"java.parameters" = c(getOption("java.parameters", default = NULL), "-Xrs")
)
```
## What's Inside The Tin?

The following functions are implemented:

Easy-interface connection helper:

- `athena_connect` Simplified Athena JDBC connection helper

Custom JDBC Classes:

- `Athena`: AthenaJDBC (make a new Athena con obj)
- `AthenaConnection-class`: AthenaJDBC
- `AthenaDriver-class`: AthenaJDBC
- `AthenaResult-class`: AthenaJDBC

Custom JDBC Class Methods:

- `dbConnect-method`
- `dbExistsTable-method`
- `dbGetQuery-method`
- `dbListFields-method`
- `dbListTables-method`
- `dbReadTable-method`
- `dbSendQuery-method`

Pulled in from other `cloudyr` pkgs:

- `read_credentials`: Use Credentials from .aws/credentials File
- `use_credentials`: Use Credentials from .aws/credentials File
- `athena_supported_types`: Retrieve the current supported type names in Athena
- `metis_jar_path()` : Retrieve the fully-qualified path to the included Athena JAR file
- `simba_driver_version`: Retrieve the version of the Simba Athena JDBC driver included with the package

## Installation

```{r eval=FALSE}
devtools::install_git("https://git.sr.ht/~hrbrmstr/metis-lite")
devtools::install_git("https://git.sr.ht/~hrbrmstr/metis-jars")
# OR
devtools::install_gitlab("hrbrmstr/metis-lite")
devtools::install_gitlab("hrbrmstr/metis-jars")
# OR
devtools::install_github("hrbrmstr/metis-lite")
devtools::install_github("hrbrmstr/metis-jars")
```

```{r message=FALSE, warning=FALSE, include=FALSE}
@@ -71,84 +54,18 @@ options(width=120)
## Usage

```{r message=FALSE, warning=FALSE}
library(metis.lite)
library(metis.jars)

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

```{r message=FALSE, warning=FALSE}
library(rJava)
library(RJDBC)
library(metis.lite)
library(magrittr)
library(dbplyr)
library(dplyr)

dbConnect(
drv = metis.lite::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")

dbExistsTable(con, "elb_logs", schema="sampledb")

dbListFields(con, "elb_logs", "sampledb")

dbGetQuery(con, "SELECT * FROM sampledb.elb_logs LIMIT 10") %>%
glimpse()
packageVersion("metis.jars")
```

### 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
") %>%
glimpse()
```
simba_driver_version()

#### dplyr
athena_supported_types()

```{r}
tbl(con, sql("
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 arr,
ARRAY['1', '2, 3', '4'] AS arr,
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
")) %>%
glimpse()
metis_jar_path()
```

## Code of Conduct


+ 35
- 177
README.md View File

@@ -1,223 +1,81 @@

# metis
# metis.jars

Access and Query Amazon Athena via DBI/JDBC
Amazon Athena JDBC Driver Wrapper Supporting the ‘metis’ Package

## Description

In Greek mythology, Metis was Athena’s “helper” so methods are provided
to help you accessing and querying Amazon Athena via DBI/JDBC and/or
`dplyr`. \#’ Methods are provides to connect to ‘Amazon’ ‘Athena’,
lookup schemas/tables,
Contents of the Amazon Athena JDBC Driver
<https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html>
provided to support functions in the ‘metis’ package. Version number
reflects the version number of the included ‘JAR’ file.

## IMPORTANT

Since R 3.5 (I don’t remember this happening in R 3.4.x) signals sent
from interrupting Athena JDBC calls crash the R interpreter. You need to
set the `-Xrs` option to avoid signals being passed on to the JVM owner.
That has to be done *before* `rJava` is loaded so you either need to
remember to put it at the top of all scripts *or* stick this in your
local `~/.Rprofile` and/or sitewide `Rprofile`:
Until a release of ‘rJava’ newer than ‘0.9.10’ is on CRAN signals sent
from interrupting Athena JDBC calls crash the R interpreter. You
therefore need to set the `-Xrs` option to avoid signals being passed on
to the JVM owner. That has to be done *before* `rJava` is loaded so you
either need to remember to put it at the top of all scripts *or* stick
this in your local `~/.Rprofile` and/or sitewide `Rprofile`:

``` r
if (!grepl("-Xrs", getOption("java.parameters", ""))) {
options(
"java.parameters" = c(getOption("java.parameters", default = NULL), "-Xrs")
)
}
options(
"java.parameters" = c(getOption("java.parameters", default = NULL), "-Xrs")
)
```

## What’s Inside The Tin?

The following functions are implemented:

Easy-interface connection helper:

- `athena_connect` Simplified Athena JDBC connection helper

Custom JDBC Classes:

- `Athena`: AthenaJDBC (make a new Athena con obj)
- `AthenaConnection-class`: AthenaJDBC
- `AthenaDriver-class`: AthenaJDBC
- `AthenaResult-class`: AthenaJDBC

Custom JDBC Class Methods:

- `dbConnect-method`
- `dbExistsTable-method`
- `dbGetQuery-method`
- `dbListFields-method`
- `dbListTables-method`
- `dbReadTable-method`
- `dbSendQuery-method`

Pulled in from other `cloudyr` pkgs:

- `read_credentials`: Use Credentials from .aws/credentials File
- `use_credentials`: Use Credentials from .aws/credentials File
- `athena_supported_types`: Retrieve the current supported type names
in Athena
- `metis_jar_path()` : Retrieve the fully-qualified path to the
included Athena JAR file
- `simba_driver_version`: Retrieve the version of the Simba Athena
JDBC driver included with the package

## Installation

``` r
devtools::install_git("https://git.sr.ht/~hrbrmstr/metis-lite")
devtools::install_git("https://git.sr.ht/~hrbrmstr/metis-jars")
# OR
devtools::install_gitlab("hrbrmstr/metis-lite")
devtools::install_gitlab("hrbrmstr/metis-jars")
# OR
devtools::install_github("hrbrmstr/metis-lite")
devtools::install_github("hrbrmstr/metis-jars")
```

## Usage

``` r
library(metis.lite)
library(metis.jars)

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

## [1] '0.3.0'

``` r
library(rJava)
library(RJDBC)
library(metis.lite)
library(magrittr)
library(dbplyr)
library(dplyr)

dbConnect(
drv = metis.lite::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")
```

## [1] "elb_logs"

``` r
dbExistsTable(con, "elb_logs", schema="sampledb")
```

## [1] TRUE

``` r
dbListFields(con, "elb_logs", "sampledb")
packageVersion("metis.jars")
```

## [1] "timestamp" "elbname" "requestip" "requestport"
## [5] "backendip" "backendport" "requestprocessingtime" "backendprocessingtime"
## [9] "clientresponsetime" "elbresponsecode" "backendresponsecode" "receivedbytes"
## [13] "sentbytes" "requestverb" "url" "protocol"
## [1] '2.0.6'

``` r
dbGetQuery(con, "SELECT * FROM sampledb.elb_logs LIMIT 10") %>%
glimpse()
simba_driver_version()
```

## Observations: 10
## Variables: 16
## $ timestamp <chr> "2014-09-29T18:18:51.826955Z", "2014-09-29T18:18:51.920462Z", "2014-09-29T18:18:52.2725…
## $ elbname <chr> "lb-demo", "lb-demo", "lb-demo", "lb-demo", "lb-demo", "lb-demo", "lb-demo", "lb-demo",…
## $ requestip <chr> "255.48.150.122", "249.213.227.93", "245.108.120.229", "241.112.203.216", "241.43.107.2…
## $ requestport <int> 62096, 62096, 62096, 62096, 56454, 33254, 18918, 64352, 1651, 56454
## $ backendip <chr> "244.238.214.120", "248.99.214.228", "243.3.190.175", "246.235.181.255", "241.112.203.2…
## $ backendport <int> 8888, 8888, 8888, 8888, 8888, 8888, 8888, 8888, 8888, 8888
## $ requestprocessingtime <dbl> 9.0e-05, 9.7e-05, 8.7e-05, 9.4e-05, 7.6e-05, 8.3e-05, 6.3e-05, 5.4e-05, 8.2e-05, 8.7e-05
## $ backendprocessingtime <dbl> 0.007410, 0.256533, 0.442659, 0.016772, 0.035036, 0.029892, 0.034148, 0.014858, 0.01518…
## $ clientresponsetime <dbl> 0.000055, 0.000075, 0.000131, 0.000078, 0.000057, 0.000043, 0.000033, 0.000043, 0.00007…
## $ elbresponsecode <chr> "302", "302", "200", "200", "200", "200", "200", "200", "200", "200"
## $ backendresponsecode <chr> "200", "200", "200", "200", "200", "200", "200", "200", "200", "200"
## $ receivedbytes <S3: integer64> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
## $ sentbytes <S3: integer64> 0, 0, 58402, 152213, 20766, 32370, 3408, 3884, 84245, 3831
## $ requestverb <chr> "GET", "GET", "GET", "GET", "GET", "GET", "GET", "GET", "GET", "GET"
## $ url <chr> "http://www.abcxyz.com:80/", "http://www.abcxyz.com:80/accounts/login/?next=/", "http:/…
## $ protocol <chr> "HTTP/1.1", "HTTP/1.1", "HTTP/1.1", "HTTP/1.1", "HTTP/1.1", "HTTP/1.1", "HTTP/1.1", "HT…

### Check types
## [1] "02.00.06.1008"

``` 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
") %>%
glimpse()
athena_supported_types()
```

## Observations: 1
## Variables: 13
## $ achar <chr> "chr "
## $ avarchr <chr> "varchr"
## $ tsday <date> 2014-09-26
## $ justadbl <dbl> 100.1
## $ asmallint <int> 127
## $ justanint <int> 100
## $ abigint <S3: integer64> 100000000000000000
## $ is_get <lgl> TRUE
## $ arr1 <chr> "1, 2, 3"
## $ arr2 <chr> "1, 2, 3, 4"
## $ mp <chr> "{bar=2, foo=1}"
## $ rw <chr> "{x=1, y=2.0}"
## $ js <chr> "\"{\\\"a\\\":1}\""

#### dplyr
## [1] "BOOLEAN" "TINYINT" "SMALLINT" "INT" "INTEGER" "BIGINT" "REAL" "FLOAT" "DOUBLE"
## [10] "DECIMAL" "DATE" "TIMESTAMP" "BINARY" "VARBINARY" "CHAR" "VARCHAR" "STRING" "ARRAY"
## [19] "MAP" "ROW" "STRUCT"

``` r
tbl(con, sql("
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 arr,
ARRAY['1', '2, 3', '4'] AS arr,
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
")) %>%
glimpse()
metis_jar_path()
```

## Observations: ??
## Variables: 13
## Database: AthenaConnection
## $ achar <chr> "chr "
## $ avarchr <chr> "varchr"
## $ tsday <date> 2014-09-27
## $ justadbl <dbl> 100.1
## $ asmallint <int> 127
## $ justanint <int> 100
## $ abigint <S3: integer64> 100000000000000000
## $ is_get <lgl> TRUE
## $ arr <chr> "1, 2, 3"
## $ arr <chr> "1, 2, 3, 4"
## $ mp <chr> "{bar=2, foo=1}"
## $ rw <chr> "{x=1, y=2.0}"
## $ js <chr> "\"{\\\"a\\\":1}\""
## [1] "/Library/Frameworks/R.framework/Versions/3.5/Resources/library/metis.jars/java/AthenaJDBC42_2.0.6.jar"

## Code of Conduct



+ 69
- 0
inst/COPYRIGHTS View File

@@ -0,0 +1,69 @@
The metis.jars package is released under the Apache 2.0 License
The include AthenaJDBC42_2.0.6.jar JAR has the following license:
-----------------
License for AWS SDK for Java
Apache License
Version 2.0, January 2004
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
2. You must cause any modified files to carry prominent notices stating that You changed the files; and
3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Note: Other license terms may apply to certain, identified software files contained within or distributed with the accompanying software if such terms are included in the directory containing the accompanying software. Such other license terms will then apply in lieu of the terms of the software license above.
JSON processing code subject to the JSON License from JSON.org:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 0
- 18
man/Athena.Rd View File

@@ -1,18 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/jdbc.r, R/sql_translate_env.R
\name{Athena}
\alias{Athena}
\alias{db_data_type.AthenaConnection}
\alias{sql_translate_env.AthenaConnection}
\title{AthenaJDBC}
\usage{
Athena(identifier.quote = "`")

db_data_type.AthenaConnection(con, fields, ...)

sql_translate_env.AthenaConnection(con)
}
\description{
AthenaJDBC
}
\keyword{internal}

+ 0
- 9
man/AthenaConnection-class.Rd View File

@@ -1,9 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/jdbc.r
\docType{class}
\name{AthenaConnection-class}
\alias{AthenaConnection-class}
\title{AthenaJDBC}
\description{
AthenaJDBC
}

+ 0
- 9
man/AthenaDriver-class.Rd View File

@@ -1,9 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/jdbc.r
\docType{class}
\name{AthenaDriver-class}
\alias{AthenaDriver-class}
\title{AthenaJDBC}
\description{
AthenaJDBC
}

+ 0
- 9
man/AthenaResult-class.Rd View File

@@ -1,9 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/jdbc.r
\docType{class}
\name{AthenaResult-class}
\alias{AthenaResult-class}
\title{AthenaJDBC}
\description{
AthenaJDBC
}

+ 0
- 57
man/athena_connect.Rd View File

@@ -1,57 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/metis.r
\name{athena_connect}
\alias{athena_connect}
\title{Simplified Athena JDBC connection helper}
\usage{
athena_connect(default_schema = "default", region = c("us-east-1",
"us-east-2", "us-west-2"),
s3_staging_dir = Sys.getenv("AWS_S3_STAGING_DIR"),
max_error_retries = 10, connection_timeout = 10000,
socket_timeout = 10000, log_path = "", log_level = c("OFF",
"FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"), ...)
}
\arguments{
\item{default_schema}{default schema (you'll still need to fully qualify non-default schema table names)}

\item{region}{AWS region (Ref: \url{http://docs.aws.amazon.com/general/latest/gr/rande.html#athena})}

\item{s3_staging_dir}{the Amazon S3 location to which your query output is written. The JDBC driver then asks Athena to read the results and provide rows of data back to the user.}

\item{max_error_retries}{the maximum number of retries that the JDBC client attempts to make a request to Athena.}

\item{connection_timeout}{the maximum amount of time, in milliseconds, to make a successful connection to Athena before an attempt is terminated.}

\item{socket_timeout}{the maximum amount of time, in milliseconds, to wait for a socket in order to send data to Athena.}

\item{log_path}{local path of the Athena JDBC driver logs. If no log path is provided, then no log files are created.}

\item{log_level}{log level of the Athena JDBC driver logs. Use names
"OFF", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE".}

\item{...}{passed on to the driver}
}
\description{
Handles the up-front JDBC config
}
\examples{
\dontrun{
use_credentials("personal")

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

dbListTables(ath)

dbGetQuery(ath, "SELECT * FROM sampledb.elb_logs LIMIT 1")

}
}
\references{
\href{https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html}{Connect with JDBC};
\href{https://s3.amazonaws.com/athena-downloads/drivers/JDBC/SimbaAthenaJDBC_2.0.6/docs/Simba+Athena+JDBC+Driver+Install+and+Configuration+Guide.pdf}{Simba Athena JDBC Driver with SQL Connector Installation and Configuration Guide}
}

+ 14
- 0
man/athena_supported_types.Rd View File

@@ -0,0 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/types.R
\name{athena_supported_types}
\alias{athena_supported_types}
\title{Retrieve the current supported type names in Athena}
\usage{
athena_supported_types()
}
\description{
Retrieve the current supported type names in Athena
}
\examples{
athena_supported_types()
}

+ 0
- 48
man/dbConnect-AthenaDriver-method.Rd View File

@@ -1,48 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/jdbc.r
\docType{methods}
\name{dbConnect,AthenaDriver-method}
\alias{dbConnect,AthenaDriver-method}
\title{AthenaJDBC}
\usage{
\S4method{dbConnect}{AthenaDriver}(drv,
provider = "com.simba.athena.amazonaws.auth.DefaultAWSCredentialsProviderChain",
region = "us-east-1",
s3_staging_dir = Sys.getenv("AWS_S3_STAGING_DIR"),
schema_name = "default", fetch_size = 1000L,
max_error_retries = 10, connection_timeout = 10000,
socket_timeout = 10000, log_path = "", log_level = 0, ...)
}
\arguments{
\item{provider}{JDBC auth provider (ideally leave default)}

\item{region}{AWS region the Athena tables are in}

\item{s3_staging_dir}{A write-able bucket on S3 that you have permissions for}

\item{schema_name}{LOL if only this actually worked with Amazon's hacked Presto driver}

\item{max_error_retries, connection_timeout, socket_timeout}{technical connection info that you should only muck with if you know what you're doing.}

\item{log_path, log_level}{The Athena JDBC driver can (shockingly) provide a decent bit
of data in logs. Set this to a temporary directory or something log4j can use. For
`log_level` use the names ("INFO", "DEBUG", "WARN", "ERROR", "ALL", "OFF", "FATAL", "TRACE") or
their corresponding integer values 0-6.}

\item{...}{passed on to the driver. See Details.}
}
\description{
Connect to Athena
}
\section{Driver Configuration Options}{


- `BinaryColumnLength`: <int> The maximum data length for `BINARY` columns. Default `32767L`
- `ComplexTypeColumnLength`: <int> The maximum data length for `ARRAY`, `MAP`, and `STRUCT` columns. Default `65535L`
- `StringColumnLength`: <int> The maximum data length for `STRING` columns. Default `255L`
}

\references{
[Connect with JDBC](https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html);
[Simba Athena JDBC Driver with SQL Connector Installation and Configuration Guide](https://s3.amazonaws.com/athena-downloads/drivers/JDBC/SimbaAthenaJDBC_2.0.6/docs/Simba+Athena+JDBC+Driver+Install+and+Configuration+Guide.pdf)
}

+ 0
- 22
man/dbExistsTable-AthenaConnection-character-method.Rd View File

@@ -1,22 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/jdbc.r
\docType{methods}
\name{dbExistsTable,AthenaConnection,character-method}
\alias{dbExistsTable,AthenaConnection,character-method}
\title{AthenaJDBC}
\usage{
\S4method{dbExistsTable}{AthenaConnection,character}(conn, name, schema,
...)
}
\arguments{
\item{conn}{Athena connection}

\item{name}{table name}

\item{schema}{Athena schema name}

\item{...}{unused}
}
\description{
AthenaJDBC
}

+ 0
- 19
man/dbGetQuery-AthenaConnection-character-method.Rd View File

@@ -1,19 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/z-dbGetQuery.R
\docType{methods}
\name{dbGetQuery,AthenaConnection,character-method}
\alias{dbGetQuery,AthenaConnection,character-method}
\title{AthenaJDBC}
\usage{
\S4method{dbGetQuery}{AthenaConnection,character}(conn, statement, ...)
}
\arguments{
\item{conn}{Athena connection}

\item{statement}{SQL statement}

\item{...}{unused}
}
\description{
AthenaJDBC
}

+ 0
- 22
man/dbListFields-AthenaConnection-character-method.Rd View File

@@ -1,22 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/jdbc.r
\docType{methods}
\name{dbListFields,AthenaConnection,character-method}
\alias{dbListFields,AthenaConnection,character-method}
\title{AthenaJDBC}
\usage{
\S4method{dbListFields}{AthenaConnection,character}(conn, name, schema,
...)
}
\arguments{
\item{conn}{Athena connection}

\item{name}{table name}

\item{schema}{Athena schema name}

\item{...}{unused}
}
\description{
AthenaJDBC
}

+ 0
- 22
man/dbListTables-AthenaConnection-method.Rd View File

@@ -1,22 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/jdbc.r
\docType{methods}
\name{dbListTables,AthenaConnection-method}
\alias{dbListTables,AthenaConnection-method}
\title{AthenaJDBC}
\usage{
\S4method{dbListTables}{AthenaConnection}(conn, pattern = "*", schema,
...)
}
\arguments{
\item{conn}{Athena connection}

\item{pattern}{table name pattern}

\item{schema}{Athena schema name}

\item{...}{unused}
}
\description{
AthenaJDBC
}

+ 0
- 21
man/dbReadTable-AthenaConnection-character-method.Rd View File

@@ -1,21 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/jdbc.r
\docType{methods}
\name{dbReadTable,AthenaConnection,character-method}
\alias{dbReadTable,AthenaConnection,character-method}
\title{AthenaJDBC}
\usage{
\S4method{dbReadTable}{AthenaConnection,character}(conn, name, schema, ...)
}
\arguments{
\item{conn}{Athena connection}

\item{name}{table name}

\item{schema}{Athena schema name}

\item{...}{unused}
}
\description{
AthenaJDBC
}

+ 0
- 19
man/dbSendQuery-AthenaConnection-character-method.Rd View File

@@ -1,19 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/jdbc.r
\docType{methods}
\name{dbSendQuery,AthenaConnection,character-method}
\alias{dbSendQuery,AthenaConnection,character-method}
\title{AthenaJDBC}
\usage{
\S4method{dbSendQuery}{AthenaConnection,character}(conn, statement, ...)
}
\arguments{
\item{conn}{Athena connection}

\item{statement}{SQL statement}

\item{...}{unused}
}
\description{
AthenaJDBC
}

+ 0
- 24
man/fetch-AthenaResult-numeric-method.Rd View File

@@ -1,24 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/z-dbGetQuery.R
\docType{methods}
\name{fetch,AthenaResult,numeric-method}
\alias{fetch,AthenaResult,numeric-method}
\title{Fetch records from a previously executed query}
\usage{
\S4method{fetch}{AthenaResult,numeric}(res, n, block = 1000L, ...)
}
\arguments{
\item{res}{An object inheriting from [DBIResult-class], created by
[dbSendQuery()].}

\item{n}{maximum number of records to retrieve per fetch. Use `n = -1`
or `n = Inf`
to retrieve all pending records. Some implementations may recognize other
special values.}

\item{...}{Other arguments passed on to methods.}
}
\description{
Fetch the next `n` elements (rows) from the result set and return them
as a data.frame.
}

+ 35
- 0
man/metis.jars.Rd View File

@@ -0,0 +1,35 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/metis-jars-package.R
\docType{package}
\encoding{UTF-8}
\name{metis.jars}
\alias{metis.jars}
\alias{metis.jars-package}
\title{Amazon Athena JDBC Driver Wrapper Supporting the 'metis' Package}
\description{
Contents of the Amazon Athena JDBC Driver
\url{https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html}
provided to support functions in the 'metis' package. Version number
reflects the version number of the included 'JAR' file.
}
\section{IMPORTANT}{


Until a release of 'rJava' newer than '0.9.10' is on CRAN signals sent
from interrupting Athena JDBC calls crash the R interpreter. You therefore
need to set the \code{-Xrs} option to avoid signals being passed on to the JVM
owner. That has to be done \emph{before} \code{rJava} is loaded so you either need
to remember to put it at the top of all scripts \emph{or} stick this
in your local \code{~/.Rprofile} and/or sitewide \code{Rprofile}:\preformatted{options(
"java.parameters" = c(getOption("java.parameters", default = NULL), "-Xrs")
)
}
}

\references{
\href{https://s3.amazonaws.com/athena-downloads/drivers/JDBC/SimbaAthenaJDBC_2.0.6/docs/Simba+Athena+JDBC+Driver+Install+and+Configuration+Guide.pdf}{Simba Athena JDBC Driver with SQL Connector Installation and Configuration Guide}
}
\author{
Bob Rudis (bob@rud.is)
}
\keyword{internal}

+ 0
- 35
man/metis.lite.Rd View File

@@ -1,35 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/metis-lite-package.R
\docType{package}
\encoding{UTF-8}
\name{metis.lite}
\alias{metis.lite}
\alias{metis.lite-package}
\title{Access and Query Amazon Athena via DBI/JDBC}
\description{
Methods are provides to connect to 'Amazon' 'Athena', lookup schemas/tables,
perform queries and retrieve query results. A lightweight 'RJDBC' implementation
is included along with an interface to the 'AWS' command-line utility.
}
\section{IMPORTANT}{


Since R 3.5 (I don't remember this happening in R 3.4.x) signals sent from interrupting
Athena JDBC calls crash the R #' interpreter. You need to set the \code{-Xrs} option to avoid
signals being passed on to the JVM owner. That has to be done \emph{before} \code{rJava} is
loaded so you either need to remember to put it at the top of all scripts \emph{or} stick this
in your local #' \code{~/.Rprofile} and/or sitewide \code{Rprofile}:\preformatted{if (!grepl("-Xrs", getOption("java.parameters", ""))) {
options(
"java.parameters" = c(getOption("java.parameters", default = NULL), "-Xrs")
)
}
}
}

\references{
\href{https://s3.amazonaws.com/athena-downloads/drivers/JDBC/SimbaAthenaJDBC_2.0.6/docs/Simba+Athena+JDBC+Driver+Install+and+Configuration+Guide.pdf}{Simba Athena JDBC Driver with SQL Connector Installation and Configuration Guide}
}
\author{
Bob Rudis (bob@rud.is)
}
\keyword{internal}

+ 14
- 0
man/metis_jar_path.Rd View File

@@ -0,0 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/metis_jar_path.R
\name{metis_jar_path}
\alias{metis_jar_path}
\title{Retrieve the fully-qualified path to the included Athena JAR file}
\usage{
metis_jar_path()
}
\description{
Retrieve the fully-qualified path to the included Athena JAR file
}
\examples{
metis_jar_path()
}

+ 14
- 0
man/simba_driver_version.Rd View File

@@ -0,0 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/version.R
\name{simba_driver_version}
\alias{simba_driver_version}
\title{Retrieve the version of the Simba Athena JDBC driver included with the package}
\usage{
simba_driver_version()
}
\description{
Retrieve the version of the Simba Athena JDBC driver included with the package
}
\examples{
simba_driver_version()
}

+ 0
- 12
man/use_credentials.Rd View File

@@ -1,12 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/metis-lite-package.R
\name{use_credentials}
\alias{use_credentials}
\alias{read_credentials}
\title{Use Credentials from .aws/credentials File}
\description{
Use Credentials from .aws/credentials File
}
\references{
\code{\link[aws.signature:use_credentials]{aws.signature::use_credentials()}} / \code{\link[aws.signature:read_credentials]{aws.signature::read_credentials()}}
}

metis-lite.Rproj → metis-jars.Rproj View File


+ 7
- 1
tests/test-all.R View File