Skip to content

Commit

Permalink
Merge pull request #99 from prestodb/support_s3_better
Browse files Browse the repository at this point in the history
Use the delayed registration mechanism in R-devel for dplyr method implementations
  • Loading branch information
onurfiliz authored Oct 23, 2018
2 parents e2193eb + 830d5d9 commit 6fa2e3b
Show file tree
Hide file tree
Showing 18 changed files with 283 additions and 347 deletions.
8 changes: 3 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: RPresto
Title: DBI Connector to Presto
Version: 1.3.1
Version: 1.3.2
Authors@R: c(
person('Onur Ismail', 'Filiz', , 'onur@fb.com', role=c('aut', 'cre')),
person('Sergey', 'Goder', , 'sgoder@fb.com', role='aut'),
Expand All @@ -25,7 +25,7 @@ Imports:
utils
Suggests:
testthat,
dplyr (>= 0.4.3),
dplyr (>= 0.7.0),
dbplyr
License: BSD_3_clause + file LICENSE
URL: https://github.com/prestodb/RPresto
Expand All @@ -41,6 +41,7 @@ Collate:
'PrestoCursor.R'
'PrestoResult.R'
'RcppExports.R'
'src.presto.R'
'copy.to.src.presto.R'
'db.data.type.PrestoConnection.R'
'dbplyr_compatible.R'
Expand Down Expand Up @@ -70,10 +71,7 @@ Collate:
'db_query_fields.R'
'fetch.R'
'help.R'
'src.translate.env.src.presto.R'
'sql_translate_env.R'
'src.desc.src.presto.R'
'src.presto.R'
'tbl.src.presto.R'
RoxygenNote: 6.1.0
LinkingTo: Rcpp
58 changes: 48 additions & 10 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,17 +1,55 @@
# Generated by roxygen2: do not edit by hand


if (getRversion() >= "3.6.0") {
S3method(dplyr::copy_to,src_presto)
} else {
export(copy_to.src_presto)
}

if (getRversion() >= "3.6.0") {
S3method(dplyr::db_data_type,PrestoConnection)
} else {
export(db_data_type.PrestoConnection)
}

if (getRversion() >= "3.6.0") {
S3method(dplyr::db_desc,PrestoConnection)
} else {
export(db_desc.PrestoConnection)
}

if (getRversion() >= "3.6.0") {
S3method(dplyr::db_explain,PrestoConnection)
} else {
export(db_explain.PrestoConnection)
}

if (getRversion() >= "3.6.0") {
S3method(dplyr::db_query_fields,PrestoConnection)
} else {
export(db_query_fields.PrestoConnection)
}

if (getRversion() >= "3.6.0") {
S3method(dplyr::db_query_rows,PrestoConnection)
} else {
export(db_query_rows.PrestoConnection)
}

if (getRversion() >= "3.6.0") {
S3method(dplyr::sql_translate_env,PrestoConnection)
} else {
export(sql_translate_env.PrestoConnection)
}

if (getRversion() >= "3.6.0") {
S3method(dplyr::tbl,src_presto)
} else {
export(tbl.src_presto)
}
export(Presto)
export(copy_to.src_presto)
export(db_data_type.PrestoConnection)
export(db_desc.PrestoConnection)
export(db_explain.PrestoConnection)
export(db_query_fields.PrestoConnection)
export(db_query_rows.PrestoConnection)
export(sql_translate_env.PrestoConnection)
export(src_desc.src_presto)
export(src_presto)
export(src_translate_env.src_presto)
export(tbl.src_presto)
exportClasses(PrestoConnection)
exportClasses(PrestoDriver)
exportClasses(PrestoResult)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# RPresto 1.3.2

- Use the new delayed S3 registration mechanism in 3.6.0 for dplyr method implementations.
- Bump minimum dplyr version required to 0.7.0.

# RPresto 1.3.1

- Presto now might return data in POST response (#89)
Expand Down
11 changes: 10 additions & 1 deletion R/copy.to.src.presto.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

#' @include src.presto.R
NULL

#' S3 implementation of \code{\link[dplyr]{copy_to}} for Presto.
#'
#' @rdname dplyr_function_implementations
#' @keywords internal
#' @export
#'
#' @rawNamespace
#' if (getRversion() >= "3.6.0") {
#' S3method(dplyr::copy_to,src_presto)
#' } else {
#' export(copy_to.src_presto)
#' }
copy_to.src_presto <- function(dest, df) {
stop("Not implemented.")
}
11 changes: 10 additions & 1 deletion R/db.data.type.PrestoConnection.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

#' @include PrestoConnection.R
NULL

#' S3 implementation of \code{\link[dplyr]{db_data_type}} for Presto.
#'
#' @rdname dplyr_function_implementations
#' @keywords internal
#' @export
#'
#' @rawNamespace
#' if (getRversion() >= "3.6.0") {
#' S3method(dplyr::db_data_type,PrestoConnection)
#' } else {
#' export(db_data_type.PrestoConnection)
#' }
db_data_type.PrestoConnection <- function(con, fields, ...) {
return(sapply(fields, function(field) dbDataType(Presto(), field)))
}
10 changes: 8 additions & 2 deletions R/db.explain.PrestoConnection.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

#' @include dbplyr_compatible.R
#' @include dbplyr_compatible.R PrestoConnection.R
NULL

#' S3 implementation of \code{\link[dplyr]{db_explain}} for Presto.
#'
#' @rdname dplyr_function_implementations
#' @keywords internal
#' @export
#'
#' @rawNamespace
#' if (getRversion() >= "3.6.0") {
#' S3method(dplyr::db_explain,PrestoConnection)
#' } else {
#' export(db_explain.PrestoConnection)
#' }
db_explain.PrestoConnection <- function(con, sql, ...) {
build_sql <- dbplyr_compatible('build_sql')
explain.sql <- build_sql("EXPLAIN ", sql)
Expand Down
11 changes: 10 additions & 1 deletion R/db.query.rows.PrestoConnection.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

#' @include PrestoConnection.R
NULL

#' S3 implementation of \code{\link[dplyr]{db_query_rows}} for Presto.
#'
#' @rdname dplyr_function_implementations
#' @keywords internal
#' @export
#'
#' @rawNamespace
#' if (getRversion() >= "3.6.0") {
#' S3method(dplyr::db_query_rows,PrestoConnection)
#' } else {
#' export(db_query_rows.PrestoConnection)
#' }
db_query_rows.PrestoConnection <- function(con, sql) {
# We shouldn't be doing a COUNT(*) over arbitrary tables because Hive tables
# can be prohibitively long. There may be something smarter we can do for
Expand Down
10 changes: 8 additions & 2 deletions R/db_desc.PrestoConnection.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

#' @include description_from_info.R
#' @include description_from_info.R PrestoConnection.R
NULL

#' S3 implementation of \code{db_desc} for Presto.
#'
#' @rdname dplyr_function_implementations
#' @keywords internal
#' @export
#'
#' @rawNamespace
#' if (getRversion() >= "3.6.0") {
#' S3method(dplyr::db_desc,PrestoConnection)
#' } else {
#' export(db_desc.PrestoConnection)
#' }
db_desc.PrestoConnection <- function(x) {
info <- dbGetInfo(x)
return(.description_from_info(info))
Expand Down
10 changes: 8 additions & 2 deletions R/db_query_fields.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

#' @include dbplyr_compatible.R
#' @include dbplyr_compatible.R PrestoConnection.R
NULL

#' S3 implementation of \code{db_query_fields} for Presto.
#'
#' @rdname dplyr_function_implementations
#' @keywords internal
#' @export
#'
#' @rawNamespace
#' if (getRversion() >= "3.6.0") {
#' S3method(dplyr::db_query_fields,PrestoConnection)
#' } else {
#' export(db_query_fields.PrestoConnection)
#' }
db_query_fields.PrestoConnection <- function(con, sql, ...) {
build_sql <- dbplyr_compatible('build_sql')
fields <- build_sql(
Expand Down
64 changes: 60 additions & 4 deletions R/sql_translate_env.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,70 @@
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

#' @include src.translate.env.src.presto.R
#' @include dbplyr_compatible.R PrestoConnection.R
NULL

presto_window_functions <- function() {
base_win <- dbplyr_compatible('base_win')
if (utils::packageVersion('dplyr') < '0.5.0.9004') {
return(base_win)
}
sql_translator <- dbplyr_compatible('sql_translator')
win_absent <- dbplyr_compatible('win_absent')
win_recycled <- dbplyr_compatible('win_recycled')
return(sql_translator(
.parent=base_win,
all=win_recycled('bool_and'),
any=win_recycled('bool_or'),
n_distinct=win_absent('n_distinct'),
sd=win_recycled("stddev_samp")
))
}

#' S3 implementation of \code{sql_translate_env} for Presto.
#'
#' @rdname dplyr_function_implementations
#' @keywords internal
#' @export
sql_translate_env.PrestoConnection <- function(conn) {
return(src_translate_env.src_presto(conn))
#'
#' @rawNamespace
#' if (getRversion() >= "3.6.0") {
#' S3method(dplyr::sql_translate_env,PrestoConnection)
#' } else {
#' export(sql_translate_env.PrestoConnection)
#' }
sql_translate_env.PrestoConnection <- function(con) {
sql_variant <- dbplyr_compatible('sql_variant')
sql_translator <- dbplyr_compatible('sql_translator')
sql_prefix <- dbplyr_compatible('sql_prefix')
sql <- dbplyr_compatible('sql')
build_sql <- dbplyr_compatible('build_sql')
base_scalar <- dbplyr_compatible('base_scalar')
base_agg <- dbplyr_compatible('base_agg')
return(sql_variant(
sql_translator(.parent = base_scalar,
ifelse = sql_prefix("if"),
as = function(column, type) {
sql_type <- stringi::stri_trans_toupper(
dbDataType(Presto(), type),
'en_US.UTF-8'
)
build_sql('CAST(', column, ' AS ', sql(sql_type), ')')
},
tolower = sql_prefix("lower"),
toupper = sql_prefix("upper"),
pmax = sql_prefix("greatest"),
pmin = sql_prefix("least"),
is.finite = sql_prefix("is_finite"),
is.infinite = sql_prefix("is_infinite"),
is.nan = sql_prefix("is_nan")
),
sql_translator(.parent = base_agg,
n = function() sql("count(*)"),
sd = sql_prefix("stddev_samp"),
var = sql_prefix("var_samp"),
all = sql_prefix("bool_and"),
any = sql_prefix("bool_or")
),
presto_window_functions()
))
}
20 changes: 0 additions & 20 deletions R/src.desc.src.presto.R

This file was deleted.

Loading

0 comments on commit 6fa2e3b

Please sign in to comment.