Browse Source

more tests; working on #32

pull/34/head
boB Rudis 5 years ago
parent
commit
cd71c1a7f8
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 1
      NAMESPACE
  2. 1
      NEWS.md
  3. 3
      R/dbi.r
  4. 3
      R/dplyr.r
  5. 72
      tests/testthat/test-sergeant.R

1
NAMESPACE

@ -52,6 +52,7 @@ exportMethods(dbGetStatement)
exportMethods(dbHasCompleted)
exportMethods(dbIsValid)
exportMethods(dbListFields)
exportMethods(dbSendQuery)
exportMethods(dbUnloadDriver)
import(DBI)
import(bit64)

1
NEWS.md

@ -17,6 +17,7 @@
columns to `BIGINT`
- Added `ctas_profile()` to automagically create a CTAS query from
a Drill `tbl` (Ref: #29 / inspired by David Severski)
- Added more tests to cover DBI and extended d[b]plyr operations
# sergeant 0.7.0-BETA

3
R/dbi.r

@ -126,6 +126,7 @@ cmake_server <- function(conn) {
#' @param conn connection
#' @param statement SQL statement
#' @param ... passed on to methods
#' @export
#' @family Drill REST DBI API
#' @aliases dbSendQuery,DrillConnection,character-method
setMethod(
@ -334,7 +335,7 @@ setMethod(
else if (inherits(obj, "POSIXct")) "TIMESTAMP"
else if (inherits(obj, "integer64")) "BIGINT"
else if (is.numeric(obj)) "DOUBLE"
else "VARCHAR(255)"
else "VARCHAR"
},
valueClass = "character"
)

3
R/dplyr.r

@ -140,7 +140,8 @@ db_explain.DrillConnection <- function(con, sql, ...) {
db_query_fields.DrillConnection <- function(con, sql, ...) {
fields <- dbplyr::build_sql(
"SELECT * FROM ", sql, " LIMIT 1",
# "SELECT * FROM ", sql, " LIMIT 1",
"SELECT * FROM ", dplyr::sql_subquery(con, sql), " LIMIT 1",
con = con
)
result <- dbSendQuery(con, fields)

72
tests/testthat/test-sergeant.R

@ -1,7 +1,9 @@
test_host <- Sys.getenv("DRILL_TEST_HOST", "localhost")
context("dplyr API")
test_that("Core dbplyr ops work", {
options(sergeant.bigint.warnonce = FALSE)
context("basic d[b]plyr API")
test_that("Core d[b]plyr ops work", {
testthat::skip_on_cran()
@ -12,7 +14,73 @@ test_that("Core dbplyr ops work", {
test_dplyr <- tbl(db, "cp.`employee.json`")
expect_that(test_dplyr, is_a("tbl"))
})
context("extended d[b]plyr API")
test_that("Extended d[b]plyr ops work", {
testthat::skip_on_cran()
db <- src_drill(test_host)
test_dplyr <- tbl(db, "cp.`employee.json`")
expect_that(dplyr::count(test_dplyr, gender), is_a("tbl"))
expect_true(sum(dplyr::collect(dplyr::count(test_dplyr, gender))[["n"]]) > 100)
emp_partial <- tbl(db, sql("SELECT full_name from cp.`employee.json`"))
expect_is(emp_partial, "tbl_drill")
fields <- db_query_fields(emp_partial$src$con, sql("SELECT full_name from cp.`employee.json`"))
expect_true(all(fields %in% c("full_name", "filename", "filepath", "fqn", "suffix")))
expln <- db_explain(emp_partial$src$con, sql("SELECT full_name from cp.`employee.json`"))
expect_true(grepl("groupscan", expln))
res <- select(emp_partial, full_name)
})
context("DBI")
test_that("core DBI ops work", {
testthat::skip_on_cran()
con <- dbConnect(Drill(), "localhost")
expect_is(con, "DrillConnection")
expect_true(dbIsValid(con))
fields <- dbListFields(con, "cp.`employee.json`")
expect_true(
all(
fields %in%
c(
"employee_id", "full_name", "first_name", "last_name", "position_id",
"position_title", "store_id", "department_id", "birth_date",
"hire_date", "salary", "supervisor_id", "education_level", "marital_status",
"gender", "management_role"
)
)
)
res <- dbSendQuery(con, "SELECT full_name from cp.`employee.json` LIMIT 1")
expect_is(res, "DrillResult")
xdf <- dbFetch(res)
expect_identical(dim(xdf), c(1L, 1L))
expect_true(dbClearResult(res))
expect_true(dbHasCompleted(res))
expect_equal(dbDataType(con, character(0)), "VARCHAR")
expect_equal(dbDataType(con, integer(0)), "INTEGER")
expect_equal(dbDataType(con, Sys.Date()), "DATE")
expect_equal(dbDataType(con, Sys.time()), "TIMESTAMP")
expect_equal(dbDataType(con, bit64::integer64(0)), "BIGINT")
expect_equal(dbDataType(con, numeric(0)), "DOUBLE")
})

Loading…
Cancel
Save