Skip to content

Commit

Permalink
[r] Make DataFrame objects shapeable at ingest (#3089)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl authored Oct 1, 2024
1 parent 303705d commit 40e2178
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions apis/r/R/write_soma.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,31 @@ write_soma.data.frame <- function(
choices = names(x),
several.ok = TRUE
)

# For index_column_name being soma_joinid -- this being the default
# -- set that domain slot to match the data. This will endow the
# dataframe with something users think of as a "shape". For the
# other slots, set the domain wide open.
#
domain <- NULL
if (.new_shape_feature_flag_is_enabled()) {
domain <- list()
for (index_column_name in index_column_names) {
if (index_column_name == "soma_joinid") {
domain[["soma_joinid"]] <- c(0, nrow(x) - 1)
} else {
domain[[index_column_name]] <- NULL
}
}
}

# Create the SOMADataFrame
tbl <- arrow::arrow_table(x)
sdf <- SOMADataFrameCreate(
uri = uri,
schema = tbl$schema,
index_column_names = index_column_names,
domain = domain,
ingest_mode = ingest_mode,
platform_config = platform_config,
tiledbsoma_ctx = tiledbsoma_ctx
Expand All @@ -239,6 +258,9 @@ write_soma.data.frame <- function(
NULL
}
}
if (ingest_mode %in% c('resume') && sdf$tiledbsoma_has_upgraded_domain()) {
sdf$resize_soma_joinid(nrow(x))
}
if (!is.null(tbl)) {
sdf$write(tbl)
}
Expand Down
5 changes: 5 additions & 0 deletions apis/r/tests/testthat/test-write-soma-resume.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ test_that("Resume-mode data frames", {
}
}

if (.new_shape_feature_flag_is_enabled()) {
sdfp$reopen("WRITE")
sdfp$resize_soma_joinid(nrow(co2))
}

expect_s3_class(
sdfc <- write_soma(
co2,
Expand Down

0 comments on commit 40e2178

Please sign in to comment.