From 6cbda152fb1da93984c59881978fb482ee018a12 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Fri, 4 Oct 2024 12:17:03 -0400 Subject: [PATCH] complete the square by implementing `can_upgrade_soma_joinid_shape` --- libtiledbsoma/src/soma/soma_array.cc | 29 +++++++++++++++++++--------- libtiledbsoma/src/soma/soma_array.h | 24 ++++++++++++++++++++++- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/libtiledbsoma/src/soma/soma_array.cc b/libtiledbsoma/src/soma/soma_array.cc index 394427df5a..b95494d045 100644 --- a/libtiledbsoma/src/soma/soma_array.cc +++ b/libtiledbsoma/src/soma/soma_array.cc @@ -1578,17 +1578,28 @@ std::pair SOMAArray::_can_set_shape_domainish_subhelper( return std::pair(true, ""); } -std::pair SOMAArray::can_resize_soma_joinid_shape( - int64_t newshape, std::string function_name_for_messages) { +std::pair 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. diff --git a/libtiledbsoma/src/soma/soma_array.h b/libtiledbsoma/src/soma/soma_array.h index d6a8508a82..c4b795c9fa 100644 --- a/libtiledbsoma/src/soma/soma_array.h +++ b/libtiledbsoma/src/soma/soma_array.h @@ -1095,7 +1095,20 @@ class SOMAArray : public SOMAObject { * for maybe_resize_soma_joinid. */ std::pair 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 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 @@ -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 _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. */