Skip to content

Commit

Permalink
complete the square by implementing can_upgrade_soma_joinid_shape
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Oct 4, 2024
1 parent 9b54d0a commit 6cbda15
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
29 changes: 20 additions & 9 deletions libtiledbsoma/src/soma/soma_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1578,17 +1578,28 @@ std::pair<bool, std::string> SOMAArray::_can_set_shape_domainish_subhelper(
return std::pair(true, "");
}

std::pair<bool, std::string> SOMAArray::can_resize_soma_joinid_shape(
int64_t newshape, std::string function_name_for_messages) {
std::pair<bool, std::string> SOMAArray::_can_set_soma_joinid_shape_helper(
int64_t newshape, bool is_resize, std::string function_name_for_messages) {
// Fail if the array doesn't already have a shape yet (they should upgrade
// first).
if (!has_current_domain()) {
return std::pair(
false,
fmt::format(
"{}: dataframe currently has no domain set: please "
"upgrade the array.",
function_name_for_messages));
if (is_resize) {
if (!has_current_domain()) {
return std::pair(
false,
fmt::format(
"{}: dataframe currently has no domain set: please "
"upgrade the array.",
function_name_for_messages));
}

} else {
if (!has_current_domain()) {
return std::pair(
false,
fmt::format(
"{}: dataframe already has a shape set.",
function_name_for_messages));
}
}

// OK if soma_joinid isn't a dim.
Expand Down
24 changes: 23 additions & 1 deletion libtiledbsoma/src/soma/soma_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,20 @@ class SOMAArray : public SOMAObject {
* for maybe_resize_soma_joinid.
*/
std::pair<bool, std::string> can_resize_soma_joinid_shape(
int64_t newshape, std::string function_name_for_messages);
int64_t newshape, std::string function_name_for_messages) {
return _can_set_soma_joinid_shape_helper(
newshape, true, function_name_for_messages);
}

/**
* This is similar to can_upgrade_shape, but it's a can-we call
* for maybe_resize_soma_joinid.
*/
std::pair<bool, std::string> can_upgrade_soma_joinid_shape(
int64_t newshape, std::string function_name_for_messages) {
return _can_set_soma_joinid_shape_helper(
newshape, false, function_name_for_messages);
}

/**
* @brief Resize the shape (what core calls "current domain") up to the
Expand Down Expand Up @@ -1211,6 +1224,15 @@ class SOMAArray : public SOMAObject {
bool check_current_domain,
std::string function_name_for_messages);

/**
* This is a code-dedupe helper for can_resize_soma_joinid_shape and
* can_upgrade_soma_joinid_shape.
*/
std::pair<bool, std::string> _can_set_soma_joinid_shape_helper(
int64_t newshape,
bool is_resize,
std::string function_name_for_messages);

/**
* This is a code-dedupe helper method for resize and upgrade_shape.
*/
Expand Down

0 comments on commit 6cbda15

Please sign in to comment.