Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected data type change when downloading zero row data frame #615

Open
elalbaicin opened this issue Jun 11, 2024 · 3 comments
Open

Unexpected data type change when downloading zero row data frame #615

elalbaicin opened this issue Jun 11, 2024 · 3 comments

Comments

@elalbaicin
Copy link

elalbaicin commented Jun 11, 2024

Whenever a query result has zero rows, some columns of the downloaded data frame have their data type changed.

In particular, the downloaded data frame converts date columns to string columns:

example

This type conversion has caused some unexpected behavior. Is it possible to ensure that the column types from downloaded data frames always match the schema?

# Download zero rows table (error)
queryData0 <- glue("SELECT {dateCol} FROM {dataset}.{table} LIMIT 0")

bq_project_query(x = projectId, query = queryData0) |>
  bq_table_download()

# Download non-zero rows table (correct)
queryData1 <- glue("SELECT {dateCol} FROM {dataset}.{table} LIMIT 1")

bq_project_query(x = projectId, query = queryData1) |>
  bq_table_download()
@elalbaicin elalbaicin changed the title Unepected data type change when downloading zero row data frame Unexpected data type change when downloading zero row data frame Jun 11, 2024
@hadley
Copy link
Member

hadley commented Jun 11, 2024

Could you please rework your reproducible example to use the reprex package ? That makes it easier to see both the input and the output, formatted in such a way that I can easily re-run in a local session. Thanks!

@elalbaicin
Copy link
Author

Yes, of course.

library(bigrquery)

# Auth
bq_auth_configure(path = "client_key_googlecloud.json")
bq_auth(path = "marine-booth-200313-xxxxxxxxxxx.json")

# Project ID
projectId <- "marine-booth-200313"

# Download one row table
queryData1 <- "SELECT date FROM RData.adsRaw LIMIT 1"

bq_project_query(x = projectId, query = queryData1) |>
  bq_table_download()
#> # A tibble: 1 × 1
#>   date      
#>   <date>    
#> 1 2020-12-22

# Download zero rows table (error)
queryData0 <- "SELECT date FROM RData.adsRaw LIMIT 0"

bq_project_query(x = projectId, query = queryData0) |>
  bq_table_download()
#> # A tibble: 0 × 1
#> # ℹ 1 variable: date <chr>

Created on 2024-06-11 with reprex v2.1.0

@hadley
Copy link
Member

hadley commented Jun 12, 2024

Thanks! It'll probably be a couple of weeks before I get to this, but I'm hoping to put some more time into bigrquery soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants