diff --git a/tiledb/sm/array/array.cc b/tiledb/sm/array/array.cc index ea629cd3ca0..a9fea9a2f75 100644 --- a/tiledb/sm/array/array.cc +++ b/tiledb/sm/array/array.cc @@ -599,43 +599,47 @@ std::vector> Array::get_enumerations( enmrs_to_load.insert(enmr_name); } - std::vector> loaded; + // Only attempt to load enumerations if we have at least one Enumeration + // to load. + if (enmrs_to_load.size() > 0) { + std::vector> loaded; - if (remote_) { - auto rest_client = resources_.rest_client(); - if (rest_client == nullptr) { - throw ArrayException( - "Error loading enumerations; " - "Remote array with no REST client."); - } + if (remote_) { + auto rest_client = resources_.rest_client(); + if (rest_client == nullptr) { + throw ArrayException( + "Error loading enumerations; " + "Remote array with no REST client."); + } - std::vector names_to_load; - for (auto& enmr_name : enmrs_to_load) { - names_to_load.push_back(enmr_name); - } + std::vector names_to_load; + for (auto& enmr_name : enmrs_to_load) { + names_to_load.push_back(enmr_name); + } - loaded = rest_client->post_enumerations_from_rest( - array_uri_, - timestamp_start_, - timestamp_end_opened_at_, - this, - names_to_load); - } else { - // Create a vector of paths to be loaded. - std::vector paths_to_load; - for (auto& enmr_name : enmrs_to_load) { - auto path = array_schema_latest_->get_enumeration_path_name(enmr_name); - paths_to_load.push_back(path); - } + loaded = rest_client->post_enumerations_from_rest( + array_uri_, + timestamp_start_, + timestamp_end_opened_at_, + this, + names_to_load); + } else { + // Create a vector of paths to be loaded. + std::vector paths_to_load; + for (auto& enmr_name : enmrs_to_load) { + auto path = array_schema_latest_->get_enumeration_path_name(enmr_name); + paths_to_load.push_back(path); + } - // Load the enumerations from storage - loaded = array_dir_.load_enumerations_from_paths( - paths_to_load, get_encryption_key()); - } + // Load the enumerations from storage + loaded = array_dir_.load_enumerations_from_paths( + paths_to_load, get_encryption_key()); + } - // Store the loaded enumerations in the schema - for (auto& enmr : loaded) { - array_schema_latest_->store_enumeration(enmr); + // Store the loaded enumerations in the schema + for (auto& enmr : loaded) { + array_schema_latest_->store_enumeration(enmr); + } } // Return the requested list of enumerations diff --git a/tiledb/sm/array/array_directory.cc b/tiledb/sm/array/array_directory.cc index e04221213ab..f6fdf9d8afa 100644 --- a/tiledb/sm/array/array_directory.cc +++ b/tiledb/sm/array/array_directory.cc @@ -192,6 +192,13 @@ std::vector> ArrayDirectory::load_enumerations_from_paths( const std::vector& enumeration_paths, const EncryptionKey& encryption_key) const { + // This should never be called with an empty list of enumeration paths, but + // there's no reason to not check an early return case here given that code + // changes. + if (enumeration_paths.size() == 0) { + return {}; + } + std::vector> ret(enumeration_paths.size()); auto& tp = resources_.get().io_tp(); throw_if_not_ok(parallel_for(&tp, 0, enumeration_paths.size(), [&](size_t i) { diff --git a/tiledb/sm/rest/rest_client.cc b/tiledb/sm/rest/rest_client.cc index 5556e568fa6..a94c9537f81 100644 --- a/tiledb/sm/rest/rest_client.cc +++ b/tiledb/sm/rest/rest_client.cc @@ -524,6 +524,13 @@ RestClient::post_enumerations_from_rest( "Error getting enumerations from REST; array is null."); } + // This should never be called with an empty list of enumeration names, but + // there's no reason to not check an early return case here given that code + // changes. + if (enumeration_names.size() == 0) { + return {}; + } + Buffer buf; serialization::serialize_load_enumerations_request( array->config(), enumeration_names, serialization_type_, buf);