4
4
BigQueryConnection <- function (project ,
5
5
dataset ,
6
6
billing ,
7
+ session = NULL ,
7
8
page_size = 1e4 ,
8
9
quiet = NA ,
9
10
use_legacy_sql = FALSE ,
@@ -15,6 +16,7 @@ BigQueryConnection <- function(project,
15
16
project = project ,
16
17
dataset = dataset ,
17
18
billing = billing ,
19
+ session = session ,
18
20
page_size = as.integer(page_size ),
19
21
quiet = quiet ,
20
22
use_legacy_sql = use_legacy_sql ,
@@ -31,6 +33,7 @@ setClass(
31
33
project = " character" ,
32
34
dataset = " ANY" ,
33
35
billing = " character" ,
36
+ session = " ANY" ,
34
37
use_legacy_sql = " logical" ,
35
38
page_size = " integer" ,
36
39
quiet = " logical" ,
@@ -91,6 +94,7 @@ setMethod("dbExecute", c("BigQueryConnection", "character"), function(conn, stat
91
94
92
95
job <- bq_perform_query(statement ,
93
96
billing = conn @ billing ,
97
+ session = conn @ session ,
94
98
default_dataset = ds ,
95
99
quiet = conn @ quiet ,
96
100
...
@@ -191,36 +195,16 @@ dbWriteTable_bq <- function(conn,
191
195
check_bool(overwrite )
192
196
check_bool(append )
193
197
194
- if (! is.null(field.types )) {
195
- cli :: cli_abort(
196
- " {.arg field.types} not supported by bigrquery." ,
197
- call = quote(DBI :: dbWriteTable())
198
- )
199
- }
200
- if (! identical(temporary , FALSE )) {
201
- cli :: cli_abort(
202
- " {.code temporary = FALSE} not supported by bigrquery." ,
203
- call = quote(DBI :: dbWriteTable())
204
- )
205
- }
206
-
207
- if (append ) {
208
- create_disposition <- " CREATE_NEVER"
209
- write_disposition <- " WRITE_APPEND"
210
- } else {
211
- create_disposition <- " CREATE_IF_NEEDED"
212
- write_disposition <- if (overwrite ) " WRITE_TRUNCATE" else " WRITE_EMPTY"
213
- }
214
- tb <- as_bq_table(conn , name )
215
-
216
- bq_table_upload(
217
- tb ,
218
- value ,
219
- create_disposition = create_disposition ,
220
- write_disposition = write_disposition ,
221
- billing = conn @ billing ,
222
- ...
198
+ browser()
199
+ sql <- DBI :: sqlCreateTable(
200
+ con ,
201
+ name ,
202
+ fields = field.types ,
203
+ temporary = temporary ,
204
+ row.names = row.names
223
205
)
206
+ DBI :: dbExecute(sql )
207
+
224
208
invisible (TRUE )
225
209
}
226
210
@@ -238,26 +222,27 @@ dbWriteTable_bq <- function(conn,
238
222
# ' @param field.types,temporary Ignored. Included for compatibility with
239
223
# ' generic.
240
224
# ' @export
241
- setMethod(
242
- " dbWriteTable" ,
243
- c(" BigQueryConnection" , " character" , " data.frame" ),
244
- dbWriteTable_bq
245
- )
246
-
247
- # ' @rdname DBI
248
- # ' @export
249
- setMethod(
250
- " dbWriteTable" ,
251
- c(" BigQueryConnection" , " Id" , " data.frame" ),
252
- dbWriteTable_bq
253
- )
225
+ # ' setMethod(
226
+ # ' "dbWriteTable",
227
+ # ' c("BigQueryConnection", "character", "data.frame"),
228
+ # ' dbWriteTable_bq
229
+ # ' )
230
+ # '
231
+ # ' #' @rdname DBI
232
+ # ' #' @export
233
+ # ' setMethod(
234
+ # ' "dbWriteTable",
235
+ # ' c("BigQueryConnection", "Id", "data.frame"),
236
+ # ' dbWriteTable_bq
237
+ # ' )
254
238
255
239
dbAppendTable_bq <- function (conn , name , value , ... , row.names = NULL ) {
256
240
tb <- as_bq_table(conn , name )
257
241
258
242
bq_table_upload(tb , value ,
259
243
create_disposition = " CREATE_NEVER" ,
260
244
write_disposition = " WRITE_APPEND" ,
245
+ session = conn @ session ,
261
246
...
262
247
)
263
248
on_connection_updated(conn )
@@ -280,15 +265,9 @@ dbCreateTable_bq <- function(conn,
280
265
... ,
281
266
row.names = NULL ,
282
267
temporary = FALSE ) {
283
- if (! identical(temporary , FALSE )) {
284
- cli :: cli_abort(
285
- " {.code temporary = FALSE} not supported by bigrquery." ,
286
- call = quote(DBI :: dbCreateTable())
287
- )
288
- }
289
268
290
269
tb <- as_bq_table(conn , name )
291
- bq_table_create(tb , fields )
270
+ bq_table_create(tb , fields , temporary = temporary , session = conn @ session )
292
271
on_connection_updated(conn )
293
272
294
273
invisible (TRUE )
@@ -305,7 +284,7 @@ setMethod("dbCreateTable", "BigQueryConnection", dbCreateTable_bq)
305
284
306
285
dbReadTable_bq <- function (conn , name , ... ) {
307
286
tb <- as_bq_table(conn , name )
308
- bq_table_download(tb , ... )
287
+ bq_table_download(tb , ... , session = conn @ session )
309
288
}
310
289
311
290
# ' @rdname DBI
@@ -328,7 +307,7 @@ setMethod(
328
307
}
329
308
ds <- bq_dataset(conn @ project , conn @ dataset )
330
309
331
- tbs <- bq_dataset_tables(ds , ... )
310
+ tbs <- bq_dataset_tables(ds , ... , session = conn @ session )
332
311
map_chr(tbs , function (x ) x $ table )
333
312
})
334
313
@@ -347,7 +326,7 @@ setMethod("dbExistsTable", c("BigQueryConnection", "Id"), dbExistsTable_bq)
347
326
348
327
dbListFields_bq <- function (conn , name , ... ) {
349
328
tb <- as_bq_table(conn , name )
350
- flds <- bq_table_fields(tb )
329
+ flds <- bq_table_fields(tb , session = conn @ session )
351
330
map_chr(flds , function (x ) x $ name )
352
331
}
353
332
@@ -362,7 +341,7 @@ setMethod("dbListFields", c("BigQueryConnection", "Id"), dbListFields_bq)
362
341
363
342
dbRemoveTable_bq <- function (conn , name , ... ) {
364
343
tb <- as_bq_table(conn , name )
365
- bq_table_delete(tb )
344
+ bq_table_delete(tb , session = conn @ session )
366
345
on_connection_updated(conn )
367
346
invisible (TRUE )
368
347
}
@@ -398,7 +377,7 @@ setMethod(
398
377
setMethod(
399
378
" dbBegin" , " BigQueryConnection" ,
400
379
function (conn , ... ) {
401
- testthat :: skip( " Not yet implemented: dbBegin(Connection) " )
380
+ dbExecute( conn , " BEGIN TRANSACTION " )
402
381
})
403
382
404
383
# ' @rdname DBI
@@ -407,7 +386,7 @@ setMethod(
407
386
setMethod(
408
387
" dbCommit" , " BigQueryConnection" ,
409
388
function (conn , ... ) {
410
- testthat :: skip( " Not yet implemented: dbCommit(Connection) " )
389
+ dbExecute( conn , " COMMIT TRANSACTION " )
411
390
})
412
391
413
392
# ' @rdname DBI
@@ -416,7 +395,7 @@ setMethod(
416
395
setMethod(
417
396
" dbRollback" , " BigQueryConnection" ,
418
397
function (conn , ... ) {
419
- testthat :: skip( " Not yet implemented: dbRollback(Connection) " )
398
+ dbExecute( conn , " ROLLBACK TRANSACTION " )
420
399
})
421
400
# nocov end
422
401
@@ -428,7 +407,6 @@ as_bq_dataset.BigQueryConnection <- function(x, ..., error_arg, error_call) {
428
407
bq_dataset(x @ project , x @ dataset )
429
408
}
430
409
431
-
432
410
# ' @export
433
411
as_bq_table.BigQueryConnection <- function (x , name , ... ) {
434
412
if (inherits(name , " dbplyr_table_ident" )) {
0 commit comments