Skip to content

Commit f3dcb3d

Browse files
committed
Fix 'tiledb_array_schema' enumeration mapping
1 parent 841d447 commit f3dcb3d

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

R/ArraySchema.R

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,22 @@ tiledb_array_schema <- function(
114114
)
115115
# if (allows_dups && !sparse) stop("'allows_dups' requires 'sparse' TRUE")
116116

117-
attr_ptr_list <- if (is.list(attrs)) lapply(attrs, function(obj) slot(obj, "ptr")) else list()
117+
if (is.list(attrs)) {
118+
attr_names <- sapply(attrs, name)
119+
attr_ptr_list <- lapply(attrs, function(obj) slot(obj, "ptr"))
120+
names(attr_ptr_list) <- attr_names
121+
122+
# Do not allow enum named list to have different names than attributes
123+
if (!is.null(enumerations)) {
124+
if (!all(names(enumerations) %in% attr_names)) {
125+
stop("'enumerations' should be a named list mapped to attributes names")
126+
}
127+
}
128+
129+
} else {
130+
attr_ptr_list <- list()
131+
}
132+
118133
coords_filter_list_ptr <- if (!is.null(coords_filter_list)) coords_filter_list@ptr else NULL
119134
offsets_filter_list_ptr <- if (!is.null(offsets_filter_list)) offsets_filter_list@ptr else NULL
120135
validity_filter_list_ptr <- if (!is.null(validity_filter_list)) validity_filter_list@ptr else NULL

src/libtiledb.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,11 +1914,13 @@ XPtr<tiledb::ArraySchema> libtiledb_array_schema(
19141914
for (R_xlen_t i = 0; i < nenum; i++) {
19151915
bool nn = enumerations[i] == R_NilValue;
19161916
if (nn == false) {
1917-
XPtr<tiledb::Attribute> attr =
1918-
as<XPtr<tiledb::Attribute>>(attributes[i]);
19191917
std::vector<std::string> enums =
19201918
as<std::vector<std::string>>(enumerations[i]);
19211919
std::string enum_name = std::string(enumnames[i]);
1920+
1921+
XPtr<tiledb::Attribute> attr =
1922+
as<XPtr<tiledb::Attribute>>(attributes[enum_name]);
1923+
19221924
bool is_ordered = false; // default
19231925
// 'ordered' is an attribute off the CharacterVector
19241926
CharacterVector enumvect = enumerations[i];

0 commit comments

Comments
 (0)