Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/live-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-commands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/pr-fetch@v2
with:
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/pr-fetch@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
20 changes: 19 additions & 1 deletion R/bq-download.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,32 @@ parse_postprocess <- function(df, bigint) {
function(x) hms::parse_hms(x)
)

# Fix for issue #624: Ensure NUMERIC/FLOAT columns remain as doubles
# Some BigQuery configurations may incorrectly return NUMERIC columns as INTEGER type
df <- col_apply(
df,
function(x) {
# Check if this is a NUMERIC or BIGNUMERIC column that got parsed as integer64
bq_type <- attr(x, "bq_type")
!is.null(bq_type) && bq_type %in% c("NUMERIC", "BIGNUMERIC") && bit64::is.integer64(x)
},
function(x) {
# Convert back to double to preserve decimal precision
as.numeric(x)
}
)

if (bigint != "integer64") {
as_bigint <- switch(
bigint,
integer = as.integer,
numeric = as.numeric,
character = as.character
)
df <- col_apply(df, bit64::is.integer64, as_bigint)
# Only apply bigint conversion to true INTEGER columns, not NUMERIC/FLOAT
df <- col_apply(df, function(x) {
bit64::is.integer64(x) && !attr(x, "bq_type") %in% c("NUMERIC", "BIGNUMERIC", "FLOAT")
}, as_bigint)
}

df
Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/test-bq-download.R
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,27 @@ test_that("can convert bytes type", {
)
)
})

test_that("NUMERIC columns preserve double precision (issue #624)", {
# Test that NUMERIC/BIGNUMERIC columns are not converted to integers
# even when bigint = "integer" is used

# Create test data that simulates NUMERIC columns incorrectly parsed as integer64
test_data <- data.frame(
value = bit64::as.integer64(c(123, 456, 789)),
count = bit64::as.integer64(c(1, 2, 3))
)
attr(test_data$value, "bq_type") <- "NUMERIC" # Should remain double
attr(test_data$count, "bq_type") <- "INTEGER" # Should be converted to int

# Apply post-processing with bigint = "integer"
result <- parse_postprocess(test_data, bigint = "integer")

# NUMERIC column should remain as double
expect_type(result$value, "double")
expect_equal(result$value, c(123, 456, 789))

# INTEGER column should be converted to integer
expect_type(result$count, "integer")
expect_equal(result$count, c(1L, 2L, 3L))
})
Loading