diff --git a/.Rbuildignore b/.Rbuildignore index f31e09b..6cc7095 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,5 +8,6 @@ ^NOTES\.*html$ ^\.codecov\.yml$ ^README_files$ -^doc$ +^docs$ ^CONDUCT\.md$ +^\.bash_profile diff --git a/DESCRIPTION b/DESCRIPTION index ec7b9db..7348e58 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 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 + + 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 diff --git a/LICENSE b/LICENSE deleted file mode 100644 index b6a10f1..0000000 --- a/LICENSE +++ /dev/null @@ -1,2 +0,0 @@ -YEAR: 2019 -COPYRIGHT HOLDER: Bob Rudis diff --git a/LICENSE.md b/LICENSE.md index c36552c..da5de31 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -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_ +_<>_ + +### 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. diff --git a/NAMESPACE b/NAMESPACE index 69e7ba8..312f3be 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/NEWS.md b/NEWS.md index 12a2e7d..f6fe3e4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 \ No newline at end of file +- Refactor \ No newline at end of file diff --git a/R/a-utils.R b/R/a-utils.R deleted file mode 100644 index 13bf73a..0000000 --- a/R/a-utils.R +++ /dev/null @@ -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") -} diff --git a/R/jdbc.r b/R/jdbc.r deleted file mode 100644 index e1c24a6..0000000 --- a/R/jdbc.r +++ /dev/null @@ -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`: The maximum data length for `BINARY` columns. Default `32767L` -#' - `ComplexTypeColumnLength`: The maximum data length for `ARRAY`, `MAP`, and `STRUCT` columns. Default `65535L` -#' - `StringColumnLength`: 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) - } - -) diff --git a/R/metis-jars-package.R b/R/metis-jars-package.R new file mode 100644 index 0000000..e3c7aab --- /dev/null +++ b/R/metis-jars-package.R @@ -0,0 +1,32 @@ +#' Amazon Athena JDBC Driver Wrapper Supporting the 'metis' Package +#' +#' Contents of the Amazon Athena JDBC Driver +#' +#' 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 diff --git a/R/metis-lite-package.R b/R/metis-lite-package.R deleted file mode 100644 index fd0cfdd..0000000 --- a/R/metis-lite-package.R +++ /dev/null @@ -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 diff --git a/R/metis.r b/R/metis.r deleted file mode 100644 index 0f9f15f..0000000 --- a/R/metis.r +++ /dev/null @@ -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: ) -#' @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 - -} diff --git a/R/metis_jar_path.R b/R/metis_jar_path.R new file mode 100644 index 0000000..a7546f1 --- /dev/null +++ b/R/metis_jar_path.R @@ -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] + +} + diff --git a/R/sql_translate_env.R b/R/sql_translate_env.R deleted file mode 100644 index 4467278..0000000 --- a/R/sql_translate_env.R +++ /dev/null @@ -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") - ) - - ) - -} \ No newline at end of file diff --git a/R/types.R b/R/types.R new file mode 100644 index 0000000..90ced56 --- /dev/null +++ b/R/types.R @@ -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 + ) + ) +} \ No newline at end of file diff --git a/R/version.R b/R/version.R new file mode 100644 index 0000000..789ae1e --- /dev/null +++ b/R/version.R @@ -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 +} diff --git a/R/z-dbGetQuery.R b/R/z-dbGetQuery.R deleted file mode 100644 index 9de4762..0000000 --- a/R/z-dbGetQuery.R +++ /dev/null @@ -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 - - } - -) \ No newline at end of file diff --git a/R/zzz.R b/R/zzz.R index 70b17a3..8bfca3f 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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." - ) - } + } diff --git a/README.Rmd b/README.Rmd index bcedb72..346819a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -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 + +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 diff --git a/README.md b/README.md index 82f5a56..9516c4f 100644 --- a/README.md +++ b/README.md @@ -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 + +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 "2014-09-29T18:18:51.826955Z", "2014-09-29T18:18:51.920462Z", "2014-09-29T18:18:52.2725… - ## $ elbname "lb-demo", "lb-demo", "lb-demo", "lb-demo", "lb-demo", "lb-demo", "lb-demo", "lb-demo",… - ## $ requestip "255.48.150.122", "249.213.227.93", "245.108.120.229", "241.112.203.216", "241.43.107.2… - ## $ requestport 62096, 62096, 62096, 62096, 56454, 33254, 18918, 64352, 1651, 56454 - ## $ backendip "244.238.214.120", "248.99.214.228", "243.3.190.175", "246.235.181.255", "241.112.203.2… - ## $ backendport 8888, 8888, 8888, 8888, 8888, 8888, 8888, 8888, 8888, 8888 - ## $ requestprocessingtime 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 0.007410, 0.256533, 0.442659, 0.016772, 0.035036, 0.029892, 0.034148, 0.014858, 0.01518… - ## $ clientresponsetime 0.000055, 0.000075, 0.000131, 0.000078, 0.000057, 0.000043, 0.000033, 0.000043, 0.00007… - ## $ elbresponsecode "302", "302", "200", "200", "200", "200", "200", "200", "200", "200" - ## $ backendresponsecode "200", "200", "200", "200", "200", "200", "200", "200", "200", "200" - ## $ receivedbytes 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - ## $ sentbytes 0, 0, 58402, 152213, 20766, 32370, 3408, 3884, 84245, 3831 - ## $ requestverb "GET", "GET", "GET", "GET", "GET", "GET", "GET", "GET", "GET", "GET" - ## $ url "http://www.abcxyz.com:80/", "http://www.abcxyz.com:80/accounts/login/?next=/", "http:/… - ## $ protocol "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 " - ## $ avarchr "varchr" - ## $ tsday 2014-09-26 - ## $ justadbl 100.1 - ## $ asmallint 127 - ## $ justanint 100 - ## $ abigint 100000000000000000 - ## $ is_get TRUE - ## $ arr1 "1, 2, 3" - ## $ arr2 "1, 2, 3, 4" - ## $ mp "{bar=2, foo=1}" - ## $ rw "{x=1, y=2.0}" - ## $ js "\"{\\\"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 " - ## $ avarchr "varchr" - ## $ tsday 2014-09-27 - ## $ justadbl 100.1 - ## $ asmallint 127 - ## $ justanint 100 - ## $ abigint 100000000000000000 - ## $ is_get TRUE - ## $ arr "1, 2, 3" - ## $ arr "1, 2, 3, 4" - ## $ mp "{bar=2, foo=1}" - ## $ rw "{x=1, y=2.0}" - ## $ js "\"{\\\"a\\\":1}\"" + ## [1] "/Library/Frameworks/R.framework/Versions/3.5/Resources/library/metis.jars/java/AthenaJDBC42_2.0.6.jar" ## Code of Conduct diff --git a/inst/COPYRIGHTS b/inst/COPYRIGHTS new file mode 100644 index 0000000..3561e29 --- /dev/null +++ b/inst/COPYRIGHTS @@ -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. diff --git a/man/Athena.Rd b/man/Athena.Rd deleted file mode 100644 index f919af0..0000000 --- a/man/Athena.Rd +++ /dev/null @@ -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} diff --git a/man/AthenaConnection-class.Rd b/man/AthenaConnection-class.Rd deleted file mode 100644 index d788751..0000000 --- a/man/AthenaConnection-class.Rd +++ /dev/null @@ -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 -} diff --git a/man/AthenaDriver-class.Rd b/man/AthenaDriver-class.Rd deleted file mode 100644 index 3457057..0000000 --- a/man/AthenaDriver-class.Rd +++ /dev/null @@ -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 -} diff --git a/man/AthenaResult-class.Rd b/man/AthenaResult-class.Rd deleted file mode 100644 index ea55534..0000000 --- a/man/AthenaResult-class.Rd +++ /dev/null @@ -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 -} diff --git a/man/athena_connect.Rd b/man/athena_connect.Rd deleted file mode 100644 index fbed4e5..0000000 --- a/man/athena_connect.Rd +++ /dev/null @@ -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} -} diff --git a/man/athena_supported_types.Rd b/man/athena_supported_types.Rd new file mode 100644 index 0000000..4386171 --- /dev/null +++ b/man/athena_supported_types.Rd @@ -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() +} diff --git a/man/dbConnect-AthenaDriver-method.Rd b/man/dbConnect-AthenaDriver-method.Rd deleted file mode 100644 index 001daec..0000000 --- a/man/dbConnect-AthenaDriver-method.Rd +++ /dev/null @@ -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`: The maximum data length for `BINARY` columns. Default `32767L` -- `ComplexTypeColumnLength`: The maximum data length for `ARRAY`, `MAP`, and `STRUCT` columns. Default `65535L` -- `StringColumnLength`: 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) -} diff --git a/man/dbExistsTable-AthenaConnection-character-method.Rd b/man/dbExistsTable-AthenaConnection-character-method.Rd deleted file mode 100644 index 24895cd..0000000 --- a/man/dbExistsTable-AthenaConnection-character-method.Rd +++ /dev/null @@ -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 -} diff --git a/man/dbGetQuery-AthenaConnection-character-method.Rd b/man/dbGetQuery-AthenaConnection-character-method.Rd deleted file mode 100644 index 49c3e1b..0000000 --- a/man/dbGetQuery-AthenaConnection-character-method.Rd +++ /dev/null @@ -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 -} diff --git a/man/dbListFields-AthenaConnection-character-method.Rd b/man/dbListFields-AthenaConnection-character-method.Rd deleted file mode 100644 index 656fb2f..0000000 --- a/man/dbListFields-AthenaConnection-character-method.Rd +++ /dev/null @@ -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 -} diff --git a/man/dbListTables-AthenaConnection-method.Rd b/man/dbListTables-AthenaConnection-method.Rd deleted file mode 100644 index 74976c8..0000000 --- a/man/dbListTables-AthenaConnection-method.Rd +++ /dev/null @@ -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 -} diff --git a/man/dbReadTable-AthenaConnection-character-method.Rd b/man/dbReadTable-AthenaConnection-character-method.Rd deleted file mode 100644 index cd02a94..0000000 --- a/man/dbReadTable-AthenaConnection-character-method.Rd +++ /dev/null @@ -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 -} diff --git a/man/dbSendQuery-AthenaConnection-character-method.Rd b/man/dbSendQuery-AthenaConnection-character-method.Rd deleted file mode 100644 index d84be40..0000000 --- a/man/dbSendQuery-AthenaConnection-character-method.Rd +++ /dev/null @@ -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 -} diff --git a/man/fetch-AthenaResult-numeric-method.Rd b/man/fetch-AthenaResult-numeric-method.Rd deleted file mode 100644 index cde0b0d..0000000 --- a/man/fetch-AthenaResult-numeric-method.Rd +++ /dev/null @@ -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. -} diff --git a/man/metis.jars.Rd b/man/metis.jars.Rd new file mode 100644 index 0000000..13c8645 --- /dev/null +++ b/man/metis.jars.Rd @@ -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} diff --git a/man/metis.lite.Rd b/man/metis.lite.Rd deleted file mode 100644 index 633a08f..0000000 --- a/man/metis.lite.Rd +++ /dev/null @@ -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} diff --git a/man/metis_jar_path.Rd b/man/metis_jar_path.Rd new file mode 100644 index 0000000..793b454 --- /dev/null +++ b/man/metis_jar_path.Rd @@ -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() +} diff --git a/man/simba_driver_version.Rd b/man/simba_driver_version.Rd new file mode 100644 index 0000000..04c4be1 --- /dev/null +++ b/man/simba_driver_version.Rd @@ -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() +} diff --git a/man/use_credentials.Rd b/man/use_credentials.Rd deleted file mode 100644 index b6a2060..0000000 --- a/man/use_credentials.Rd +++ /dev/null @@ -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()}} -} diff --git a/metis-lite.Rproj b/metis-jars.Rproj similarity index 100% rename from metis-lite.Rproj rename to metis-jars.Rproj diff --git a/tests/test-all.R b/tests/test-all.R index fb8feef..5e18134 100644 --- a/tests/test-all.R +++ b/tests/test-all.R @@ -1,2 +1,8 @@ +options( + "java.parameters" = unique( + c(getOption("java.parameters", default = NULL), "-Xrs") + ) +) + library(testthat) -test_check("metis-lite") +test_check("metis.jars") diff --git a/tests/testthat/test-metis-lite.R b/tests/testthat/test-metis-lite.R deleted file mode 100644 index ab6f62f..0000000 --- a/tests/testthat/test-metis-lite.R +++ /dev/null @@ -1,6 +0,0 @@ -context("basic functionality") -test_that("we can do something", { - - #expect_that(some_function(), is_a("data.frame")) - -}) diff --git a/tests/testthat/test-metis.jars.R b/tests/testthat/test-metis.jars.R new file mode 100644 index 0000000..75bf28a --- /dev/null +++ b/tests/testthat/test-metis.jars.R @@ -0,0 +1,11 @@ +options( + "java.parameters" = unique( + c(getOption("java.parameters", default = NULL), "-Xrs") + ) +) + +context("JAR loads; classes available") + +expect_is(simba_driver_version(), "character") +expect_is(athena_supported_types(), "character") +expect_is(metis_jar_path(), "character")