Skip to content

Commit 037db4f

Browse files
author
Mark IIH
committed
add support for fieldDelimiter
1 parent f00aa54 commit 037db4f

File tree

5 files changed

+43
-16
lines changed

5 files changed

+43
-16
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# bigQueryR 0.3.2.9000
22

3-
* support `nullMarker`, `maxBadRecords` in upload jobs
3+
* support `nullMarker`, `maxBadRecords`, `fieldDelimiter` in upload jobs
44
* Support BigQuery type `DATE` for R class `Date` data.frame columns (BigQuery type `TIMESTAMP` still default for `POSIXct`columns) (#48)
55
* Allow custom user schema for uploads of data.frames (#48)
66
* Rename misnamed global functions from `bq_` prefix to `bqr_` prefix

R/jobs.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ bqr_wait_for_job <- function(job, wait=5){
134134
#'
135135
#' @family BigQuery asynch query functions
136136
#' @export
137-
bqr_get_job <- function(jobId, projectId = bqr_get_global_project()){
137+
bqr_get_job <- function(jobId = .Last.value, projectId = bqr_get_global_project()){
138138
check_bq_auth()
139139

140140
if(is.job(jobId)){

R/uploadData.R

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#' @param maxBadRecords The maximum number of bad records that BigQuery can ignore when running the job
1616
#' @param allowJaggedRows Whether to allow rows with variable length columns
1717
#' @param allowQuotedNewlines Whether to allow datasets with quoted new lines
18+
#' @param fieldDelimiter The separator for fields in a CSV file. Default is comma - \code{,}
1819
#'
1920
#' @return TRUE if successful, FALSE if not.
2021
#'
@@ -78,7 +79,8 @@ bqr_upload_data <- function(projectId = bqr_get_global_project(),
7879
nullMarker = NULL,
7980
maxBadRecords = NULL,
8081
allowJaggedRows = FALSE,
81-
allowQuotedNewlines = FALSE){
82+
allowQuotedNewlines = FALSE,
83+
fieldDelimiter = ","){
8284

8385

8486
assert_that(is.string(projectId),
@@ -88,7 +90,8 @@ bqr_upload_data <- function(projectId = bqr_get_global_project(),
8890
is.flag(wait),
8991
is.flag(allowJaggedRows),
9092
is.flag(allowQuotedNewlines),
91-
is.flag(autodetect))
93+
is.flag(autodetect),
94+
is.string(fieldDelimiter))
9295
sourceFormat <- match.arg(sourceFormat)
9396
create <- match.arg(create)
9497

@@ -123,7 +126,8 @@ bqr_upload_data <- function(projectId = bqr_get_global_project(),
123126
nullMarker = nullMarker,
124127
maxBadRecords = maxBadRecords,
125128
allowJaggedRows = allowJaggedRows,
126-
allowQuotedNewlines = allowQuotedNewlines)
129+
allowQuotedNewlines = allowQuotedNewlines,
130+
fieldDelimiter = fieldDelimiter)
127131

128132
}
129133

@@ -140,7 +144,8 @@ bqr_do_upload <- function(upload_data,
140144
nullMarker,
141145
maxBadRecords,
142146
allowJaggedRows,
143-
allowQuotedNewlines){
147+
allowQuotedNewlines,
148+
fieldDelimiter){
144149
check_bq_auth()
145150
UseMethod("bqr_do_upload", upload_data)
146151
}
@@ -158,7 +163,8 @@ bqr_do_upload.data.frame <- function(upload_data,
158163
nullMarker,
159164
maxBadRecords,
160165
allowJaggedRows,
161-
allowQuotedNewlines){
166+
allowQuotedNewlines,
167+
fieldDelimiter){
162168

163169
if(!is.null(user_schema)){
164170
schema <- user_schema
@@ -169,6 +175,7 @@ bqr_do_upload.data.frame <- function(upload_data,
169175
config <- list(
170176
configuration = list(
171177
load = list(
178+
fieldDelimiter = fieldDelimiter,
172179
nullMarker = nullMarker,
173180
maxBadRecords = maxBadRecords,
174181
sourceFormat = "CSV",
@@ -272,7 +279,8 @@ bqr_do_upload.character <- function(upload_data,
272279
nullMarker,
273280
maxBadRecords,
274281
allowJaggedRows,
275-
allowQuotedNewlines){
282+
allowQuotedNewlines,
283+
fieldDelimiter){
276284

277285
if(length(upload_data) > 1){
278286
source_uri <- upload_data
@@ -283,14 +291,12 @@ bqr_do_upload.character <- function(upload_data,
283291
config <- list(
284292
configuration = list(
285293
load = list(
294+
fieldDelimiter = fieldDelimiter,
286295
nullMarker = nullMarker,
287296
maxBadRecords = maxBadRecords,
288297
sourceFormat = sourceFormat,
289298
createDisposition = jsonlite::unbox(create),
290299
sourceUris = source_uri,
291-
# schema = list(
292-
# fields = user_schema
293-
# ),
294300
destinationTable = list(
295301
projectId = projectId,
296302
datasetId = datasetId,
@@ -305,12 +311,31 @@ bqr_do_upload.character <- function(upload_data,
305311

306312
## only provide schema if autodetect is FALSE
307313
if(!autodetect){
308-
config <- config$configuration$schema <- list(
309-
fields = user_schema
314+
config <- list(
315+
configuration = list(
316+
load = list(
317+
fieldDelimiter = fieldDelimiter,
318+
nullMarker = nullMarker,
319+
maxBadRecords = maxBadRecords,
320+
sourceFormat = sourceFormat,
321+
createDisposition = jsonlite::unbox(create),
322+
sourceUris = source_uri,
323+
schema = list(
324+
fields = user_schema
325+
),
326+
destinationTable = list(
327+
projectId = projectId,
328+
datasetId = datasetId,
329+
tableId = tableId
330+
),
331+
autodetect = autodetect,
332+
allowJaggedRows = allowJaggedRows,
333+
allowQuotedNewlines = allowQuotedNewlines
334+
)
335+
)
310336
)
311337
}
312338

313-
314339
l <-
315340
googleAuthR::gar_api_generator("https://www.googleapis.com/bigquery/v2",
316341
"POST",

man/bqr_get_job.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/bqr_upload_data.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)