duckdb / duckdb-r

The duckdb R package
https://r.duckdb.org/
Other
115 stars 25 forks source link

`NULL` mapped to `NA_integer_` #155

Open krlmlr opened 4 months ago

krlmlr commented 4 months ago

It's more idiomatic to map to logical.

duckdb <- asNamespace("duckdb")
drv <- duckdb::duckdb()
con <- DBI::dbConnect(drv)
experimental <- FALSE
df1 <- tibble::tibble(a = 1)

rel1 <- duckdb$rel_from_df(con, df1, experimental = experimental)
rel2 <- duckdb$rel_project(
  rel1,
  list(
    {
      tmp_expr <- duckdb$expr_reference("a")
      duckdb$expr_set_alias(tmp_expr, "a")
      tmp_expr
    },
    {
      tmp_expr <- if ("experimental" %in% names(formals(duckdb$expr_constant))) {
        duckdb$expr_constant(NA, experimental = experimental)
      } else {
        duckdb$expr_constant(NA)
      }
      duckdb$expr_set_alias(tmp_expr, "b")
      tmp_expr
    }
  )
)
rel2
#> DuckDB Relation: 
#> ---------------------
#> --- Relation Tree ---
#> ---------------------
#> Projection [a as a, NULL as b]
#>   r_dataframe_scan(0x11e727dd0)
#> 
#> ---------------------
#> -- Result Columns  --
#> ---------------------
#> - a (DOUBLE)
#> - b (INTEGER)
dput(duckdb$rel_to_altrep(rel2))
#> structure(list(a = 1, b = NA_integer_), row.names = c(NA, -1L
#> ), class = "data.frame")

DBI::dbDisconnect(con)

Created on 2024-05-04 with reprex v2.1.0

krlmlr commented 3 months ago

Upstream: https://github.com/krlmlr/duckdb/commit/40efc4bb686aad9224f65e788cd6ba581a897f9e

krlmlr commented 3 months ago

Next try: https://github.com/krlmlr/duckdb/commit/4e17c71dc34ca3c09e7e2183a67a9141de67753f

krlmlr commented 3 months ago

Keep pushing: https://github.com/krlmlr/duckdb/actions/runs/9340041792

krlmlr commented 3 months ago

Too many things fail in duckdb when this is changed. Let's revisit what is truly necessary for duckplyr.