~hrbrmstr/sergeant

ref: 1726a7c966b3bcaeee26a197eb1441c3884c079a sergeant/tests/testthat/test-sergeant.R -rw-r--r-- 1.2 KiB
1726a7c9hrbrmstr finalizing stuff for release 1 year, 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
library(dbplyr)
library(dplyr)

test_host <- Sys.getenv("DRILL_TEST_HOST", "localhost")

options(sergeant.bigint.warnonce = FALSE)

context("basic d[b]plyr API")
test_that("Core d[b]plyr ops work", {

  testthat::skip_on_cran()

  db <- src_drill(test_host)

  expect_that(db, is_a("src_drill"))

  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)

})