@@ -88,7 +88,7 @@ spec_sql_append_table <- list(
88
88
select = " unique" , from = " join" , where = " order" ,
89
89
stringsAsFactors = FALSE
90
90
)
91
- test_table_roundtrip( use_append = TRUE , con , tbl_in , name = " exists" )
91
+ append_table_test_roundtrip( con , tbl_in , name = " exists" )
92
92
},
93
93
94
94
append_roundtrip_quotes = function (ctx , con , table_name ) {
@@ -104,7 +104,7 @@ spec_sql_append_table <- list(
104
104
)
105
105
106
106
names(tbl_in ) <- letters [seq_along(tbl_in )]
107
- test_table_roundtrip (con , tbl_in , use_append = TRUE )
107
+ append_table_test_roundtrip (con , tbl_in )
108
108
},
109
109
110
110
append_roundtrip_quotes_table_names = function (ctx , con ) {
@@ -125,7 +125,7 @@ spec_sql_append_table <- list(
125
125
tbl_in <- trivial_df()
126
126
127
127
for (table_name in table_names ) {
128
- test_table_roundtrip_one (con , tbl_in , use_append = TRUE , .add_na = FALSE )
128
+ append_table_test_roundtrip_one (con , tbl_in , .add_na = FALSE )
129
129
}
130
130
},
131
131
@@ -145,7 +145,7 @@ spec_sql_append_table <- list(
145
145
146
146
tbl_in <- trivial_df(length(column_names ), column_names )
147
147
148
- test_table_roundtrip_one (con , tbl_in , use_append = TRUE , .add_na = FALSE )
148
+ append_table_test_roundtrip_one (con , tbl_in , .add_na = FALSE )
149
149
},
150
150
151
151
# '
@@ -154,13 +154,13 @@ spec_sql_append_table <- list(
154
154
# ' and be read identically with [dbReadTable()]:
155
155
# ' - integer
156
156
tbl_in <- data.frame (a = c(1 : 5 ))
157
- test_table_roundtrip( use_append = TRUE , con , tbl_in )
157
+ append_table_test_roundtrip( con , tbl_in )
158
158
},
159
159
160
160
append_roundtrip_numeric = function (con ) {
161
161
# ' - numeric
162
162
tbl_in <- data.frame (a = c(seq(1 , 3 , by = 0.5 )))
163
- test_table_roundtrip( use_append = TRUE , con , tbl_in )
163
+ append_table_test_roundtrip( con , tbl_in )
164
164
# ' (the behavior for `Inf` and `NaN` is not specified)
165
165
},
166
166
@@ -169,14 +169,13 @@ spec_sql_append_table <- list(
169
169
tbl_in <- data.frame (a = c(TRUE , FALSE , NA ))
170
170
tbl_exp <- tbl_in
171
171
tbl_exp $ a <- ctx $ tweaks $ logical_return(tbl_exp $ a )
172
- test_table_roundtrip( use_append = TRUE , con , tbl_in , tbl_exp )
172
+ append_table_test_roundtrip( con , tbl_in , tbl_exp )
173
173
},
174
174
175
175
append_roundtrip_null = function (con ) {
176
176
# ' - `NA` as NULL
177
177
tbl_in <- data.frame (a = NA )
178
- test_table_roundtrip(
179
- use_append = TRUE ,
178
+ append_table_test_roundtrip(
180
179
con , tbl_in ,
181
180
transform = function (tbl_out ) {
182
181
tbl_out $ a <- as.logical(tbl_out $ a ) # Plain NA is of type logical
@@ -188,8 +187,7 @@ spec_sql_append_table <- list(
188
187
# ' - 64-bit values (using `"bigint"` as field type); the result can be
189
188
append_roundtrip_64_bit_numeric = function (ctx , con ) {
190
189
tbl_in <- data.frame (a = c(- 1e14 , 1e15 ))
191
- test_table_roundtrip(
192
- use_append = TRUE ,
190
+ append_table_test_roundtrip(
193
191
con , tbl_in ,
194
192
transform = function (tbl_out ) {
195
193
# ' - converted to a numeric, which may lose precision,
@@ -204,8 +202,7 @@ spec_sql_append_table <- list(
204
202
tbl_in <- data.frame (a = c(- 1e14 , 1e15 ))
205
203
tbl_exp <- tbl_in
206
204
tbl_exp $ a <- format(tbl_exp $ a , scientific = FALSE )
207
- test_table_roundtrip(
208
- use_append = TRUE ,
205
+ append_table_test_roundtrip(
209
206
con , tbl_in , tbl_exp ,
210
207
transform = function (tbl_out ) {
211
208
# ' - converted a character vector, which gives the full decimal
@@ -222,7 +219,7 @@ spec_sql_append_table <- list(
222
219
dbWriteTable(con , table_name , tbl_in , field.types = c(a = " BIGINT" ))
223
220
tbl_out <- dbReadTable(con , table_name )
224
221
# ' - written to another table and read again unchanged
225
- test_table_roundtrip( use_append = TRUE , con , tbl_out , tbl_expected = tbl_out )
222
+ append_table_test_roundtrip( con , tbl_out , tbl_expected = tbl_out )
226
223
},
227
224
228
225
append_roundtrip_character = function (con ) {
@@ -232,7 +229,7 @@ spec_sql_append_table <- list(
232
229
a = get_texts(),
233
230
stringsAsFactors = FALSE
234
231
)
235
- test_table_roundtrip( use_append = TRUE , con , tbl_in )
232
+ append_table_test_roundtrip( con , tbl_in )
236
233
},
237
234
238
235
append_roundtrip_character_native = function (con ) {
@@ -241,7 +238,7 @@ spec_sql_append_table <- list(
241
238
a = c(enc2native(get_texts())),
242
239
stringsAsFactors = FALSE
243
240
)
244
- test_table_roundtrip( use_append = TRUE , con , tbl_in )
241
+ append_table_test_roundtrip( con , tbl_in )
245
242
},
246
243
247
244
append_roundtrip_character_empty = function (con ) {
@@ -250,7 +247,7 @@ spec_sql_append_table <- list(
250
247
a = c(" " , " a" ),
251
248
stringsAsFactors = FALSE
252
249
)
253
- test_table_roundtrip( use_append = TRUE , con , tbl_in )
250
+ append_table_test_roundtrip( con , tbl_in )
254
251
},
255
252
256
253
append_roundtrip_character_empty_after = function (con ) {
@@ -259,7 +256,7 @@ spec_sql_append_table <- list(
259
256
a = c(" a" , " " ),
260
257
stringsAsFactors = FALSE
261
258
)
262
- test_table_roundtrip( use_append = TRUE , con , tbl_in )
259
+ append_table_test_roundtrip( con , tbl_in )
263
260
},
264
261
265
262
append_roundtrip_factor = function (con ) {
@@ -272,7 +269,7 @@ spec_sql_append_table <- list(
272
269
# ' with a warning)
273
270
suppressWarnings(
274
271
expect_warning(
275
- test_table_roundtrip( use_append = TRUE , con , tbl_in , tbl_exp )
272
+ append_table_test_roundtrip( con , tbl_in , tbl_exp )
276
273
)
277
274
)
278
275
},
@@ -287,8 +284,7 @@ spec_sql_append_table <- list(
287
284
tbl_in <- data.frame (id = 1L , a = I(list (as.raw(0 : 10 ))))
288
285
tbl_exp <- tbl_in
289
286
tbl_exp $ a <- blob :: as_blob(unclass(tbl_in $ a ))
290
- test_table_roundtrip(
291
- use_append = TRUE ,
287
+ append_table_test_roundtrip(
292
288
con , tbl_in , tbl_exp ,
293
289
transform = function (tbl_out ) {
294
290
tbl_out $ a <- blob :: as_blob(tbl_out $ a )
@@ -305,8 +301,7 @@ spec_sql_append_table <- list(
305
301
}
306
302
307
303
tbl_in <- data.frame (id = 1L , a = blob :: blob(as.raw(0 : 10 )))
308
- test_table_roundtrip(
309
- use_append = TRUE ,
304
+ append_table_test_roundtrip(
310
305
con , tbl_in ,
311
306
transform = function (tbl_out ) {
312
307
tbl_out $ a <- blob :: as_blob(tbl_out $ a )
@@ -324,8 +319,7 @@ spec_sql_append_table <- list(
324
319
325
320
# ' returned as `Date`)
326
321
tbl_in <- data.frame (a = as_numeric_date(c(Sys.Date() + 1 : 5 )))
327
- test_table_roundtrip(
328
- use_append = TRUE ,
322
+ append_table_test_roundtrip(
329
323
con , tbl_in ,
330
324
transform = function (tbl_out ) {
331
325
expect_type(unclass(tbl_out $ a ), " double" )
@@ -352,8 +346,7 @@ spec_sql_append_table <- list(
352
346
" 2040-01-01" ,
353
347
" 2999-09-09"
354
348
)))
355
- test_table_roundtrip(
356
- use_append = TRUE ,
349
+ append_table_test_roundtrip(
357
350
con , tbl_in ,
358
351
transform = function (tbl_out ) {
359
352
expect_type(unclass(tbl_out $ a ), " double" )
@@ -376,7 +369,7 @@ spec_sql_append_table <- list(
376
369
tbl_exp $ a <- hms :: as_hms(tbl_exp $ a )
377
370
tbl_exp $ b <- hms :: as_hms(tbl_exp $ b )
378
371
379
- test_table_roundtrip (
372
+ append_table_test_roundtrip (
380
373
con , tbl_in , tbl_exp ,
381
374
transform = function (tbl_out ) {
382
375
# ' returned as objects that inherit from `difftime`)
@@ -412,8 +405,7 @@ spec_sql_append_table <- list(
412
405
413
406
# ' respecting the time zone but not necessarily preserving the
414
407
# ' input time zone),
415
- test_table_roundtrip(
416
- use_append = TRUE ,
408
+ append_table_test_roundtrip(
417
409
con , tbl_in ,
418
410
transform = function (out ) {
419
411
dates <- vapply(out , inherits , " POSIXt" , FUN.VALUE = logical (1L ))
@@ -453,8 +445,7 @@ spec_sql_append_table <- list(
453
445
454
446
# ' respecting the time zone but not necessarily preserving the
455
447
# ' input time zone)
456
- test_table_roundtrip(
457
- use_append = TRUE ,
448
+ append_table_test_roundtrip(
458
449
con , tbl_in ,
459
450
transform = function (out ) {
460
451
dates <- vapply(out , inherits , " POSIXt" , FUN.VALUE = logical (1L ))
@@ -479,7 +470,7 @@ spec_sql_append_table <- list(
479
470
}
480
471
)
481
472
482
- lapply(tbl_in_list , test_table_roundtrip , con = con )
473
+ lapply(tbl_in_list , append_table_test_roundtrip , con = con )
483
474
},
484
475
485
476
append_table_name = function (ctx , con ) {
@@ -617,3 +608,37 @@ spec_sql_append_table <- list(
617
608
#
618
609
NULL
619
610
)
611
+
612
+
613
+ append_table_test_roundtrip <- function (... ) {
614
+ append_table_test_roundtrip_one(... , .add_na = " none" )
615
+ append_table_test_roundtrip_one(... , .add_na = " above" )
616
+ append_table_test_roundtrip_one(... , .add_na = " below" )
617
+ }
618
+
619
+ append_table_test_roundtrip_one <- function (
620
+ con , tbl_in , tbl_expected = tbl_in , transform = identity , name = NULL ,
621
+ field.types = NULL , .add_na = " none"
622
+ ) {
623
+ force(tbl_expected )
624
+ if (.add_na == " above" ) {
625
+ tbl_in <- add_na_above(tbl_in )
626
+ tbl_expected <- add_na_above(tbl_expected )
627
+ } else if (.add_na == " below" ) {
628
+ tbl_in <- add_na_below(tbl_in )
629
+ tbl_expected <- add_na_below(tbl_expected )
630
+ }
631
+
632
+ if (is.null(name )) {
633
+ name <- random_table_name()
634
+ }
635
+
636
+ local_remove_test_table(con , name = name )
637
+
638
+ dbCreateTable(con , name , field.types %|| % tbl_in )
639
+ dbAppendTable(con , name , tbl_in )
640
+
641
+ tbl_read <- check_df(dbReadTable(con , name , check.names = FALSE ))
642
+ tbl_out <- transform(tbl_read )
643
+ expect_equal_df(tbl_out , tbl_expected )
644
+ }
0 commit comments