Browse Source

Tweaks for updates to REST API; more tests; code coverage

tags/v0.5.2
boB Rudis 7 years ago
parent
commit
be603265c9
No known key found for this signature in database GPG Key ID: 2A514A4997464560
  1. 1
      .Rbuildignore
  2. 3
      .travis.yml
  3. 3
      DESCRIPTION
  4. 11
      R/jdbc.r
  5. 15
      R/query.r
  6. 4
      R/schemas.R
  7. 8
      R/sergeant.r
  8. 12
      R/set.R
  9. 9
      R/utils.r
  10. 3
      README.Rmd
  11. 8
      README.md
  12. 1
      codecov.yml
  13. 65
      tests/testthat/test-sergeant.R

1
.Rbuildignore

@ -7,3 +7,4 @@
^sergeant.png$
^inst/jars$
^docs$
^codecov\.yml$

3
.travis.yml

@ -27,6 +27,9 @@ after_script:
- "$HOME/local/apache-drill-1.10.0/bin/drillbit.sh stop"
- "sudo service zookeeper-server stop"
after_success:
- Rscript -e 'covr::codecov()'
r:
- oldrel
- release

3
DESCRIPTION

@ -29,5 +29,6 @@ Imports:
Suggests:
RJDBC,
rJava,
testthat
testthat,
covr
RoxygenNote: 6.0.1

11
R/jdbc.r

@ -27,13 +27,8 @@
#' }
drill_jdbc <- function(nodes="localhost:2181", cluster_id=NULL, schema=NULL, use_zk=TRUE) {
if (!requireNamespace("rJava")) {
stop("RJDBC & rJava are required to use the Drill JDBC connectors", .call=FALSE)
}
if (!requireNamespace("RJDBC")) {
stop("RJDBC & rJava are required to use the Drill JDBC connectors", .call=FALSE)
}
try_require("rJava")
try_require("RJDBC")
jar_path <- Sys.getenv("DRILL_JDBC_JAR")
if (!file.exists(jar_path)) {
@ -41,7 +36,7 @@ drill_jdbc <- function(nodes="localhost:2181", cluster_id=NULL, schema=NULL, use
}
drill_jdbc_drv <- RJDBC::JDBC(driverClass="org.apache.drill.jdbc.Driver",
classPath=jar_path, identifier.quote=' ')
classPath=jar_path, identifier.quote='`')
conn_type <- "drillbit"
if (use_zk) conn_type <- "zk"

15
R/query.r

@ -24,13 +24,8 @@ drill_query <- function(drill_con, query, uplift=TRUE, .progress=interactive())
if (inherits(drill_con, "JDBCConnection")) {
if (!requireNamespace("rJava")) {
stop("RJDBC & rJava are required to use the Drill JDBC connectors", .call=FALSE)
}
if (!requireNamespace("RJDBC")) {
stop("RJDBC & rJava are required to use the Drill JDBC connectors", .call=FALSE)
}
try_require("rJava")
try_require("RJDBC")
dplyr::tbl_df(RJDBC::dbGetQuery(drill_con, query))
@ -42,13 +37,11 @@ drill_query <- function(drill_con, query, uplift=TRUE, .progress=interactive())
res <- httr::POST(sprintf("%s/query.json", drill_server),
encode="json",
progress(),
body=list(queryType="SQL",
query=query))
body=list(queryType="SQL", query=query))
} else {
res <- httr::POST(sprintf("%s/query.json", drill_server),
encode="json",
body=list(queryType="SQL",
query=query))
body=list(queryType="SQL", query=query))
}
out <- jsonlite::fromJSON(httr::content(res, as="text", encoding="UTF-8"), flatten=TRUE)

4
R/schemas.R

@ -4,7 +4,7 @@
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @export
drill_show_schemas <- function(drill_con) {
drill_query(drill_con, "SHOW SCHEMAS")$rows$SCHEMA_NAME
drill_query(drill_con, "SHOW SCHEMAS")
}
#' Change to a particular schema.
@ -17,7 +17,7 @@ drill_show_schemas <- function(drill_con) {
drill_use <- function(drill_con, schema_name) {
query <- sprintf("USE `%s`", schema_name)
out <- drill_query(drill_con, query)
if (!("errorMessage" %in% names(out))) message(out$rows$summary[1])
if (!("errorMessage" %in% names(out))) message(out)
invisible(out)
}

8
R/sergeant.r

@ -129,10 +129,10 @@ drill_profile <- function(drill_con, query_id) {
#' @export
drill_cancel <- function(drill_con, query_id) {
drill_server <- make_server(drill_con)
res <- httr::GET(sprintf("%s/profiles/cancel%s", drill_server, query_id))
res <- httr::GET(sprintf("%s/profiles/cancel/%s", drill_server, query_id))
httr::stop_for_status(res)
cnt <- httr::content(res, as="text", encoding="UTF-8")
jsonlite::fromJSON(cnt)
message(httr::content(res, as="text", encoding="UTF-8"))
invisible(TRUE)
}
#' Get the list of storage plugin names and configurations
@ -192,7 +192,7 @@ drill_options <- function(drill_con, pattern=NULL) {
#' }
drill_stats <- function(drill_con) {
drill_server <- make_server(drill_con)
res <- httr::GET(sprintf("%s/stats.json", drill_server))
res <- httr::GET(sprintf("%s/cluster.json", drill_server))
httr::stop_for_status(res)
cnt <- httr::content(res, as="text", encoding="UTF-8")
jsonlite::fromJSON(cnt)

12
R/set.R

@ -28,20 +28,20 @@ drill_set <- function(drill_con, ..., type=c("session", "system")) {
purrr::map_df(function(x) {
y <- drill_query(drill_con, x)
if (length(y) == 2) {
dplyr::data_frame(query=x, param=y[[2]]$summary, value=y[[2]]$ok, error=NA)
dplyr::data_frame(query=x, param=y$summary, value=y$ok, error_msg=NA)
} else {
dplyr::data_frame(query=x, param=NA, value=NA, error=y[[1]])
dplyr::data_frame(query=x, param=NA, value=NA, error_msg=y[[1]])
}
}) -> res
if (sum(!is.na(res$error))>0) {
if (sum(!is.na(res$error_msg))>0) {
dplyr::filter(res, !is.na(error)) %>%
dplyr::mutate(msg=sprintf("QUERY => %s\n%s\n", query, error)) -> msgs
dplyr::filter(res, !is.na(error_msg)) %>%
dplyr::mutate(msg=sprintf("QUERY => %s\n%s\n", query, error_msg)) -> msgs
msgs <- paste0(msgs$msg, collapse="\n")
message(sprintf("%d errors:\n\n%s", sum(!is.na(res$error)), msgs))
message(sprintf("%d errors:\n\n%s", sum(!is.na(res$error_msg)), msgs))
}

9
R/utils.r

@ -0,0 +1,9 @@
try_require <- function(package, fun) {
if (requireNamespace(package, quietly = TRUE)) {
library(package, character.only = TRUE)
return(invisible())
}
stop("Package `", package, "` required for `", fun , "`.\n", # nocov start
"Please install and try again.", call. = FALSE) # nocov end
}

3
README.Rmd

@ -11,7 +11,8 @@ knitr::opts_chunk$set(
)
```
[![Travis-CI Build Status](https://travis-ci.org/hrbrmstr/sergeant.svg?branch=master)](https://travis-ci.org/hrbrmstr/sergeant)
[![Travis-CI Build Status](https://travis-ci.org/hrbrmstr/sergeant.svg?branch=master)](https://travis-ci.org/hrbrmstr/sergeant)
<!-- [![Coverage Status](https://img.shields.io/codecov/c/github/hrbrmstr/sergeant/master.svg)](https://codecov.io/github/hrbrmstr/sergeant?branch=master) -->
<img src="sergeant.png" width="33" align="left" style="padding-right:20px"/>

8
README.md

@ -1,6 +1,6 @@
<!-- README.md is generated from README.Rmd. Please edit that file -->
[![Travis-CI Build Status](https://travis-ci.org/hrbrmstr/sergeant.svg?branch=master)](https://travis-ci.org/hrbrmstr/sergeant)
[![Travis-CI Build Status](https://travis-ci.org/hrbrmstr/sergeant.svg?branch=master)](https://travis-ci.org/hrbrmstr/sergeant) <!-- [![Coverage Status](https://img.shields.io/codecov/c/github/hrbrmstr/sergeant/master.svg)](https://codecov.io/github/hrbrmstr/sergeant?branch=master) -->
<img src="sergeant.png" width="33" align="left" style="padding-right:20px"/>
@ -460,12 +460,14 @@ library(testthat)
#> matches
date()
#> [1] "Sat Jun 17 20:48:00 2017"
#> [1] "Sun Jun 18 23:52:57 2017"
devtools::test()
#> Loading sergeant
#> Testing sergeant
#> basic functionality: ..
#> dplyr: ....
#> rest: ................
#> jdbc: ..
#>
#> DONE ===================================================================================================================
```

1
codecov.yml

@ -0,0 +1 @@
comment: false

65
tests/testthat/test-sergeant.R

@ -1,16 +1,67 @@
context("basic functionality")
context("dplyr")
test_that("we can do something", {
testthat::skip_on_cran()
# testthat::skip_on_travis()
testthat::skip_on_cran()
src_drill("localhost") %>%
tbl("cp.`employee.json`") -> test_dplyr
db <- src_drill("localhost")
drill_connection("localhost") %>%
drill_query("SELECT * FROM cp.`employee.json` limit 10") -> test_rest
expect_that(db, is_a("src_drill"))
expect_that(sql_translate_env(db$con), is_a("sql_variant"))
test_dplyr <- tbl(db, "cp.`employee.json`")
expect_that(test_dplyr, is_a("tbl"))
expect_that(count(test_dplyr, gender), is_a("tbl"))
})
context("rest")
test_that("we can do something", {
testthat::skip_on_cran()
dc <- drill_connection("localhost")
expect_that(drill_active(dc), equals(TRUE))
test_rest <- drill_query(dc, "SELECT * FROM cp.`employee.json` limit 10")
expect_that(test_rest, is_a("data.frame"))
expect_that(drill_version(dc), is_a("character"))
expect_that(drill_metrics(dc), is_a("list"))
expect_that(drill_options(dc), is_a("tbl"))
dp <- drill_profiles(dc)
expect_that(dp, is_a("list"))
expect_that(drill_profile(dc, dp$finishedQueries[1]$queryId[1]), is_a("list"))
expect_that(drill_cancel(dc, dp$finishedQueries[1]$queryId[1]), equals(TRUE))
expect_that(drill_show_files(dc, schema_spec = "dfs"), is_a("tbl"))
expect_that(drill_show_schemas(dc), is_a("tbl"))
expect_that(drill_storage(dc), is_a("tbl"))
expect_that(drill_stats(dc), is_a("list"))
expect_that(drill_status(dc), is_a("html"))
expect_that(drill_threads(dc), is_a("html"))
expect_that(drill_use(dc, "cp"), is_a("tbl"))
expect_that(drill_set(dc, exec.errors.verbose=TRUE,
store.format="parquet",
q = 4,
web.logs.max_lines=20000), is_a("tbl"))
})
context("jdbc")
test_that("we can do something", {
testthat::skip_on_cran()
dc <- drill_jdbc("localhost:31010", use_zk=FALSE)
expect_that(dc, is_a("JDBCConnection"))
expect_that(drill_query(dc, "SELECT * FROM cp.`employee.json`"),
is_a("tbl"))
})

Loading…
Cancel
Save