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

Implement n_distinct() for the Arrow Substrait compiler #245

Open
thisisnic opened this issue Jan 30, 2023 · 0 comments
Open

Implement n_distinct() for the Arrow Substrait compiler #245

thisisnic opened this issue Jan 30, 2023 · 0 comments

Comments

@thisisnic
Copy link
Contributor

n_distinct() was implemented in #244 for DuckDB, but cannot yet be implemented for Arrow as it's not been implemented in libarrow to be translated to the appropriate Acero function.

Here's a possible implementation a test:

arrow_funs[["n_distinct"]] <- function(x, na.rm = FALSE) {
  check_na_rm(na.rm)
  warn_n_distinct()

  substrait_call_agg(
    "aggregate_approx.approx_count_distinct",
    x,
    .output_type = substrait_i64(),
    .phase = 3L,
    .invocation = 1L
  )
}

test_that("arrow translation for n_distinct works", {
  skip_if_not(has_arrow_with_substrait())
  skip("Substrait function `approx_count_distinct` not yet implemented in Arrow C++")

  expect_equal(
    tibble::tibble(x = c(1:5, 1:3)) %>%
      arrow_substrait_compiler() %>%
      substrait_aggregate(n = n_distinct(x, na.rm = TRUE)) %>%
      dplyr::collect(),
    tibble::tibble(
      n = 5
    )
  )
})

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

No branches or pull requests

1 participant