Skip to content

Commit d621e08

Browse files
committed
Corrections based on PR comments. Returned to use list, cleaned up check_labels and corrected tests
1 parent ad400e8 commit d621e08

4 files changed

Lines changed: 13 additions & 29 deletions

File tree

R/bq-parse.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
bq_parse_single <- function(value, type, ...) {
22
field <- bq_field("", type, ...)
3-
field_j <- jsonlite::toJSON(as_json(field), auto_unbox = TRUE)
3+
field_j <- jsonlite::toJSON(as_json(field))
44
value_j <- jsonlite::toJSON(value, auto_unbox = TRUE)
55

66
bq_field_init(field_j, value_j)

R/bq-perform.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ bq_perform_upload <- function(
168168
metadata <- bq_body(metadata, ...)
169169
metadata <- list(
170170
"type" = "application/json; charset=UTF-8",
171-
"content" = jsonlite::toJSON(metadata, auto_unbox = TRUE, pretty = TRUE)
171+
"content" = jsonlite::toJSON(metadata, auto_unbox = TRUE, pretty = TRUE, digits = json_digits)
172172
)
173173

174174
if (source_format == "NEWLINE_DELIMITED_JSON") {

R/utils.R

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,13 @@ has_bigrquerystorage <- function() {
8787
}
8888

8989
check_labels <- function(labels) {
90-
if (is.null(labels) || length(labels) == 0 || (length(labels) == 1 && is.na(labels))) {
90+
if (is.null(labels) || length(labels) == 0) {
9191
return(NULL)
9292
}
9393

94-
if (!is.character(labels) || is.null(names(labels)) || anyNA(names(labels)) || any(names(labels) == "")) {
95-
warning("Labels must be a named character vector; dropping labels", immediate. = TRUE, call. = FALSE)
96-
return(NULL)
97-
}
98-
99-
nms <- names(labels)
100-
bad_keys <- nms[nms != tolower(nms)]
101-
if (length(bad_keys) > 0) {
102-
warning(sprintf("Label key '%s' must match ^[a-z0-9_-]{0,62}$; dropping labels", bad_keys[[1]]), immediate. = TRUE, call. = FALSE)
103-
return(NULL)
104-
}
105-
106-
bad_vals <- labels[labels != tolower(labels)]
107-
if (length(bad_vals) > 0) {
108-
warning(sprintf("Label value '%s' must be empty or match ^[a-z0-9_-]{0,62}$; dropping labels", bad_vals[[1]]), immediate. = TRUE, call. = FALSE)
109-
return(NULL)
94+
if (!is.list(labels) || any(names2(labels) == "")) {
95+
cli::cli_abort("Labels must be a named list.")
11096
}
11197

112-
return(labels)
98+
labels
11399
}

tests/testthat/test-utils.R

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ test_that("bq_check_namespace() works", {
88

99
test_that("check_labels() accepts valid labels and NULL-like inputs", {
1010
expect_null(check_labels(NULL))
11-
expect_null(check_labels(NA))
12-
expect_null(check_labels(character()))
11+
expect_null(check_labels(list()))
1312

14-
expect_equal(check_labels(c(env = "prod")), c(env = "prod"))
15-
expect_equal(check_labels(c(env = "prod", team = "data")), c(env = "prod", team = "data"))
13+
expect_equal(check_labels(list(env = "prod")), list(env = "prod"))
14+
expect_equal(check_labels(list(env = "prod", team = "data")), list(env = "prod", team = "data"))
15+
expect_equal(check_labels(list(env = "")), list(env = ""))
1616
})
1717

18-
test_that("check_labels() warns and returns NULL for invalid inputs", {
19-
expect_warning(check_labels(list(env = "prod")), "named character vector")
20-
expect_warning(check_labels(c("no-name")), "named character vector")
21-
expect_warning(check_labels(c(ENV = "prod")), "must match")
22-
expect_warning(check_labels(c(env = "Prod")), "must be empty or match")
18+
test_that("check_labels() errors on invalid inputs", {
19+
expect_error(check_labels(c(env = "prod")), "named list")
20+
expect_error(check_labels(list("no-name")), "named list")
2321
})

0 commit comments

Comments
 (0)