Skip to content

Commit

Permalink
test: Enable remaining Arrow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Dec 16, 2023
1 parent 89ea7a6 commit 1f0eab0
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 82 deletions.
174 changes: 92 additions & 82 deletions R/spec-arrow-send-query-arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,88 +41,98 @@ spec_arrow_send_query_arrow <- list(
expect_error(dbSendQueryArrow(con, NA_character_))
},

# FIXME: Enable

# arrow_send_query_syntax_error = function(con) {
# #' An error is also raised if the syntax of the query is invalid
# #' and all query parameters are given (by passing the `params` argument)
# #' or the `immediate` argument is set to `TRUE`.
# #'
# #' @section Failure modes:
# expect_error(dbSendQueryArrow(con, "SELLECT", params = list()))
# expect_error(dbSendQueryArrow(con, "SELLECT", immediate = TRUE))
# },
# #' @section Additional arguments:
# #' The following arguments are not part of the `dbSendQueryArrow()` generic
# #' (to improve compatibility across backends)
# #' but are part of the DBI specification:
# #' - `params` (default: `NULL`)
# #' - `immediate` (default: `NULL`)
# #'
# #' They must be provided as named arguments.
# #' See the "Specification" sections for details on their usage.
#
# arrow_send_query_result_valid = function(con) {
# #' @section Specification:
# #' No warnings occur under normal conditions.
# expect_warning(res <- dbSendQueryArrow(con, trivial_query()), NA)
# #' When done, the DBIResult object must be cleared with a call to
# #' [dbClearResult()].
# dbClearResult(res)
# },
# #
# arrow_send_query_stale_warning = function(ctx) {
# #' Failure to clear the result set leads to a warning
# #' when the connection is closed.
# con <- connect(ctx)
# on.exit(dbDisconnect(con))
# expect_warning(dbSendQueryArrow(con, trivial_query()), NA)
#
# expect_warning({
# dbDisconnect(con)
# gc()
# })
# on.exit(NULL)
# },
#
# #'
# arrow_send_query_only_one_result_set = function(con) {
# #' If the backend supports only one open result set per connection,
# res1 <- dbSendQueryArrow(con, trivial_query())
# #' issuing a second query invalidates an already open result set
# #' and raises a warning.
# expect_warning(res2 <- dbSendQueryArrow(con, "SELECT 2"))
# expect_false(dbIsValid(res1))
# #' The newly opened result set is valid
# expect_true(dbIsValid(res2))
# #' and must be cleared with `dbClearResult()`.
# dbClearResult(res2)
# },
#
# #'
# arrow_send_query_params = function(ctx, con) {
# #' The `param` argument allows passing query parameters, see [dbBind()] for details.
# placeholder_funs <- get_placeholder_funs(ctx)
#
# for (placeholder_fun in placeholder_funs) {
# placeholder <- placeholder_fun(1)
# query <- paste0("SELECT ", placeholder, " + 1.0 AS a")
# values <- trivial_values(3) - 1
# params <- stats::setNames(list(values), names(placeholder))
# rs <- dbSendQueryArrow(con, query, params = params)
# ret <- dbFetch(rs)
# expect_equal(ret, trivial_df(3), info = placeholder)
# dbClearResult(rs)
# }
# },
#
# arrow_send_query_immediate = function(con, table_name) {
# #' @inheritSection spec_result_get_query Specification for the `immediate` argument
# res <- expect_visible(dbSendQueryArrow(con, trivial_query(), immediate = TRUE))
# expect_s4_class(res, "DBIResult")
# expect_error(dbGetRowsAffected(res), NA)
# dbClearResult(res)
# },
arrow_send_query_syntax_error = function(ctx, con) {
skip_if_not_dbitest(ctx, "1.7.99.5")

#' An error is also raised if the syntax of the query is invalid
#' and all query parameters are given (by passing the `params` argument)
#' or the `immediate` argument is set to `TRUE`.
#'
#' @section Failure modes:
expect_error(dbSendQueryArrow(con, "SELLECT", params = list()))
expect_error(dbSendQueryArrow(con, "SELLECT", immediate = TRUE))
},
#' @section Additional arguments:
#' The following arguments are not part of the `dbSendQueryArrow()` generic
#' (to improve compatibility across backends)
#' but are part of the DBI specification:
#' - `params` (default: `NULL`)
#' - `immediate` (default: `NULL`)
#'
#' They must be provided as named arguments.
#' See the "Specification" sections for details on their usage.

arrow_send_query_result_valid = function(ctx, con) {
skip_if_not_dbitest(ctx, "1.7.99.6")

#' @section Specification:
#' No warnings occur under normal conditions.
expect_warning(res <- dbSendQueryArrow(con, trivial_query()), NA)
#' When done, the DBIResult object must be cleared with a call to
#' [dbClearResult()].
dbClearResult(res)
},
#
arrow_send_query_stale_warning = function(ctx) {
skip_if_not_dbitest(ctx, "1.7.99.7")

#' Failure to clear the result set leads to a warning
#' when the connection is closed.
con <- connect(ctx)
on.exit(dbDisconnect(con))
expect_warning(dbSendQueryArrow(con, trivial_query()), NA)

expect_warning({
dbDisconnect(con)
gc()
})
on.exit(NULL)
},

#'
arrow_send_query_only_one_result_set = function(ctx, con) {
skip_if_not_dbitest(ctx, "1.7.99.8")

#' If the backend supports only one open result set per connection,
res1 <- dbSendQueryArrow(con, trivial_query())
#' issuing a second query invalidates an already open result set
#' and raises a warning.
expect_warning(res2 <- dbSendQueryArrow(con, "SELECT 2"))
expect_false(dbIsValid(res1))
#' The newly opened result set is valid
expect_true(dbIsValid(res2))
#' and must be cleared with `dbClearResult()`.
dbClearResult(res2)
},

#'
arrow_send_query_params = function(ctx, con) {
skip_if_not_dbitest(ctx, "1.7.99.9")

#' The `param` argument allows passing query parameters, see [dbBind()] for details.
placeholder_funs <- get_placeholder_funs(ctx)

for (placeholder_fun in placeholder_funs) {
placeholder <- placeholder_fun(1)
query <- paste0("SELECT ", placeholder, " + 1.0 AS a")
values <- trivial_values(3) - 1
params <- stats::setNames(list(values), names(placeholder))
rs <- dbSendQueryArrow(con, query, params = params)
ret <- dbFetch(rs)
expect_equal(ret, trivial_df(3), info = placeholder)
dbClearResult(rs)
}
},

arrow_send_query_immediate = function(ctx, con, table_name) {
skip_if_not_dbitest(ctx, "1.7.99.10")

#' @inheritSection spec_result_get_query Specification for the `immediate` argument
res <- expect_visible(dbSendQueryArrow(con, trivial_query(), immediate = TRUE))
expect_s4_class(res, "DBIResultArrow")
expect_error(dbGetRowsAffected(res), NA)
dbClearResult(res)
},

NULL
)
78 changes: 78 additions & 0 deletions man/spec_arrow_send_query_arrow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f0eab0

Please sign in to comment.