~hrbrmstr/metis-jars

041c62da0c8589ced227b56d7a16ede28de025f2 — hrbrmstr 2 years ago a0512cb
handles types\!
15 files changed, 128 insertions(+), 53 deletions(-)

D .codecov.yml
D .travis.yml
M DESCRIPTION
M NAMESPACE
M NEWS.md
M R/jdbc.r
R R/{metis-package.R => metis-lite-package.R}
M R/sql_translate_env.R
M R/zzz.R
M man/Athena.Rd
R man/{metis.Rd => metis.lite.Rd}
M man/use_credentials.Rd
R metis.Rproj => metis-lite.Rproj
M tests/test-all.R
R tests/testthat/{test-metis.R => test-metis-lite.R}
D .codecov.yml => .codecov.yml +0 -1
@@ 1,1 0,0 @@
comment: false

D .travis.yml => .travis.yml +0 -31
@@ 1,31 0,0 @@
language: r

warnings_are_errors: true

sudo: required

cache: packages

r:
 - oldrel
 - release
 - devel

apt_packages:
  - libv8-dev
  - xclip

env:
 global:
   - CRAN: http://cran.rstudio.com

after_success:
  - Rscript -e 'covr::codecov()'

notifications:
  email:
    - bob@rud.is
  irc:
    channels:
      - "104.236.112.222#builds"
    nick: travisci

M DESCRIPTION => DESCRIPTION +4 -9
@@ 1,21 1,17 @@
Package: metis
Package: metis.lite
Type: Package
Title: Helpers for Accessing and Querying Amazon Athena
Version: 0.4.0
Date: 2018-03-19
Version: 0.3.0
Date: 2019-02-14
Authors@R: c(
    person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"),
           comment = c(ORCID = "0000-0001-5670-2640")),
    person("Derek", "Abdine", comment = "Authentication driver update"),
    person("Zachary", "Kurtz", email = "zdkurtz@gmail.com", role = "ctb")
           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 an interface to the 'AWS' command-line utility.
URL: https://github.com/hrbrmstr/metis
BugReports: https://github.com/hrbrmstr/metis/issues
SystemRequirements: JDK 1.8+
License: AGPL
Suggests:


@@ 31,6 27,5 @@ Imports:
    readr,
    aws.signature,
    uuid,
    reticulate,
    jsonlite
RoxygenNote: 6.1.1

M NAMESPACE => NAMESPACE +1 -0
@@ 1,5 1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(db_data_type,AthenaConnection)
S3method(sql_translate_env,AthenaConnection)
export(Athena)
export(athena_connect)

M NEWS.md => NEWS.md +2 -1
@@ 1,7 1,8 @@
0.2.0
0.3.0
=========

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

0.2.0
=========

M R/jdbc.r => R/jdbc.r +86 -2
@@ 1,3 1,28 @@
.jt <- list(
  BIT = -7,
  TINYINT = -6,
  BIGINT = -5,
  LONGVARBINARY = -4,
  VARBINARY = -3,
  BINARY = -2,
  LONGVARCHAR = -1,
  .NULL = 0,
  CHAR = 1,
  NUMERIC = 2,
  DECIMAL = 3,
  INTEGER = 4,
  SMALLINT = 5,
  FLOAT = 6,
  REAL = 7,
  DOUBLE = 8,
  VARCHAR = 12,
  DATE = 91,
  TIME = 92,
  TIMESTAMP = 93,
  OTHER = 1111
)


stats::setNames(
  0:6,
  c("OFF", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE")


@@ 137,11 162,70 @@ setMethod(
  signature(conn="AthenaConnection", statement="character"),

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

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

    on.exit(.jcall(r@stat, "V", "close"))
    res <- dplyr::tbl_df(fetch(r, -1, block=1000))
    if (type_convert) res <- readr::type_convert(res)

    structure(
      list(
        cols = list(),
        default = structure(list(), class = c("collector_guess", "collector"))
      ),
      class = "col_spec"
    ) -> l

    cols <- .jcall(r@md, "I", "getColumnCount")
    nms <- c()

    cts <- rep(0L, cols)
    for (i in 1:cols) {
      ct <- .jcall(r@md, "I", "getColumnType", i)
      if (ct == .jt$CHAR) {
        l$cols[[i]] <- col_character()
      } else if (ct == .jt$NUMERIC) {
        l$cols[[i]] <- col_double()
      } else if (ct == .jt$DECIMAL) {
        l$cols[[i]] <- col_double()
      } else if (ct == .jt$INTEGER) {
        l$cols[[i]] <- col_integer()
      } else if (ct == .jt$SMALLINT) {
        l$cols[[i]] <- col_integer()
      } else if (ct == .jt$TINYINT) {
        l$cols[[i]] <- col_integer()
      } else if (ct == .jt$BIGINT) {
        l$cols[[i]] <- col_double()
      } else if (ct == .jt$FLOAT) {
        l$cols[[i]] <- col_double()
      } else if (ct == .jt$REAL) {
        l$cols[[i]] <- col_double()
      } else if (ct == .jt$DOUBLE) {
        l$cols[[i]] <- col_double()
      } else if (ct == .jt$VARCHAR) {
        l$cols[[i]] <- col_character()
      } else if (ct == .jt$DATE) {
        l$cols[[i]] <- col_date()
      } else if (ct == .jt$TIME) {
        l$cols[[i]] <- col_time()
      } else if (ct == .jt$TIMESTAMP) {
        l$cols[[i]] <- col_datetime()
      } else if (ct == .jt$BIT) {
        l$cols[[i]] <- col_logical()
      } else {
        l$cols[[i]] <- col_character()
      }
      nms[i] <- .jcall(r@md, "S", "getColumnLabel", i)
    }

    l$cols <- stats::setNames(l$cols, nms)

    res <- fetch(r, -1, block=1000)
    res <- readr::type_convert(res, col_types = l)

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

    res

  }

)

R R/metis-package.R => R/metis-lite-package.R +1 -1
@@ 4,7 4,7 @@
#' perform queries and retrieve query results. A lightweight 'RJDBC' implementation
#' is included along with an interface to the 'AWS' command-line utility.
#'
#' @name metis
#' @name metis.lite
#' @encoding UTF-8
#' @docType package
#' @author Bob Rudis (bob@@rud.is)

M R/sql_translate_env.R => R/sql_translate_env.R +23 -0
@@ 1,6 1,29 @@
#' @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

M R/zzz.R => R/zzz.R +2 -2
@@ 1,4 1,4 @@
.onLoad <- function(libname, pkgname) {
  # rJava::.jpackage(pkgname, jars = "*", lib.loc = libname)
  rJava::.jaddClassPath(dir(file.path(getwd(), "inst/java"), full.names = TRUE))
  rJava::.jpackage(pkgname, jars = "*", lib.loc = libname)
  # rJava::.jaddClassPath(dir(file.path(getwd(), "inst/java"), full.names = TRUE))
}

M man/Athena.Rd => man/Athena.Rd +3 -0
@@ 2,11 2,14 @@
% 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 = "`")

\method{db_data_type}{AthenaConnection}(con, fields, ...)

\method{sql_translate_env}{AthenaConnection}(con)
}
\description{

R man/metis.Rd => man/metis.lite.Rd +4 -4
@@ 1,10 1,10 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/metis-package.R
% Please edit documentation in R/metis-lite-package.R
\docType{package}
\encoding{UTF-8}
\name{metis}
\alias{metis}
\alias{metis-package}
\name{metis.lite}
\alias{metis.lite}
\alias{metis.lite-package}
\title{Helpers for Accessing and Querying Amazon Athena}
\description{
Methods are provides to connect to 'Amazon' 'Athena', lookup schemas/tables,

M man/use_credentials.Rd => man/use_credentials.Rd +1 -1
@@ 1,5 1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/metis-package.R
% Please edit documentation in R/metis-lite-package.R
\name{use_credentials}
\alias{use_credentials}
\alias{read_credentials}

R metis.Rproj => metis-lite.Rproj +0 -0
M tests/test-all.R => tests/test-all.R +1 -1
@@ 1,2 1,2 @@
library(testthat)
test_check("metis")
test_check("metis-lite")

R tests/testthat/test-metis.R => tests/testthat/test-metis-lite.R +0 -0