mirror of https://git.sr.ht/~hrbrmstr/metis
13 changed files with 140 additions and 169 deletions
@ -0,0 +1,2 @@ |
|||
YEAR: 2019 |
|||
COPYRIGHT HOLDER: Bob Rudis |
@ -0,0 +1,21 @@ |
|||
# 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. |
@ -0,0 +1,12 @@ |
|||
set_names <- function (object = nm, nm) { |
|||
names(object) <- nm |
|||
object |
|||
} |
|||
|
|||
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,0 +1,71 @@ |
|||
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 |
|||
"1111" = as.character # OTHER |
|||
) -> .jdbc_converters |
|||
|
|||
#' 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, type_convert=FALSE, ...) { |
|||
|
|||
r <- dbSendQuery(conn, statement, ...) |
|||
|
|||
on.exit(.jcall(r@stat, "V", "close")) |
|||
|
|||
#message("dbGetQuery()") |
|||
|
|||
nms <- c() |
|||
athena_type_convert <- list() |
|||
|
|||
cols <- .jcall(r@md, "I", "getColumnCount") |
|||
|
|||
for (i in 1:cols) { |
|||
ct <- as.character(.jcall(r@md, "I", "getColumnType", i)) |
|||
athena_type_convert[[i]] <- .jdbc_converters[[ct]] |
|||
nms <- c(nms, .jcall(r@md, "S", "getColumnLabel", i)) |
|||
} |
|||
|
|||
athena_type_convert <- set_names(athena_type_convert, nms) |
|||
|
|||
res <- fetch(r, -1, block = 1000) |
|||
|
|||
for (nm in names(athena_type_convert)) { |
|||
res[[nm]] <- athena_type_convert[[nm]](res[[nm]]) |
|||
} |
|||
|
|||
class(res) <- c("tbl_df", "tbl", "data.frame") |
|||
|
|||
res |
|||
|
|||
} |
|||
|
|||
) |
Loading…
Reference in new issue