-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[r] Add Arrow to R type mapper (#3161)
* [r] Add Arrow to R type mapper Add new `r_type_from_arrow_type()` function to get R types from Arrow types. This function takes an Arrow schema, field, or datatype and returns the corresponding R type (as indicated by `typeof()`) (or types for a schema) [SC-57387](https://app.shortcut.com/tiledb-inc/story/57387) * Update docs * Update changelog Bump develop version
- Loading branch information
1 parent
cced6ea
commit 4d37aa9
Showing
7 changed files
with
234 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
test_that("Arrow to R types: data type", { | ||
skip_if(!extended_tests()) | ||
skip_if_not_installed('arrow') | ||
|
||
ints <- apply( | ||
expand.grid(c('', 'u'), 'int', c('8', '16', '32')), | ||
MARGIN = 1L, | ||
FUN = paste, | ||
collapse = '' | ||
) | ||
for (i in c(ints, 'dictionary')) { | ||
f <- get(i, envir = asNamespace('arrow')) | ||
expect_type(rt <- r_type_from_arrow_type(f()), 'character') | ||
expect_length(rt, 1L) | ||
expect_null(names(rt)) | ||
expect_identical( | ||
rt, | ||
'integer', | ||
label = sprintf('r_type_from_arrow_type(arrow::%s())', i) | ||
) | ||
} | ||
|
||
dbls <- c('int64', 'uint64', 'date32', 'timestamp' ,'float', 'float32') | ||
for (i in dbls) { | ||
f <- get(i, envir = asNamespace('arrow')) | ||
expect_type(rt <- r_type_from_arrow_type(f()), 'character') | ||
expect_length(rt, 1L) | ||
expect_null(names(rt)) | ||
expect_identical( | ||
rt, | ||
'double', | ||
label = sprintf('r_type_from_arrow_type(arrow::%s())', i) | ||
) | ||
} | ||
|
||
for (i in c('bool', 'boolean')) { | ||
f <- get(i, envir = asNamespace('arrow')) | ||
expect_type(rt <- r_type_from_arrow_type(f()), 'character') | ||
expect_length(rt, 1L) | ||
expect_null(names(rt)) | ||
expect_identical( | ||
rt, | ||
'logical', | ||
label = sprintf('r_type_from_arrow_type(arrow::%s())', i) | ||
) | ||
} | ||
for (i in c('utf8', 'string', 'large_utf8')) { | ||
f <- get(i, envir = asNamespace('arrow')) | ||
expect_type(rt <- r_type_from_arrow_type(f()), 'character') | ||
expect_length(rt, 1L) | ||
expect_null(names(rt)) | ||
expect_identical( | ||
rt, | ||
'character', | ||
label = sprintf('r_type_from_arrow_type(arrow::%s())', i) | ||
) | ||
} | ||
}) | ||
|
||
test_that("Arrow to R types: field", { | ||
skip_if(!extended_tests()) | ||
skip_if_not_installed('arrow') | ||
|
||
field <- arrow::field(name = random_name(), type = arrow::int8()) | ||
expect_type(rt <- r_type_from_arrow_type(field), 'character') | ||
expect_length(rt, 1L) | ||
expect_named(rt, field$name) | ||
expect_equivalent(rt, 'integer') | ||
}) | ||
|
||
test_that("Arrow to R types: schema", { | ||
skip_if(!extended_tests()) | ||
|
||
asch <- create_arrow_schema() | ||
expect_type(rt <- r_type_from_arrow_type(asch), 'character') | ||
expect_length(rt, length(asch)) | ||
expect_named(rt, asch$names) | ||
for (fn in names(rt)) { | ||
et <- switch( | ||
EXPR = fn, | ||
int_column = 'integer', | ||
soma_joinid = 'double', | ||
float_column = 'double', | ||
string_column = 'character' | ||
) | ||
expect_equivalent( | ||
rt[fn], | ||
et, | ||
label = sprintf('r_type_from_arrow_type(schema[[%s]])', fn), | ||
expected.label = dQuote(et, FALSE) | ||
) | ||
} | ||
}) |