Skip to content

Commit

Permalink
sql_union()
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Oct 15, 2022
1 parent 07b00ec commit fc02c97
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export(package_name)
export(random_table_name)
export(s4_methods)
export(set_default_context)
export(sql_union)
export(test_all)
export(test_compliance)
export(test_connection)
Expand Down
4 changes: 2 additions & 2 deletions R/spec-meta-get-row-count.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec_meta_get_row_count <- list(
},
#
row_count_query_limited = function(ctx, con) {
query <- union(.ctx = ctx, trivial_query(), "SELECT 2", "SELECT 3")
query <- sql_union(.ctx = ctx, trivial_query(), "SELECT 2", "SELECT 3")
res <- local_result(dbSendQuery(con, query))
rc1 <- dbGetRowCount(res)
expect_equal(rc1, 0L)
Expand All @@ -44,7 +44,7 @@ spec_meta_get_row_count <- list(
#
row_count_query_empty = function(ctx, con) {
#' For queries with an empty result set,
query <- union(
query <- sql_union(
.ctx = ctx, "SELECT * FROM (SELECT 1 as a) a WHERE (0 = 1)"
)
res <- local_result(dbSendQuery(con, query))
Expand Down
2 changes: 1 addition & 1 deletion R/spec-result-fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ spec_result_fetch <- list(

fetch_multi_row_multi_column = function(ctx, con) {
#' or more columns by default returns the entire result.
query <- union(
query <- sql_union(
.ctx = ctx, paste("SELECT", 1:5 + 0.5, "AS a,", 4:0 + 0.5, "AS b"), .order_by = "a"
)

Expand Down
2 changes: 1 addition & 1 deletion R/spec-result-get-query.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ spec_result_get_query <- list(

get_query_multi_row_multi_column = function(ctx, con) {
#' or more columns returns the entire result.
query <- union(
query <- sql_union(
.ctx = ctx, paste("SELECT", 1:5 + 0.5, "AS a,", 4:0 + 0.5, "AS b"), .order_by = "a"
)

Expand Down
2 changes: 1 addition & 1 deletion R/spec-result-roundtrip.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ test_select <- function(con, ..., .dots = NULL, .add_null = "none",
query <- rev(query)
}
query <- paste0(query, ", ", 1:2, " as id")
query <- union(.ctx = .ctx, query)
query <- sql_union(.ctx = .ctx, query)
}

rows <- check_df(dbGetQuery(con, query))
Expand Down
5 changes: 3 additions & 2 deletions R/spec-result.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ spec_result <- c(

# Helpers -----------------------------------------------------------------

union <- function(..., .order_by = NULL, .ctx) {
#' @export
sql_union <- function(..., .order_by = NULL, .ctx) {
query <- .ctx$tweaks$union(c(...))

if (!missing(.order_by)) {
Expand All @@ -34,7 +35,7 @@ trivial_query <- function(n = 1L, column = "a", .order_by = NULL, .ctx = NULL) {
if (length(column) == n) {
query <- paste0("SELECT ", paste0(value, " AS ", column, collapse = ", "))
} else {
query <- union(
query <- sql_union(
paste0("SELECT ", value, " AS ", column),
.order_by = .order_by,
.ctx = .ctx
Expand Down
1 change: 1 addition & 0 deletions R/use.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use_dbitest <- function(path) {
"get_placeholder_funs",
"has_utf8_or_ascii_encoding",
#
"sql_union",
"trivial_query",
"trivial_df",
"trivial_values",
Expand Down

0 comments on commit fc02c97

Please sign in to comment.