Skip to content

Commit

Permalink
[r] Min-sizing for dataframes/arrays [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Oct 19, 2024
1 parent 60bdcf5 commit c97a86b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
21 changes: 20 additions & 1 deletion apis/r/R/utils-arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,26 @@ get_domain_and_extent_dataframe <- function(tbl_schema, ind_col_names, domain =

requested_slot <- domain[[ind_col_name]]
ind_cur_dom <- if (is.null(requested_slot)) {
ind_max_dom
if (.new_shape_feature_flag_is_enabled()) {
# New shape: if the slot is null, make the size as small
# as possible since current domain can only be resized upward.
#
# Core current-domain semantics are (lo, hi) with both
# inclusive, with lo <= hi. This means smallest is (0, 0)
# which is shape 1, not 0.
if (bit64::is.integer64(ind_max_dom)) {
c(bit64::as.integer64(0), bit64::as.integer64(0))
} else if (is.integer(ind_max_dom)) {
c(0L, 0L)
} else {
c(0, 0)
}
} else {
# Old shape: if the slot is null, make the size as large
# as possible since there is not current domain, and the
# max domain is immutable.
ind_max_dom
}
} else {
requested_slot
}
Expand Down
12 changes: 12 additions & 0 deletions apis/r/tests/testthat/helper-test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,15 @@ create_arrow_table <- function(nrows = 10L, factors = FALSE) {
# schema = create_arrow_schema(false)
)
}

domain_for_arrow_table <- function() {
return(
list(
int_column = c(0, 1000000),
soma_joinid = c(0, 1000000),
float_column = c(-1e6, 1e6),
string_column = NULL,
grp = NULL
)
)
}
16 changes: 14 additions & 2 deletions apis/r/tests/testthat/helper-test-soma-objects.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Returns the object created, populated, and closed (unless otherwise requested)

create_and_populate_soma_dataframe <- function(
uri,
nrows = 10L,
Expand All @@ -9,10 +10,21 @@ create_and_populate_soma_dataframe <- function(
) {
set.seed(seed)

# arrow_schema <- create_arrow_schema()
tbl <- create_arrow_table(nrows = nrows, factors = factors)

sdf <- SOMADataFrameCreate(uri, tbl$schema, index_column_names = index_column_names)
full_domain <- domain_for_arrow_table()
domain <- list()
for (index_column in index_column_names) {
domain[[index_column]] <- full_domain[[index_column]]
}

sdf <- SOMADataFrameCreate(
uri,
tbl$schema,
index_column_names = index_column_names,
domain = domain
)

sdf$write(tbl)

if (is.null(mode)) {
Expand Down

0 comments on commit c97a86b

Please sign in to comment.