~hrbrmstr/sergeant

7a0f124632b6192fe761e7334c9ee28dde3fd0b1 — Bob Rudis 4 years ago a811b87
tweaks
12 files changed, 121 insertions(+), 38 deletions(-)

M NAMESPACE
M R/query.r
M R/schemas.R
M R/set.R
M README.Rmd
M README.md
M man/drill_query.Rd
M man/drill_set.Rd
D man/drill_setting_reset.Rd
M man/drill_system_reset.Rd
M man/drill_uplift.Rd
M man/drill_version.Rd
M NAMESPACE => NAMESPACE +1 -1
@@ 7,7 7,7 @@ export(drill_profile)
export(drill_profiles)
export(drill_query)
export(drill_set)
export(drill_setting_reset)
export(drill_settings_reset)
export(drill_show_files)
export(drill_show_schemas)
export(drill_stats)

M R/query.r => R/query.r +8 -2
@@ 1,10 1,13 @@
#' Submit a query and return results
#'
#' @param query query to run
#' @param uplift automatically run `drill_uplift()` on the result?
#' @param uplift automatically run \code{drill_uplift()} on the result?
#' @param drill_server base URL of the \code{drill} server
#' @export
drill_query <- function(query, uplift=FALSE, drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
#' @examples \dontrun{
#' drill_query("SELECT * FROM cp.`employee.json` limit 5")
#' }
drill_query <- function(query, uplift=TRUE, drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {

  res <- httr::POST(sprintf("%s/query.json", drill_server),
                    encode="json",


@@ 29,6 32,9 @@ drill_query <- function(query, uplift=FALSE, drill_server=Sys.getenv("DRILL_URL"
#' you can pipe it to this function to pull out `rows` and automatically
#' type-convert it.
#'
#' Not really intended to be called directly, but useful if you ran \code{drill_query()}
#' without `uplift=TRUE` but want to then convert the structure.
#'
#' @param query_result the result of a call to `drill_query()`
#' @export
drill_uplift <- function(query_result) {

M R/schemas.R => R/schemas.R +0 -8
@@ 19,14 19,6 @@ drill_use <- function(schema_name, drill_server=Sys.getenv("DRILL_URL", unset="h
  invisible(out)
}

#' Identify the version of Drill running
#'
#' @param drill_server base URL of the \code{drill} server
#' @export
drill_version <- function(drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {
  drill_query("SELECT version FROM sys.version", drill_server=drill_server)$rows$version[1]
}

#' Show files in a file system schema.
#'
#' @param schema_spec properly quoted "filesystem.directory_name" reference path

M R/set.R => R/set.R +8 -2
@@ 6,7 6,7 @@
#'
#' If any query errors result, error messages will be presented to the console.
#'
#' @param ... named parameters to be sent to \code{ALTER [SYSTEM|SESSION]}
#' @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.


@@ 54,6 54,9 @@ drill_set <- function(..., type=c("session", "system"),
#' @param all if \code{TRUE}, all parameters are reset (\code{...} is ignored)
#' @param drill_server base URL of the \code{drill} server
#' @export
#' @examples \dontrun{
#' drill_system_reset(all=TRUE)
#' }
drill_system_reset <- function(..., all=FALSE,
                               drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {



@@ 91,7 94,10 @@ drill_system_reset <- function(..., all=FALSE,
#' @param ... bare name of system options to reset
#' @param drill_server base URL of the \code{drill} server
#' @export
drill_setting_reset <- function(...,
#' @examples \dontrun{
#' drill_settings_reset(exec.errors.verbose)
#' }
drill_settings_reset <- function(...,
                               drill_server=Sys.getenv("DRILL_URL", unset="http://localhost:8047")) {



M README.Rmd => README.Rmd +10 -1
@@ 29,7 29,7 @@ The following functions are implemented:
- `drill_profiles`:	Get the profiles of running and completed queries
- `drill_query`:	Submit a query and return results
- `drill_set`:	Set Drill SYSTEM or SESSION options
- `drill_setting_reset`:	Changes (optionally, all) session settings back to system defaults
- `drill_settings_reset`:	Changes (optionally, all) session settings back to system defaults
- `drill_show_files`:	Show files in a file system schema.
- `drill_show_schemas`:	Returns a list of available schemas.
- `drill_stats`:	Get Drillbit information, such as ports numbers


@@ 59,6 59,15 @@ library(sergeant)
# current verison
packageVersion("sergeant")

drill_version()

drill_storage()$name

drill_query("SELECT * FROM cp.`employee.json` limit 100")

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

drill_options()
```

### Test Results

M README.md => README.md +71 -2
@@ 17,7 17,7 @@ The following functions are implemented:
-   `drill_profiles`: Get the profiles of running and completed queries
-   `drill_query`: Submit a query and return results
-   `drill_set`: Set Drill SYSTEM or SESSION options
-   `drill_setting_reset`: Changes (optionally, all) session settings back to system defaults
-   `drill_settings_reset`: Changes (optionally, all) session settings back to system defaults
-   `drill_show_files`: Show files in a file system schema.
-   `drill_show_schemas`: Returns a list of available schemas.
-   `drill_stats`: Get Drillbit information, such as ports numbers


@@ 43,6 43,75 @@ library(sergeant)
# current verison
packageVersion("sergeant")
#> [1] '0.1.0.9000'

drill_version()
#> [1] "1.9.0"

drill_storage()$name
#> [1] "cp"    "dfs"   "hbase" "hive"  "kudu"  "mongo" "s3"

drill_query("SELECT * FROM cp.`employee.json` limit 100")
#> Parsed with column specification:
#> cols(
#>   store_id = col_integer(),
#>   gender = col_character(),
#>   department_id = col_integer(),
#>   birth_date = col_date(format = ""),
#>   supervisor_id = col_integer(),
#>   last_name = col_character(),
#>   position_title = col_character(),
#>   hire_date = col_datetime(format = ""),
#>   management_role = col_character(),
#>   salary = col_double(),
#>   marital_status = col_character(),
#>   full_name = col_character(),
#>   employee_id = col_integer(),
#>   education_level = col_character(),
#>   first_name = col_character(),
#>   position_id = col_integer()
#> )
#> # A tibble: 100 × 16
#>    store_id gender department_id birth_date supervisor_id last_name         position_title  hire_date   management_role
#> *     <int>  <chr>         <int>     <date>         <int>     <chr>                  <chr>     <dttm>             <chr>
#> 1         0      F             1 1961-08-26             0    Nowmer              President 1994-12-01 Senior Management
#> 2         0      M             1 1915-07-03             1   Whelply     VP Country Manager 1994-12-01 Senior Management
#> 3         0      M             1 1969-06-20             1    Spence     VP Country Manager 1998-01-01 Senior Management
#> 4         0      F             1 1951-05-10             1 Gutierrez     VP Country Manager 1998-01-01 Senior Management
#> 5         0      F             2 1942-10-08             1   Damstra VP Information Systems 1994-12-01 Senior Management
#> 6         0      F             3 1949-03-27             1  Kanagaki     VP Human Resources 1994-12-01 Senior Management
#> 7         9      F            11 1922-08-10             5   Brunner          Store Manager 1998-01-01  Store Management
#> 8        21      F            11 1979-06-23             5  Blumberg          Store Manager 1998-01-01  Store Management
#> 9         0      M             5 1949-08-26             1     Stanz             VP Finance 1994-12-01 Senior Management
#> 10        1      M            11 1967-06-20             5  Murraiin          Store Manager 1998-01-01  Store Management
#> # ... 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")
#> Parsed with column specification:
#> cols(
#>   gender = col_integer()
#> )
#> # A tibble: 2 × 1
#>   gender
#> *  <int>
#> 1    601
#> 2    554

drill_options()
#> # A tibble: 105 × 4
#>                                              name value   type    kind
#> *                                           <chr> <chr>  <chr>   <chr>
#> 1                  planner.enable_hash_single_key  TRUE SYSTEM BOOLEAN
#> 2              planner.enable_limit0_optimization FALSE SYSTEM BOOLEAN
#> 3               store.json.read_numbers_as_double FALSE SYSTEM BOOLEAN
#> 4                 planner.enable_constant_folding  TRUE SYSTEM BOOLEAN
#> 5                       store.json.extended_types FALSE SYSTEM BOOLEAN
#> 6    planner.memory.non_blocking_operators_memory    64 SYSTEM    LONG
#> 7                   planner.enable_multiphase_agg  TRUE SYSTEM BOOLEAN
#> 8  planner.filter.max_selectivity_estimate_factor     1 SYSTEM  DOUBLE
#> 9                     planner.enable_mux_exchange  TRUE SYSTEM BOOLEAN
#> 10                   store.parquet.use_new_reader FALSE SYSTEM BOOLEAN
#> # ... with 95 more rows
```

### Test Results


@@ 52,7 121,7 @@ library(sergeant)
library(testthat)

date()
#> [1] "Sat Dec  3 11:28:51 2016"
#> [1] "Sat Dec  3 12:35:10 2016"

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

M man/drill_query.Rd => man/drill_query.Rd +7 -2
@@ 4,17 4,22 @@
\alias{drill_query}
\title{Submit a query and return results}
\usage{
drill_query(query, uplift = FALSE, drill_server = Sys.getenv("DRILL_URL",
drill_query(query, uplift = TRUE, drill_server = Sys.getenv("DRILL_URL",
  unset = "http://localhost:8047"))
}
\arguments{
\item{query}{query to run}

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

\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")
}
}


M man/drill_set.Rd => man/drill_set.Rd +1 -1
@@ 8,7 8,7 @@ drill_set(..., type = c("session", "system"),
  drill_server = Sys.getenv("DRILL_URL", unset = "http://localhost:8047"))
}
\arguments{
\item{...}{named parameters to be sent to \code{ALTER [SYSTEM|SESSION]}}
\item{...}{named parameters to be sent to ALTER [SYSTEM|SESSION]}

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


D man/drill_setting_reset.Rd => man/drill_setting_reset.Rd +0 -18
@@ 1,18 0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/set.R
\name{drill_setting_reset}
\alias{drill_setting_reset}
\title{Changes (optionally, all) session settings back to system defaults}
\usage{
drill_setting_reset(..., drill_server = Sys.getenv("DRILL_URL", unset =
  "http://localhost:8047"))
}
\arguments{
\item{...}{bare name of system options to reset}

\item{drill_server}{base URL of the \code{drill} server}
}
\description{
Changes (optionally, all) session settings back to system defaults
}


M man/drill_system_reset.Rd => man/drill_system_reset.Rd +5 -0
@@ 17,4 17,9 @@ drill_system_reset(..., all = FALSE, drill_server = Sys.getenv("DRILL_URL",
\description{
Changes (optionally, all) system settings back to system defaults
}
\examples{
\dontrun{
drill_system_reset(all=TRUE)
}
}


M man/drill_uplift.Rd => man/drill_uplift.Rd +4 -0
@@ 14,4 14,8 @@ If you know the result of `drill_query()` will be a data frame, then
you can pipe it to this function to pull out `rows` and automatically
type-convert it.
}
\details{
Not really intended to be called directly, but useful if you ran \code{drill_query()}
without `uplift=TRUE` but want to then convert the structure.
}


M man/drill_version.Rd => man/drill_version.Rd +6 -1
@@ 1,5 1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/schemas.R
% Please edit documentation in R/sergeant.r
\name{drill_version}
\alias{drill_version}
\title{Identify the version of Drill running}


@@ 13,4 13,9 @@ drill_version(drill_server = Sys.getenv("DRILL_URL", unset =
\description{
Identify the version of Drill running
}
\examples{
\dontrun{
drill_version()
}
}