r-dbi / bigrquery

An interface to Google's BigQuery from R.
https://bigrquery.r-dbi.org
Other
517 stars 182 forks source link

Problem with double columns. I need double but bigrquery brings integer to me #624

Open joscani opened 1 month ago

joscani commented 1 month ago

In https://bigrquery.r-dbi.org/ I read this

library(dplyr)

natality <- tbl(con, "natality")

natality %>%
  select(year, month, day, weight_pounds) %>% 
  head(10) %>%
  collect()

and get

#> # A tibble: 10 × 4
#>     year month   day weight_pounds
#>    <int> <int> <int>         <dbl>
#>  1  2005     5    NA          7.56
#>  2  2005     6    NA          4.75
#>  3  2005    11    NA          7.37
#>  4  2005     6    NA          7.81
#>  5  2005     5    NA          3.69
#>  6  2005    10    NA          6.95
#>  7  2005    12    NA          8.44
#>  8  2005    10    NA          8.69
#>  9  2005    10    NA          7.63
#> 10  2005     7    NA          8.27

but trying to get the same using my billing project


con <- dbConnect(
  bigrquery::bigquery(),
  project = "publicdata",
  dataset = "samples",
  billing = billing
)

natality <- tbl(con, "natality")

natality  |> 
  select(year, month, day, weight_pounds)  |>  
  head(4)

I get

Job complete
Billed: 3.76 GB
Streamed 4 rows in 1 messages.                                                                   
# Source:   SQL [4 x 4]
# Database: BigQueryConnection
   year month   day weight_pounds
  <int> <int> <int>         <int>
1  2005    11    NA             8
2  2005     1    NA             8
3  2005     3    NA             7
4  2005     7    NA             7

Is a problem , because I need to summarise and get target (0, 1 variable) averages for a group, and only gets 1 or 0 not te proportion.

And If I upload a dataframe like mtcars for example to a bigquery table . double columns in dataframe are changed to integer columns.

Any idea? Thanks

joscani commented 1 month ago

Ok. The problem is with the newest development release. If I remove package and install again with

install.packages("bigrquery")

all runs smoothly

IoannaNika commented 4 days ago

Hello, in what version is this fixed? I experience this issue with version 1.51.

ablack3 commented 4 days ago

Here is a reprex using the current cran release. The column order changes and 5.0 (double) is cast to 5 (integer).

library(bigrquery)
bq_auth(path = Sys.getenv("BIGQUERY_SERVICE_ACCOUNT_JSON_PATH"))

con <- DBI::dbConnect(
  bigrquery::bigquery(),
  project = Sys.getenv("BIGQUERY_PROJECT_ID"),
  dataset = Sys.getenv("BIGQUERY_CDM_SCHEMA")
)

schema <- Sys.getenv("BIGQUERY_SCRATCH_SCHEMA")

df <- data.frame(a = 5.4, b = 5.0)
DBI::dbRemoveTable(con, DBI::Id(schema = schema, table = "test1"))
DBI::dbWriteTable(con, DBI::Id(schema = schema, table = "test1"), value = df)

DBI::dbGetQuery(con, glue::glue("select * from {schema}.test1")) |> dplyr::tibble()
#> # A tibble: 1 × 2
#>       b     a
#>   <int> <dbl>
#> 1     5   5.4

DBI::dbDisconnect(con)

Created on 2024-11-25 with reprex v2.1.1

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.3 (2024-02-29) #> os macOS Sonoma 14.1 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz UTC #> date 2024-11-25 #> pandoc 3.1.11 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/aarch64/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> askpass 1.2.1 2024-10-04 [1] CRAN (R 4.3.3) #> bigrquery * 1.5.1 2024-03-14 [1] CRAN (R 4.3.1) #> bit 4.5.0 2024-09-20 [1] CRAN (R 4.3.3) #> bit64 4.5.2 2024-09-22 [1] CRAN (R 4.3.3) #> brio 1.1.5 2024-04-24 [1] CRAN (R 4.3.1) #> cli 3.6.3 2024-06-21 [1] CRAN (R 4.3.3) #> curl 5.2.3 2024-09-20 [1] CRAN (R 4.3.3) #> DBI 1.2.3 2024-06-02 [1] CRAN (R 4.3.3) #> digest 0.6.37 2024-08-19 [1] CRAN (R 4.3.3) #> dplyr 1.1.4 2023-11-17 [1] CRAN (R 4.3.1) #> evaluate 1.0.1 2024-10-10 [1] CRAN (R 4.3.3) #> fansi 1.0.6 2023-12-08 [1] CRAN (R 4.3.1) #> fastmap 1.2.0 2024-05-15 [1] CRAN (R 4.3.3) #> fs 1.6.4 2024-04-25 [1] CRAN (R 4.3.1) #> gargle 1.5.2 2023-07-20 [1] CRAN (R 4.3.0) #> generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.0) #> glue 1.8.0 2024-09-30 [1] CRAN (R 4.3.3) #> htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.3.1) #> httr 1.4.7 2023-08-15 [1] CRAN (R 4.3.0) #> jsonlite 1.8.9 2024-09-20 [1] CRAN (R 4.3.3) #> knitr 1.48 2024-07-07 [1] CRAN (R 4.3.3) #> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.3.1) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0) #> openssl 2.2.2 2024-09-20 [1] CRAN (R 4.3.3) #> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.3.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0) #> reprex 2.1.1 2024-07-06 [1] CRAN (R 4.3.3) #> rlang 1.1.4 2024-06-04 [1] CRAN (R 4.3.3) #> rmarkdown 2.28 2024-08-17 [1] CRAN (R 4.3.3) #> rstudioapi 0.17.0 2024-10-16 [1] CRAN (R 4.3.3) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0) #> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.3.0) #> tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.3.1) #> utf8 1.2.4 2023-10-22 [1] CRAN (R 4.3.1) #> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.3.1) #> withr 3.0.2 2024-10-28 [1] CRAN (R 4.3.3) #> xfun 0.48 2024-10-03 [1] CRAN (R 4.3.3) #> yaml 2.3.10 2024-07-26 [1] CRAN (R 4.3.3) #> #> [1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library #> #> ────────────────────────────────────────────────────────────────────────────── ```