-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathspec-arrow-fetch-arrow.R
98 lines (82 loc) · 3.08 KB
/
spec-arrow-fetch-arrow.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#' spec_arrow_fetch_arrow
#' @family Arrow specifications
#' @usage NULL
#' @format NULL
#' @keywords NULL
spec_arrow_fetch_arrow <- list(
arrow_fetch_arrow_formals = function() {
# <establish formals of described functions>
expect_equal(names(formals(dbFetchArrow)), c("res", "..."))
},
arrow_fetch_arrow_atomic = function(con) {
#' @return
#' `dbFetchArrow()` always returns an object coercible to a [data.frame] with
#' as many rows as records were fetched and as many
#' columns as fields in the result set,
#' even if the result is a single value
query <- trivial_query()
res <- local_result(dbSendQueryArrow(con, query))
rows <- check_arrow(dbFetchArrow(res))
expect_equal(rows, data.frame(a = 1.5))
},
arrow_fetch_arrow_one_row = function(con) {
#' or has one
query <- trivial_query(3, letters[1:3])
result <- trivial_df(3, letters[1:3])
res <- local_result(dbSendQueryArrow(con, query))
rows <- check_arrow(dbFetchArrow(res))
expect_identical(rows, result)
},
arrow_fetch_arrow_zero_rows = function(con) {
#' or zero rows.
query <-
"SELECT * FROM (SELECT 1 as a, 2 as b, 3 as c) AS x WHERE (1 = 0)"
res <- local_result(dbSendQueryArrow(con, query))
rows <- check_arrow(dbFetchArrow(res))
expect_identical(class(rows), "data.frame")
},
#'
arrow_fetch_arrow_closed = function(ctx, con) {
skip_if_not_dbitest(ctx, "1.8.0.15")
#' @section Failure modes:
#' An attempt to fetch from a closed result set raises an error.
query <- trivial_query()
res <- dbSendQueryArrow(con, query)
dbClearResult(res)
expect_error(dbFetchArrow(res))
},
arrow_fetch_arrow_multi_row_single_column = function(ctx, con) {
#' @section Specification:
#' Fetching multi-row queries with one
query <- trivial_query(3, .ctx = ctx, .order_by = "a")
result <- trivial_df(3)
res <- local_result(dbSendQueryArrow(con, query))
rows <- check_arrow(dbFetchArrow(res))
expect_identical(rows, result)
},
arrow_fetch_arrow_multi_row_multi_column = function(ctx, con) {
#' or more columns by default returns the entire result.
query <- sql_union(
.ctx = ctx, paste("SELECT", 1:5 + 0.5, "AS a,", 4:0 + 0.5, "AS b"), .order_by = "a"
)
res <- local_result(dbSendQueryArrow(con, query))
rows <- check_arrow(dbFetchArrow(res))
expect_identical(rows, data.frame(a = 1:5 + 0.5, b = 4:0 + 0.5))
},
arrow_fetch_arrow_record_batch_reader = function(ctx, con) {
#' The object returned by `dbFetchArrow()` can also be passed to
#' [nanoarrow::as_nanoarrow_array_stream()] to create a nanoarrow
#' array stream object that can be used to read the result set
#' in batches.
query <- trivial_query(25, .ctx = ctx, .order_by = "a")
result <- trivial_df(25)
res <- local_result(dbSendQueryArrow(con, query))
stream <- dbFetchArrow(res)
rbr <- nanoarrow::as_nanoarrow_array_stream(stream)
#' The chunk size is implementation-specific.
out <- as.data.frame(rbr$get_next())
expect_equal(out, head(result, nrow(out)))
},
#
NULL
)