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

feat(r): Implement infer schema methods #104

Merged
merged 5 commits into from
Feb 8, 2023

Conversation

paleolimbot
Copy link
Member

@paleolimbot paleolimbot commented Feb 8, 2023

This PR implements infer_nanoarrow_schema(), which gives a hypothetical type of what schema an object would have if it were converted to Arrow format. Arrow's arrow::infer_type() does the same thing, and before this PR, nanoarrow just fell back on Arrow to infer the type conversion. Now that types can be created natively, we don't need Arrow for this.

This PR implements schema inference using S3 dispatch. It would be faster to implement this in C, and this probably will be done in the future; however for now it seems like the overhead is acceptable for most uses (basically, you need more than 10,000 columns in a data frame to start noticing).

library(arrow, warn.conflicts = FALSE)
#> Some features are not enabled in this build of Arrow. Run `arrow_info()` for more information.
library(nanoarrow)

make_big_df <- function(n) {
  cols <- lapply(seq_len(n), function(...) integer())
  names(cols) <- paste0("col", seq_len(n))
  tibble::new_tibble(cols, nrow = 0)
}

df <- make_big_df(1e5)

bench::mark(
  infer_nanoarrow_schema(df),
  arrow::infer_type(df),
  check = F
)
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.
#> # A tibble: 2 × 6
#>   expression                      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>                 <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 infer_nanoarrow_schema(df)  582.4ms  582.4ms      1.72    2.43MB     13.7
#> 2 arrow::infer_type(df)        85.1ms   86.6ms     11.5     1.02MB      0

Created on 2023-02-08 with reprex v2.0.2

@paleolimbot paleolimbot marked this pull request as ready for review February 8, 2023 18:08
@paleolimbot paleolimbot merged commit 5771e5e into apache:main Feb 8, 2023
@paleolimbot paleolimbot deleted the infer-schema branch February 8, 2023 18:10
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

Successfully merging this pull request may close these issues.

None yet

1 participant