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] Call array schema evolution after loop setting up enums #2201

Merged
merged 1 commit into from
Mar 5, 2024
Merged
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
6 changes: 4 additions & 2 deletions apis/r/R/SOMADataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ SOMADataFrame <- R6::R6Class(
has_enums <- tiledb::tiledb_array_has_enumeration(arr)
if (any(has_enums)) { # if enumerations exists in array
attrs <- tiledb::attrs(tiledb::schema(arr))
ase <- tiledb::tiledb_array_schema_evolution()
call_ase <- FALSE
if (!tiledb::tiledb_array_is_open(arr)) arr <- tiledb::tiledb_array_open(arr, "READ")
for (attr_name in names(attrs)) {
if (has_enums[attr_name]) {
Expand All @@ -186,14 +188,14 @@ SOMADataFrame <- R6::R6Class(
stop(sprintf("For column '%s' cannot add %d factor levels to existing %d for type '%s' with maximum value %d",
attr_name, length(added_enum), length(old_enum), datatype, maxval), call. = FALSE)
}
ase <- tiledb::tiledb_array_schema_evolution()
call_ase <- TRUE
ase <- tiledb::tiledb_array_schema_evolution_extend_enumeration(ase, arr, attr_name, added_enum)
tiledb::tiledb_array_schema_evolution_array_evolve(ase, self$uri)
df[, attr_name] <- factor(df[, attr_name], levels = unique(c(old_enum,new_enum)), ordered=is.ordered(df[, attr_name]))
spdl::debug("[tiledbsoma$write] writing '{}' '{}' {}", paste(unique(c(old_enum,new_enum)),collapse=","), paste(added_enum,collapse=","), is.ordered(df[, attr_name]))
}
}
}
if (call_ase) tiledb::tiledb_array_schema_evolution_array_evolve(ase, self$uri)
arr <- tiledb::tiledb_array_close(arr)
arr <- tiledb::tiledb_array_open(arr, "WRITE")
}
Expand Down
Loading