Skip to content

is.na() and %in% must use BinaryExecutor #113

@krlmlr

Description

@krlmlr

Otherwise, "dictionary vectors" are not handled correctly. Example (with duckdb 1.1.3, probably also works the same with 1.1.2), should keep the second row but removes all:

duckdb <- asNamespace("duckdb")
drv <- duckdb::duckdb()
con <- DBI::dbConnect(drv)
experimental <- FALSE
invisible(duckdb$rapi_load_rfuns(drv@database_ref))
invisible(DBI::dbExecute(con, 'CREATE MACRO "&"(x, y) AS (x AND y)'))
invisible(DBI::dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- tibble::tibble(a = c(0, NA), b = 1:2)

"filter"
#> [1] "filter"
rel1 <- duckdb$rel_from_df(con, df1, experimental = experimental)
"filter"
#> [1] "filter"
rel2 <- duckdb$rel_filter(
  rel1,
  list(
    duckdb$expr_function(
      "&",
      list(
        duckdb$expr_function("r_base::is.na", list(duckdb$expr_reference("a"))),
        duckdb$expr_function(
          "r_base::==",
          list(
            duckdb$expr_reference("b"),
            if ("experimental" %in% names(formals(duckdb$expr_constant))) {
              duckdb$expr_constant(2, experimental = experimental)
            } else {
              duckdb$expr_constant(2)
            }
          )
        )
      )
    )
  )
)
"count"
#> [1] "count"
rel3 <- duckdb$rel_aggregate(
  rel2,
  groups = list(),
  aggregates = list({
    tmp_expr <- duckdb$expr_function("n", list())
    duckdb$expr_set_alias(tmp_expr, "n")
    tmp_expr
  })
)
rel3
#> DuckDB Relation: 
#> ---------------------
#> --- Relation Tree ---
#> ---------------------
#> Aggregate [n()]
#>   Filter ["&"("r_base::is.na"(a), "r_base::=="(b, 2.0))]
#>     r_dataframe_scan(0x11aadba88)
#> 
#> ---------------------
#> -- Result Columns  --
#> ---------------------
#> - n (INTEGER)
duckdb$rel_to_altrep(rel3)
#>   n
#> 1 0

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

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions