~hrbrmstr/sergeant

b9a1301d22b73b70c20054f53b3b020b2d6f98c1 — Bob Rudis 4 years ago 7039011
new idiom
M NAMESPACE => NAMESPACE +3 -0
@@ 1,7 1,9 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(drill_active)
export(drill_cancel)
export(drill_connection)
export(drill_metrics)
export(drill_options)
export(drill_profile)


@@ 26,6 28,7 @@ import(utils)
importFrom(dplyr,bind_cols)
importFrom(dplyr,bind_rows)
importFrom(dplyr,data_frame)
importFrom(dplyr,filter)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,select)

A NEWS.md => NEWS.md +7 -0
@@ 0,0 1,7 @@
# sergeant 0.1.0.9000

* Changed idiom to piping in a connection object
* Added a `NEWS.md` file to track changes to the package.




M R/aaa.r => R/aaa.r +12 -0
@@ 1,1 1,13 @@
utils::globalVariables(c("error", "everything", "isDirectory", "name", "params", "permissions", "query"))

make_server <- function(drill_con) {

  ret <- sprintf("%s://%s:%s",
          ifelse(drill_con$ssl[1], "https", "http"),
          drill_con$host, drill_con$port)

  message(ret)

  ret

}

M R/query.r => R/query.r +5 -3
@@ 1,15 1,17 @@
#' Submit a query and return results
#'
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @param query query to run
#' @param uplift automatically run \code{drill_uplift()} on the result?
#' @param .progress if \code{TRUE} then ask \code{httr::PSOT} to display a progress bar
#' @param drill_server base URL of the \code{drill} server
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @export
#' @examples \dontrun{
#' drill_query("SELECT * FROM cp.`employee.json` limit 5")
#' drill_con() %>% drill_query("SELECT * FROM cp.`employee.json` limit 5")
#' }
drill_query <- function(query, uplift=TRUE, .progress=FALSE, drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_query <- function(drill_con, query, uplift=TRUE, .progress=FALSE) {

  drill_server <- make_server(drill_con)

  if (.progress) {
    res <- httr::POST(sprintf("%s/query.json", drill_server),

M R/schemas.R => R/schemas.R +10 -11
@@ 1,38 1,37 @@
#' Returns a list of available schemas.
#'
#' @param drill_server base URL of the \code{drill} server
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @export
drill_show_schemas <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
  drill_query("SHOW SCHEMAS", drill_server=drill_server)$rows$SCHEMA_NAME
drill_show_schemas <- function(drill_con) {
  drill_query(drill_con, "SHOW SCHEMAS")$rows$SCHEMA_NAME
}

#' Change to a particular schema.
#'
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @param schema_name A unique name for a Drill schema. A schema in Drill is a configured
#'                   storage plugin, such as hive, or a storage plugin and workspace.
#' @param drill_server base URL of the \code{drill} server
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @export
drill_use <- function(schema_name, drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_use <- function(drill_con, schema_name) {
  query <- sprintf("USE `%s`", schema_name)
  out <- drill_query(query, drill_server=drill_server)
  out <- drill_query(drill_con, query)
  if (!("errorMessage" %in% names(out))) message(out$rows$summary[1])
  invisible(out)
}

#' Show files in a file system schema.
#'
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @param schema_spec properly quoted "filesystem.directory_name" reference path
#' @param drill_server base URL of the \code{drill} server
#' @export
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @examples \dontrun{
#' drill_show_files("dfs.tmp")
#' drill_show_files("dfs.tmp")
#' drill_con() %>% drill_show_files("dfs.tmp")
#' }
drill_show_files <- function(schema_spec, drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_show_files <- function(drill_con, schema_spec) {
  query <- sprintf("SHOW FILES IN %s", schema_spec)
  drill_query(query, uplift=TRUE, drill_server=drill_server) %>%
  drill_query(drill_con, query, uplift=TRUE) %>%
    dplyr::select(name, isDirectory, permissions, everything())
}

M R/sergeant-package.r => R/sergeant-package.r +16 -1
@@ 18,6 18,21 @@
#' @author Bob Rudis (bob@@rud.is)
#' @import httr jsonlite htmltools
#' @importFrom purrr map map2 map2_df %>%
#' @importFrom dplyr mutate select left_join bind_cols bind_rows data_frame tbl
#' @importFrom dplyr mutate select left_join bind_cols bind_rows data_frame tbl filter
#' @import utils
NULL


#' sergeant exported operators
#'
#' The following functions are imported and then re-exported
#' from the sergeant package to enable use of the magrittr
#' pipe operator with no additional library calls
#'
#' @name sergeant-exports
NULL

#' @name %>%
#' @export
#' @rdname sergeant-exports
NULL

M R/sergeant.r => R/sergeant.r +75 -33
@@ 1,27 1,57 @@
s_head <- purrr::safely(httr::HEAD)

#' Setup a Drill connection
#'
#' @param host Drill host (will pick up the value from \code{DRILL_HOST} env var)
#' @param port Drill port (will pick up the value from \code{DRILL_POST} env var)
#' @param ssl use ssl?
#' @param user,password NOT IMPLEMENTED YET credentials for username/password auth.
#'                      (will pick up the values from \code{DRILL_USER}/\code{DRILL_PASSWORD}
#'                      env vars)
#' @export
#' @examples
#' dc <- drill_connection()
drill_connection <- function(host=Sys.getenv("DRILL_HOST", "localhost"),
                      port=Sys.getenv("DRILL_PORT", 8047),
                      ssl=FALSE,
                      user=Sys.getenv("DRILL_USER", ""),
                      password=Sys.getenv("DRILL_PASSWORD", "")) {
  list(host=host,
       port=port,
       ssl=ssl,
       user=ifelse(user[1]=="", NA, user[1]),
       password=ifelse(password[1]=="", NA, password[1])) -> out

  class(out) <- c("drill_conn", class(out))

  out

}

#' Test whether Drill HTTP REST API server is up
#'
#' This is a very simple test (performs \code{HEAD /} on \code{drill_server}
#' This is a very simple test (performs \code{HEAD /} request on the Drill server/cluster)
#'
#' @param drill_server base URL of the \code{drill} server
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @export
#' @examples \dontrun{
#' drill_active()
#' drill_connection() %>% drill_active()
#' }
drill_active <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_active <- function(drill_con) {
  drill_server <- make_server(drill_con)
  !is.null(s_head(drill_server, httr::timeout(2))$result)
}

#' Get the status of Drill
#'
#' @note The output of this is in a "viewer" window
#' @param drill_server base URL of the \code{drill} server
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @export
#' @examples \dontrun{
#' drill_status()
#' drill_connection() %>% drill_status()
#' }
drill_status <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_status <- function(drill_con) {
  drill_server <- make_server(drill_con)
  res <- httr::GET(sprintf("%s/status", drill_server))
  cnt <- httr::content(res, as="text", encoding="UTF-8")
  cnt <- htmltools::HTML(cnt)


@@ 30,12 60,13 @@ drill_status <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://loca

#' Get the current memory metrics
#'
#' @param drill_server base URL of the \code{drill} server
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @export
#' @examples \dontrun{
#' drill_metrics()
#' drill_connection() %>% drill_metrics()
#' }
drill_metrics <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_metrics <- function(drill_con) {
  drill_server <- make_server(drill_con)
  res <- httr::GET(sprintf("%s/status/metrics", drill_server))
  cnt <- httr::content(res, as="text", encoding="UTF-8")
  jsonlite::fromJSON(cnt, flatten=TRUE)


@@ 44,12 75,13 @@ drill_metrics <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://loc
#' Get information about threads
#'
#' @note The output of this is in a "viewer" window
#' @param drill_server base URL of the \code{drill} server
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @export
#' @examples \dontrun{
#' drill_threads()
#' drill_connection() %>% drill_threads()
#' }
drill_threads <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_threads <- function(drill_con) {
  drill_server <- make_server(drill_con)
  res <- httr::GET(sprintf("%s/status/threads", drill_server))
  cnt <- httr::content(res, as="text", encoding="UTF-8")
  cnt <- htmltools::HTML(sprintf("<pre>%s</pre>", cnt))


@@ 58,13 90,14 @@ drill_threads <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://loc

#' Get the profiles of running and completed queries
#'
#' @param drill_server base URL of the \code{drill} server
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @export
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @examples \dontrun{
#' drill_profiles()
#' drill_connection() %>% drill_profiles()
#' }
drill_profiles <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_profiles <- function(drill_con) {
  drill_server <- make_server(drill_con)
  res <- httr::GET(sprintf("%s/profiles.json", drill_server))
  cnt <- httr::content(res, as="text", encoding="UTF-8")
  jsonlite::fromJSON(cnt)


@@ 72,11 105,12 @@ drill_profiles <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://lo

#' Get the profile of the query that has the given queryid
#'
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @param query_id UUID of the query in standard UUID format that Drill assigns to each query
#' @param drill_server base URL of the \code{drill} server
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @export
drill_profile <- function(query_id, drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_profile <- function(drill_con, query_id) {
  drill_server <- make_server(drill_con)
  res <- httr::GET(sprintf("%s/profiles/%s.json", drill_server, query_id))
  cnt <- httr::content(res, as="text", encoding="UTF-8")
  jsonlite::fromJSON(cnt)


@@ 84,11 118,12 @@ drill_profile <- function(query_id, drill_server=Sys.getenv("DRILL_URL", unset="

#' Cancel the query that has the given queryid
#'
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @param query_id the UUID of the query in standard UUID format that Drill assigns to each query.
#' @param drill_server base URL of the \code{drill} server
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @export
drill_cancel <- function(query_id, drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
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))
  cnt <- httr::content(res, as="text", encoding="UTF-8")
  jsonlite::fromJSON(cnt)


@@ 101,9 136,11 @@ drill_cancel <- function(query_id, drill_server=Sys.getenv("DRILL_URL", unset="h
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @export
#' @examples \dontrun{
#' drill_storage()
#' drill_connection() %>% drill_storage()
#' }
drill_storage <- function(plugin=NULL, drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_storage <- function(drill_con, plugin=NULL) {

  drill_server <- make_server(drill_con)

  if (is.null(plugin)) {
    res <- httr::GET(sprintf("%s/storage.json", drill_server))


@@ 119,28 156,33 @@ drill_storage <- function(plugin=NULL, drill_server=Sys.getenv("DRILL_URL", unse

#' List the name, default, and data type of the system and session options
#'
#' @param drill_server base URL of the \code{drill} server
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @param pattern pattern to filter results by
#' @export
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @examples \dontrun{
#' drill_options()
#' drill_connection() %>% drill_options()
#' }
drill_options <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_options <- function(drill_con, pattern=NULL) {
  drill_server <- make_server(drill_con)
  res <- httr::GET(sprintf("%s/options.json", drill_server))
  cnt <- httr::content(res, as="text", encoding="UTF-8")
  jsonlite::fromJSON(cnt) %>%
    dplyr::tbl_df()
    dplyr::tbl_df() -> out
  if (!is.null(pattern)) out <- dplyr::filter(out, grepl(pattern, name))
  out
}

#' Get Drillbit information, such as ports numbers
#'
#' @param drill_server base URL of the \code{drill} server
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @export
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @examples \dontrun{
#' drill_stats()
#' drill_con() %>% drill_stats()
#' }
drill_stats <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_stats <- function(drill_con) {
  drill_server <- make_server(drill_con)
  res <- httr::GET(sprintf("%s/stats.json", drill_server))
  cnt <- httr::content(res, as="text", encoding="UTF-8")
  jsonlite::fromJSON(cnt)


@@ 148,12 190,12 @@ drill_stats <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://local

#' Identify the version of Drill running
#'
#' @param drill_server base URL of the \code{drill} server
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @export
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @examples \dontrun{
#' drill_version()
#' drill_connection() %>% drill_version()
#' }
drill_version <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
  drill_query("SELECT version FROM sys.version", uplift=FALSE, drill_server=drill_server)$rows$version[1]
drill_version <- function(drill_con) {
  drill_query(drill_con, "SELECT version FROM sys.version", uplift=FALSE)$rows$version[1]
}

M R/set.R => R/set.R +12 -13
@@ 6,17 6,17 @@
#'
#' If any query errors result, error messages will be presented to the console.
#'
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @param ... named parameters to be sent to ALTER [SYSTEM|SESSION]
#' @param type set the \code{session} or \code{system} parameter
#' @param drill_server base URL of the \code{drill} server
#' @return a \code{tbl} (invisibly) with the \code{ALTER} queries sent and results, including errors.
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @export
#' @examples \dontrun{
#' drill_set(exec.errors.verbose=TRUE, store.format="parquet", web.logs.max_lines=20000)
#' drill_connection() %>%
#'   drill_set(exec.errors.verbose=TRUE, store.format="parquet", web.logs.max_lines=20000)
#' }
drill_set <- function(..., type=c("session", "system"),
                      drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_set <- function(drill_con, ..., type=c("session", "system")) {

  type <- toupper(match.arg(tolower(type), choices=c("session", "system")))



@@ 26,7 26,7 @@ drill_set <- function(..., type=c("session", "system"),

  purrr::map2(names(params), params, ~sprintf("ALTER %s SET `%s` = %s", type, .x, .y)) %>%
    purrr::map_df(function(x) {
    y <- drill_query(x, drill_server=drill_server)
    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)
    } else {


@@ 51,23 51,22 @@ drill_set <- function(..., type=c("session", "system"),

#' Changes (optionally, all) system settings back to system defaults
#'
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @param ... bare name of system options to reset
#' @param all if \code{TRUE}, all parameters are reset (\code{...} is ignored)
#' @param drill_server base URL of the \code{drill} server
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @export
#' @examples \dontrun{
#' drill_system_reset(all=TRUE)
#' drill_connection() %>% drill_system_reset(all=TRUE)
#' }
drill_system_reset <- function(..., all=FALSE,
                               drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
drill_system_reset <- function(drill_con, ..., all=FALSE) {

  if (all) return(invisible(drill_query("ALTER SYSTEM RESET ALL", drill_server=drill_server)))

  as.list(substitute(list(...)))[-1L] %>%
  purrr::map(params, ~sprintf("ALTER SYSTEM RESET `%s`", .)) %>%
    purrr::map_df(function(x) {
    y <- drill_query(x, drill_server=drill_server)
    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)
    } else {


@@ 93,12 92,12 @@ drill_system_reset <- function(..., all=FALSE,

#' Changes (optionally, all) session settings back to system defaults
#'
#' @param drill_con drill server connection object setup by \code{drill_connection()}
#' @param ... bare name of system options to reset
#' @param drill_server base URL of the \code{drill} server
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @export
#' @examples \dontrun{
#' drill_settings_reset(exec.errors.verbose)
#' drill_connection() %>% drill_settings_reset(exec.errors.verbose)
#' }
drill_settings_reset <- function(...,
                               drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {


@@ 107,7 106,7 @@ drill_settings_reset <- function(...,
  as.list(substitute(list(...)))[-1L] %>%
  purrr::map(params, ~sprintf("ALTER SESSION RESET `%s`", .)) %>%
    purrr::map_df(function(x) {
    y <- drill_query(x, drill_server=drill_server)
    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)
    } else {

M README.Rmd => README.Rmd +14 -9
@@ 40,6 40,7 @@ Finally, I run most of this locally and at home, so it's all been coded with no 

The following functions are implemented:

- `drill_connection`: Setup parameters for a Drill server/cluster connection
- `drill_active`: Test whether Drill HTTP REST API server is up
- `drill_cancel`:	Cancel the query that has the given queryid
- `drill_metrics`:	Get the current memory metrics


@@ 78,33 79,37 @@ library(sergeant)
# current verison
packageVersion("sergeant")

drill_active()
dc <- drill_connection() 

drill_version()
drill_active(dc)

drill_storage()$name
drill_version(dc)

drill_storage(dc)$name
```

Working with the built-in JSON data sets:

```{r}
drill_query("SELECT * FROM cp.`employee.json` limit 100")
drill_query(dc, "SELECT * FROM cp.`employee.json` limit 100")

drill_query(dc, "SELECT COUNT(gender) AS gender FROM cp.`employee.json` GROUP BY gender")

drill_query("SELECT COUNT(gender) AS gender FROM cp.`employee.json` GROUP BY gender")
drill_options(dc)

drill_options()
drill_options(dc, "json")
```

## Working with parquet files

```{r}
drill_query("SELECT * FROM dfs.`/usr/local/drill/sample-data/nation.parquet` LIMIT 5")
drill_query(dc, "SELECT * FROM dfs.`/usr/local/drill/sample-data/nation.parquet` LIMIT 5")
```

Including multiple parquet files in different directories (note the wildcard support):

```{r}
drill_query("SELECT * FROM dfs.`/usr/local/drill/sample-data/nations*/nations*.parquet` LIMIT 5")
drill_query(dc, "SELECT * FROM dfs.`/usr/local/drill/sample-data/nations*/nations*.parquet` LIMIT 5")
```

### A preview of the built-in support for spatial ops


@@ 114,7 119,7 @@ Via: <https://github.com/k255/drill-gis>
A common use case is to select data within boundary of given polygon:

```{r}
drill_query("
drill_query(dc, "
select columns[2] as city, columns[4] as lon, columns[3] as lat
    from cp.`sample-data/CA-cities.csv`
    where

M README.md => README.md +35 -10
@@ 28,6 28,7 @@ Finally, I run most of this locally and at home, so it's all been coded with no 

The following functions are implemented:

-   `drill_connection`: Setup parameters for a Drill server/cluster connection
-   `drill_active`: Test whether Drill HTTP REST API server is up
-   `drill_cancel`: Cancel the query that has the given queryid
-   `drill_metrics`: Get the current memory metrics


@@ 63,20 64,26 @@ library(sergeant)
packageVersion("sergeant")
#> [1] '0.1.0.9000'

drill_active()
dc <- drill_connection() 

drill_active(dc)
#> http://localhost:8047
#> [1] TRUE

drill_version()
drill_version(dc)
#> http://localhost:8047
#> [1] "1.9.0"

drill_storage()$name
drill_storage(dc)$name
#> http://localhost:8047
#> [1] "cp"    "dfs"   "hbase" "hive"  "kudu"  "mongo" "s3"
```

Working with the built-in JSON data sets:

``` r
drill_query("SELECT * FROM cp.`employee.json` limit 100")
drill_query(dc, "SELECT * FROM cp.`employee.json` limit 100")
#> http://localhost:8047
#> Parsed with column specification:
#> cols(
#>   store_id = col_integer(),


@@ 112,7 119,8 @@ drill_query("SELECT * FROM cp.`employee.json` limit 100")
#> # ... with 90 more rows, and 7 more variables: salary <dbl>, marital_status <chr>, full_name <chr>, employee_id <int>,
#> #   education_level <chr>, first_name <chr>, position_id <int>

drill_query("SELECT COUNT(gender) AS gender FROM cp.`employee.json` GROUP BY gender")
drill_query(dc, "SELECT COUNT(gender) AS gender FROM cp.`employee.json` GROUP BY gender")
#> http://localhost:8047
#> Parsed with column specification:
#> cols(
#>   gender = col_integer()


@@ 123,7 131,8 @@ drill_query("SELECT COUNT(gender) AS gender FROM cp.`employee.json` GROUP BY gen
#> 1    601
#> 2    554

drill_options()
drill_options(dc)
#> http://localhost:8047
#> # A tibble: 105 × 4
#>                                              name value   type    kind
#> *                                           <chr> <chr>  <chr>   <chr>


@@ 138,13 147,27 @@ drill_options()
#> 9                     planner.enable_mux_exchange  TRUE SYSTEM BOOLEAN
#> 10                   store.parquet.use_new_reader FALSE SYSTEM BOOLEAN
#> # ... with 95 more rows

drill_options(dc, "json")
#> http://localhost:8047
#> # A tibble: 7 × 4
#>                                                    name value   type    kind
#>                                                   <chr> <chr>  <chr>   <chr>
#> 1                     store.json.read_numbers_as_double FALSE SYSTEM BOOLEAN
#> 2                             store.json.extended_types FALSE SYSTEM BOOLEAN
#> 3                              store.json.writer.uglify FALSE SYSTEM BOOLEAN
#> 4                store.json.reader.skip_invalid_records  TRUE SYSTEM BOOLEAN
#> 5 store.json.reader.print_skipped_invalid_record_number  TRUE SYSTEM BOOLEAN
#> 6                              store.json.all_text_mode  TRUE SYSTEM BOOLEAN
#> 7                    store.json.writer.skip_null_fields  TRUE SYSTEM BOOLEAN
```

Working with parquet files
--------------------------

``` r
drill_query("SELECT * FROM dfs.`/usr/local/drill/sample-data/nation.parquet` LIMIT 5")
drill_query(dc, "SELECT * FROM dfs.`/usr/local/drill/sample-data/nation.parquet` LIMIT 5")
#> http://localhost:8047
#> Parsed with column specification:
#> cols(
#>   N_COMMENT = col_character(),


@@ 165,7 188,8 @@ drill_query("SELECT * FROM dfs.`/usr/local/drill/sample-data/nation.parquet` LIM
Including multiple parquet files in different directories (note the wildcard support):

``` r
drill_query("SELECT * FROM dfs.`/usr/local/drill/sample-data/nations*/nations*.parquet` LIMIT 5")
drill_query(dc, "SELECT * FROM dfs.`/usr/local/drill/sample-data/nations*/nations*.parquet` LIMIT 5")
#> http://localhost:8047
#> Parsed with column specification:
#> cols(
#>   N_COMMENT = col_character(),


@@ 191,7 215,7 @@ Via: <https://github.com/k255/drill-gis>
A common use case is to select data within boundary of given polygon:

``` r
drill_query("
drill_query(dc, "
select columns[2] as city, columns[4] as lon, columns[3] as lat
    from cp.`sample-data/CA-cities.csv`
    where


@@ 202,6 226,7 @@ select columns[2] as city, columns[4] as lon, columns[3] as lat
                )
            )
")
#> http://localhost:8047
#> Parsed with column specification:
#> cols(
#>   city = col_character(),


@@ 227,7 252,7 @@ library(sergeant)
library(testthat)

date()
#> [1] "Sat Dec  3 14:25:31 2016"
#> [1] "Mon Dec  5 10:12:22 2016"

test_dir("tests/")
#> testthat results ========================================================================================================

M man/drill_active.Rd => man/drill_active.Rd +4 -5
@@ 4,18 4,17 @@
\alias{drill_active}
\title{Test whether Drill HTTP REST API server is up}
\usage{
drill_active(drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_active(drill_con)
}
\arguments{
\item{drill_server}{base URL of the \code{drill} server}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}
}
\description{
This is a very simple test (performs \code{HEAD /} on \code{drill_server}
This is a very simple test (performs \code{HEAD /} request on the Drill server/cluster)
}
\examples{
\dontrun{
drill_active()
drill_connection() \%>\% drill_active()
}
}


M man/drill_cancel.Rd => man/drill_cancel.Rd +3 -4
@@ 4,13 4,12 @@
\alias{drill_cancel}
\title{Cancel the query that has the given queryid}
\usage{
drill_cancel(query_id, drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_cancel(drill_con, query_id)
}
\arguments{
\item{query_id}{the UUID of the query in standard UUID format that Drill assigns to each query.}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}

\item{drill_server}{base URL of the \code{drill} server}
\item{query_id}{the UUID of the query in standard UUID format that Drill assigns to each query.}
}
\description{
Cancel the query that has the given queryid

A man/drill_connection.Rd => man/drill_connection.Rd +29 -0
@@ 0,0 1,29 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sergeant.r
\name{drill_connection}
\alias{drill_connection}
\title{Setup a Drill connection}
\usage{
drill_connection(host = Sys.getenv("DRILL_HOST", "localhost"),
  port = Sys.getenv("DRILL_PORT", 8047), ssl = FALSE,
  user = Sys.getenv("DRILL_USER", ""),
  password = Sys.getenv("DRILL_PASSWORD", ""))
}
\arguments{
\item{host}{Drill host (will pick up the value from \code{DRILL_HOST} env var)}

\item{port}{Drill port (will pick up the value from \code{DRILL_POST} env var)}

\item{ssl}{use ssl?}

\item{user, password}{NOT IMPLEMENTED YET credentials for username/password auth.
(will pick up the values from \code{DRILL_USER}/\code{DRILL_PASSWORD}
env vars)}
}
\description{
Setup a Drill connection
}
\examples{
dc <- drill_connection()
}


M man/drill_metrics.Rd => man/drill_metrics.Rd +3 -4
@@ 4,18 4,17 @@
\alias{drill_metrics}
\title{Get the current memory metrics}
\usage{
drill_metrics(drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_metrics(drill_con)
}
\arguments{
\item{drill_server}{base URL of the \code{drill} server}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}
}
\description{
Get the current memory metrics
}
\examples{
\dontrun{
drill_metrics()
drill_connection() \%>\% drill_metrics()
}
}


M man/drill_options.Rd => man/drill_options.Rd +5 -4
@@ 4,18 4,19 @@
\alias{drill_options}
\title{List the name, default, and data type of the system and session options}
\usage{
drill_options(drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_options(drill_con, pattern = NULL)
}
\arguments{
\item{drill_server}{base URL of the \code{drill} server}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}

\item{pattern}{pattern to filter results by}
}
\description{
List the name, default, and data type of the system and session options
}
\examples{
\dontrun{
drill_options()
drill_connection() \%>\% drill_options()
}
}
\references{

M man/drill_profile.Rd => man/drill_profile.Rd +3 -4
@@ 4,13 4,12 @@
\alias{drill_profile}
\title{Get the profile of the query that has the given queryid}
\usage{
drill_profile(query_id, drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_profile(drill_con, query_id)
}
\arguments{
\item{query_id}{UUID of the query in standard UUID format that Drill assigns to each query}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}

\item{drill_server}{base URL of the \code{drill} server}
\item{query_id}{UUID of the query in standard UUID format that Drill assigns to each query}
}
\description{
Get the profile of the query that has the given queryid

M man/drill_profiles.Rd => man/drill_profiles.Rd +3 -4
@@ 4,18 4,17 @@
\alias{drill_profiles}
\title{Get the profiles of running and completed queries}
\usage{
drill_profiles(drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_profiles(drill_con)
}
\arguments{
\item{drill_server}{base URL of the \code{drill} server}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}
}
\description{
Get the profiles of running and completed queries
}
\examples{
\dontrun{
drill_profiles()
drill_connection() \%>\% drill_profiles()
}
}
\references{

M man/drill_query.Rd => man/drill_query.Rd +4 -5
@@ 4,24 4,23 @@
\alias{drill_query}
\title{Submit a query and return results}
\usage{
drill_query(query, uplift = TRUE, .progress = FALSE,
  drill_server = Sys.getenv("DRILL_URL", unset = "http://localhost:8047"))
drill_query(drill_con, query, uplift = TRUE, .progress = FALSE)
}
\arguments{
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}

\item{query}{query to run}

\item{uplift}{automatically run \code{drill_uplift()} on the result?}

\item{.progress}{if \code{TRUE} then ask \code{httr::PSOT} to display a progress bar}

\item{drill_server}{base URL of the \code{drill} server}
}
\description{
Submit a query and return results
}
\examples{
\dontrun{
drill_query("SELECT * FROM cp.`employee.json` limit 5")
drill_con() \%>\% drill_query("SELECT * FROM cp.`employee.json` limit 5")
}
}
\references{

M man/drill_set.Rd => man/drill_set.Rd +5 -5
@@ 4,15 4,14 @@
\alias{drill_set}
\title{Set Drill SYSTEM or SESSION options}
\usage{
drill_set(..., type = c("session", "system"),
  drill_server = Sys.getenv("DRILL_URL", unset = "http://localhost:8047"))
drill_set(drill_con, ..., type = c("session", "system"))
}
\arguments{
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}

\item{...}{named parameters to be sent to ALTER [SYSTEM|SESSION]}

\item{type}{set the \code{session} or \code{system} parameter}

\item{drill_server}{base URL of the \code{drill} server}
}
\value{
a \code{tbl} (invisibly) with the \code{ALTER} queries sent and results, including errors.


@@ 27,7 26,8 @@ If any query errors result, error messages will be presented to the console.
}
\examples{
\dontrun{
drill_set(exec.errors.verbose=TRUE, store.format="parquet", web.logs.max_lines=20000)
drill_connection() \%>\%
  drill_set(exec.errors.verbose=TRUE, store.format="parquet", web.logs.max_lines=20000)
}
}
\references{

M man/drill_settings_reset.Rd => man/drill_settings_reset.Rd +2 -2
@@ 10,14 10,14 @@ drill_settings_reset(..., drill_server = Sys.getenv("DRILL_URL", unset =
\arguments{
\item{...}{bare name of system options to reset}

\item{drill_server}{base URL of the \code{drill} server}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}
}
\description{
Changes (optionally, all) session settings back to system defaults
}
\examples{
\dontrun{
drill_settings_reset(exec.errors.verbose)
drill_connection() \%>\% drill_settings_reset(exec.errors.verbose)
}
}
\references{

M man/drill_show_files.Rd => man/drill_show_files.Rd +4 -6
@@ 4,21 4,19 @@
\alias{drill_show_files}
\title{Show files in a file system schema.}
\usage{
drill_show_files(schema_spec, drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_show_files(drill_con, schema_spec)
}
\arguments{
\item{schema_spec}{properly quoted "filesystem.directory_name" reference path}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}

\item{drill_server}{base URL of the \code{drill} server}
\item{schema_spec}{properly quoted "filesystem.directory_name" reference path}
}
\description{
Show files in a file system schema.
}
\examples{
\dontrun{
drill_show_files("dfs.tmp")
drill_show_files("dfs.tmp")
drill_con() \%>\% drill_show_files("dfs.tmp")
}
}
\references{

M man/drill_show_schemas.Rd => man/drill_show_schemas.Rd +2 -3
@@ 4,11 4,10 @@
\alias{drill_show_schemas}
\title{Returns a list of available schemas.}
\usage{
drill_show_schemas(drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_show_schemas(drill_con)
}
\arguments{
\item{drill_server}{base URL of the \code{drill} server}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}
}
\description{
Returns a list of available schemas.

M man/drill_stats.Rd => man/drill_stats.Rd +3 -4
@@ 4,18 4,17 @@
\alias{drill_stats}
\title{Get Drillbit information, such as ports numbers}
\usage{
drill_stats(drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_stats(drill_con)
}
\arguments{
\item{drill_server}{base URL of the \code{drill} server}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}
}
\description{
Get Drillbit information, such as ports numbers
}
\examples{
\dontrun{
drill_stats()
drill_con() \%>\% drill_stats()
}
}
\references{

M man/drill_status.Rd => man/drill_status.Rd +3 -4
@@ 4,11 4,10 @@
\alias{drill_status}
\title{Get the status of Drill}
\usage{
drill_status(drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_status(drill_con)
}
\arguments{
\item{drill_server}{base URL of the \code{drill} server}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}
}
\description{
Get the status of Drill


@@ 18,7 17,7 @@ The output of this is in a "viewer" window
}
\examples{
\dontrun{
drill_status()
drill_connection() \%>\% drill_status()
}
}


M man/drill_storage.Rd => man/drill_storage.Rd +2 -3
@@ 4,8 4,7 @@
\alias{drill_storage}
\title{Get the list of storage plugin names and configurations}
\usage{
drill_storage(plugin = NULL, drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_storage(drill_con, plugin = NULL)
}
\arguments{
\item{plugin}{the assigned name in the storage plugin definition.}


@@ 17,7 16,7 @@ Get the list of storage plugin names and configurations
}
\examples{
\dontrun{
drill_storage()
drill_connection() \%>\% drill_storage()
}
}
\references{

M man/drill_system_reset.Rd => man/drill_system_reset.Rd +4 -5
@@ 4,22 4,21 @@
\alias{drill_system_reset}
\title{Changes (optionally, all) system settings back to system defaults}
\usage{
drill_system_reset(..., all = FALSE, drill_server = Sys.getenv("DRILL_URL",
  unset = "http://localhost:8047"))
drill_system_reset(drill_con, ..., all = FALSE)
}
\arguments{
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}

\item{...}{bare name of system options to reset}

\item{all}{if \code{TRUE}, all parameters are reset (\code{...} is ignored)}

\item{drill_server}{base URL of the \code{drill} server}
}
\description{
Changes (optionally, all) system settings back to system defaults
}
\examples{
\dontrun{
drill_system_reset(all=TRUE)
drill_connection() \%>\% drill_system_reset(all=TRUE)
}
}
\references{

M man/drill_threads.Rd => man/drill_threads.Rd +3 -4
@@ 4,11 4,10 @@
\alias{drill_threads}
\title{Get information about threads}
\usage{
drill_threads(drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_threads(drill_con)
}
\arguments{
\item{drill_server}{base URL of the \code{drill} server}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}
}
\description{
Get information about threads


@@ 18,7 17,7 @@ The output of this is in a "viewer" window
}
\examples{
\dontrun{
drill_threads()
drill_connection() \%>\% drill_threads()
}
}


M man/drill_use.Rd => man/drill_use.Rd +3 -4
@@ 4,14 4,13 @@
\alias{drill_use}
\title{Change to a particular schema.}
\usage{
drill_use(schema_name, drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_use(drill_con, schema_name)
}
\arguments{
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}

\item{schema_name}{A unique name for a Drill schema. A schema in Drill is a configured
storage plugin, such as hive, or a storage plugin and workspace.}

\item{drill_server}{base URL of the \code{drill} server}
}
\description{
Change to a particular schema.

M man/drill_version.Rd => man/drill_version.Rd +3 -4
@@ 4,18 4,17 @@
\alias{drill_version}
\title{Identify the version of Drill running}
\usage{
drill_version(drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
drill_version(drill_con)
}
\arguments{
\item{drill_server}{base URL of the \code{drill} server}
\item{drill_con}{drill server connection object setup by \code{drill_connection()}}
}
\description{
Identify the version of Drill running
}
\examples{
\dontrun{
drill_version()
drill_connection() \%>\% drill_version()
}
}
\references{

A man/sergeant-exports.Rd => man/sergeant-exports.Rd +12 -0
@@ 0,0 1,12 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sergeant-package.r
\name{sergeant-exports}
\alias{\%>\%}
\alias{sergeant-exports}
\title{sergeant exported operators}
\description{
The following functions are imported and then re-exported
from the sergeant package to enable use of the magrittr
pipe operator with no additional library calls
}