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

[r] Remove arrow_*_from_tiledb_*() Helpers #3646

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions apis/r/R/utils-arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,49 +251,12 @@ arrow_type_unsigned_range <- function(x) {
range
}

#' Create an Arrow field from a TileDB dimension
#' @noRd
arrow_field_from_tiledb_dim <- function(x) {
stopifnot(inherits(x, "tiledb_dim"))
arrow::field(
name = tiledb::name(x),
type = arrow_type_from_tiledb_type(tiledb::datatype(x)),
nullable = FALSE
)
}

## With a nod to Kevin Ushey
#' @noRd
yoink <- function(package, symbol) {
do.call(":::", list(package, symbol))
}

#' Create an Arrow field from a TileDB attribute
#' @noRd
arrow_field_from_tiledb_attr <- function(x, arrptr = NULL) {
stopifnot(inherits(x, "tiledb_attr"))
if (tiledb::tiledb_attribute_has_enumeration(x) && !is.null(arrptr)) {
.tiledb_array_is_open <- yoink("tiledb", "libtiledb_array_is_open")
if (!.tiledb_array_is_open(arrptr)) {
.tiledb_array_open_with_ptr <- yoink("tiledb", "libtiledb_array_open_with_ptr")
arrptr <- .tiledb_array_open_with_ptr(arrptr, "READ")
}
ord <- tiledb::tiledb_attribute_is_ordered_enumeration_ptr(x, arrptr)
idx <- arrow_type_from_tiledb_type(tiledb::datatype(x))
arrow::field(
name = tiledb::name(x),
type = arrow::dictionary(index_type = idx, ordered = ord),
nullable = tiledb::tiledb_attribute_get_nullable(x)
)
} else {
arrow::field(
name = tiledb::name(x),
type = arrow_type_from_tiledb_type(tiledb::datatype(x)),
nullable = tiledb::tiledb_attribute_get_nullable(x)
)
}
}

#' Create a TileDB attribute from an Arrow field
#' @return a [`tiledb::tiledb_attr-class`]
#' @noRd
Expand Down Expand Up @@ -324,19 +287,6 @@ tiledb_attr_from_arrow_field <- function(field, tiledb_create_options) {
)
}

#' Create an Arrow schema from a TileDB array schema
#' @noRd
arrow_schema_from_tiledb_schema <- function(x) {
stopifnot(inherits(x, "tiledb_array_schema"))
dimfields <- lapply(tiledb::dimensions(x), arrow_field_from_tiledb_dim)
if (!is.null(x@arrptr)) {
attfields <- lapply(tiledb::attrs(x), arrow_field_from_tiledb_attr, x@arrptr)
} else {
attfields <- lapply(tiledb::attrs(x), arrow_field_from_tiledb_attr)
}
arrow::schema(c(dimfields, attfields))
}

#' Validate external pointer to ArrowArray which is embedded in a nanoarrow S3 type
#' @noRd
check_arrow_pointers <- function(arrlst) {
Expand Down
81 changes: 0 additions & 81 deletions apis/r/tests/testthat/test-01-Arrow-utils.R
Original file line number Diff line number Diff line change
@@ -1,84 +1,3 @@
test_that("TileDB classes can be converted to Arrow equivalents", {
# Dimension to Arrow field
dim0 <- tiledb::tiledb_dim(
name = "dim0",
domain = NULL,
tile = NULL,
type = "ASCII"
)

dim1 <- tiledb::tiledb_dim(
name = "dim1",
domain = bit64::as.integer64(c(0, 100)),
tile = bit64::as.integer64(10),
type = "INT64"
)

# Error if not a dimension
expect_error(arrow_field_from_tiledb_attr(dim0))

# String dimension
dim0_field <- arrow_field_from_tiledb_dim(dim0)
expect_true(is_arrow_field(dim0_field))
expect_equal(dim0_field$name, tiledb::name(dim0))
expect_equal(
tiledb_type_from_arrow_type(dim0_field$type, is_dim = TRUE),
tiledb::datatype(dim0)
)

# Integer dimension
dim1_field <- arrow_field_from_tiledb_dim(dim1)
expect_true(is_arrow_field(dim1_field))
expect_equal(dim1_field$name, tiledb::name(dim1))
expect_equal(
tiledb_type_from_arrow_type(dim1_field$type, is_dim = TRUE),
tiledb::datatype(dim1)
)

# Attribute to Arrow field
attr0 <- tiledb::tiledb_attr(
name = "attr0",
type = "UTF8"
)

attr1 <- tiledb::tiledb_attr(
name = "attr1",
type = "INT64"
)

# Error if not an attribute
expect_error(arrow_field_from_tiledb_attr(dim0))

# String attribute
attr0_field <- arrow_field_from_tiledb_attr(attr0)
expect_true(is_arrow_field(attr0_field))
expect_equal(attr0_field$name, tiledb::name(attr0))
expect_equal(
tiledb_type_from_arrow_type(attr0_field$type, is_dim = FALSE),
tiledb::datatype(attr0)
)

# Integer attribute
attr1_field <- arrow_field_from_tiledb_attr(attr1)
expect_true(is_arrow_field(attr1_field))
expect_equal(attr1_field$name, tiledb::name(attr1))
expect_equal(
tiledb_type_from_arrow_type(attr1_field$type, is_dim = FALSE),
tiledb::datatype(attr1)
)

# TileDB schema to Arrow schema
tdb_schema <- tiledb::tiledb_array_schema(
domain = tiledb::tiledb_domain(c(dim0, dim1)),
attrs = c(attr0, attr1),
sparse = TRUE
)

arrow_schema <- arrow_schema_from_tiledb_schema(tdb_schema)
expect_true(is_arrow_schema(arrow_schema))
expect_equal(length(arrow_schema$fields), 4)
expect_equal(names(arrow_schema), c("dim0", "dim1", "attr0", "attr1"))
})

test_that("Validating arrow data type compatibility", {
expect_false(check_arrow_data_types(arrow::int32(), arrow::float32()))
Expand Down
4 changes: 0 additions & 4 deletions apis/r/tests/testthat/test-11-OrderedAndFactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ test_that("SOMADataFrame round-trip with factor and ordered", {
tsch <- tiledb::schema(turi)
expect_true(inherits(tsch, "tiledb_array_schema"))

## we no longer use this one though
sch <- tiledbsoma:::arrow_schema_from_tiledb_schema(tsch)
expect_true(inherits(sch, "Schema"))

att <- arrow::as_arrow_table(ett)
expect_true(inherits(att, "Table"))

Expand Down