@@ -805,33 +805,85 @@ void Array::encryption_type(
805805
806806shared_ptr<const Enumeration> Array::get_enumeration (
807807 const std::string& enumeration_name) {
808+ return get_enumerations ({enumeration_name})[0 ];
809+ }
810+
811+ std::unordered_map<std::string, std::vector<shared_ptr<const Enumeration>>>
812+ Array::get_enumerations_all_schemas () {
808813 if (!is_open_) {
809814 throw ArrayException (" Unable to load enumerations; Array is not open." );
810815 }
811816
812- auto schema = opened_array_->array_schema_latest_ptr ();
813- if (!schema->has_enumeration (enumeration_name)) {
814- throw ArrayException (
815- " Unable to get enumeration; Enumeration '" + enumeration_name +
816- " ' does not exist." );
817- } else if (schema->is_enumeration_loaded (enumeration_name)) {
818- return schema->get_enumeration (enumeration_name);
817+ std::unordered_map<std::string, std::vector<shared_ptr<const Enumeration>>>
818+ ret;
819+ if (remote_) {
820+ auto rest_client = resources_.rest_client ();
821+ if (rest_client == nullptr ) {
822+ throw ArrayException (
823+ " Error loading enumerations; Remote array with no REST client." );
824+ }
825+
826+ // Pass an empty list of enumeration names. REST will use timestamps to
827+ // load all enumerations on all schemas for the array within that range.
828+ ret = rest_client->post_enumerations_from_rest (
829+ array_uri_,
830+ array_dir_timestamp_start_,
831+ array_dir_timestamp_end_,
832+ this ,
833+ {},
834+ memory_tracker_);
835+
836+ // Store the enumerations from the REST response.
837+ for (const auto & schema_enmrs : ret) {
838+ auto schema = array_schemas_all ().at (schema_enmrs.first );
839+ for (const auto & enmr : schema_enmrs.second ) {
840+ schema->store_enumeration (enmr);
841+ }
842+ }
843+ } else {
844+ for (const auto & schema : array_schemas_all ()) {
845+ std::unordered_set<std::string> enmrs_to_load;
846+ auto enumeration_names = schema.second ->get_enumeration_names ();
847+ // Dedupe requested names and filter out anything already loaded.
848+ for (auto & enmr_name : enumeration_names) {
849+ if (schema.second ->is_enumeration_loaded (enmr_name)) {
850+ continue ;
851+ }
852+ enmrs_to_load.insert (enmr_name);
853+ }
854+
855+ // Create a vector of paths to be loaded.
856+ std::vector<std::string> paths_to_load;
857+ for (auto & enmr_name : enmrs_to_load) {
858+ auto path = schema.second ->get_enumeration_path_name (enmr_name);
859+ paths_to_load.push_back (path);
860+ }
861+
862+ // Load the enumerations from storage
863+ auto loaded = array_directory ().load_enumerations_from_paths (
864+ paths_to_load, *encryption_key (), memory_tracker_);
865+
866+ // Store the loaded enumerations in the schema.
867+ for (auto & enmr : loaded) {
868+ schema.second ->store_enumeration (enmr);
869+ }
870+ ret[schema.first ] = loaded;
871+ }
819872 }
820873
821- return get_enumerations ({enumeration_name}, schema)[ 0 ] ;
874+ return ret ;
822875}
823876
824877std::vector<shared_ptr<const Enumeration>> Array::get_enumerations (
825- const std::vector<std::string>& enumeration_names,
826- shared_ptr<ArraySchema> schema) {
878+ const std::vector<std::string>& enumeration_names) {
827879 if (!is_open_) {
828880 throw ArrayException (" Unable to load enumerations; Array is not open." );
829881 }
830882
831883 // Dedupe requested names and filter out anything already loaded.
832884 std::unordered_set<std::string> enmrs_to_load;
833885 for (auto & enmr_name : enumeration_names) {
834- if (schema-> is_enumeration_loaded (enmr_name)) {
886+ if (array_schema_latest (). is_enumeration_loaded (enmr_name)) {
835887 continue ;
836888 }
837889 enmrs_to_load.insert (enmr_name);
@@ -856,16 +908,16 @@ std::vector<shared_ptr<const Enumeration>> Array::get_enumerations(
856908
857909 loaded = rest_client->post_enumerations_from_rest (
858910 array_uri_,
859- schema-> timestamp_range (). first ,
860- schema-> timestamp_range (). second ,
911+ array_dir_timestamp_start_ ,
912+ array_dir_timestamp_end_ ,
861913 this ,
862914 names_to_load,
863- memory_tracker_);
915+ memory_tracker_)[ array_schema_latest (). name ()] ;
864916 } else {
865917 // Create a vector of paths to be loaded.
866918 std::vector<std::string> paths_to_load;
867919 for (auto & enmr_name : enmrs_to_load) {
868- auto path = schema-> get_enumeration_path_name (enmr_name);
920+ auto path = array_schema_latest (). get_enumeration_path_name (enmr_name);
869921 paths_to_load.push_back (path);
870922 }
871923
@@ -876,25 +928,36 @@ std::vector<shared_ptr<const Enumeration>> Array::get_enumerations(
876928
877929 // Store the loaded enumerations in the schema
878930 for (auto & enmr : loaded) {
879- schema ->store_enumeration (enmr);
931+ opened_array_-> array_schema_latest_ptr () ->store_enumeration (enmr);
880932 }
881933 }
882934
883935 // Return the requested list of enumerations
884936 std::vector<shared_ptr<const Enumeration>> ret (enumeration_names.size ());
885937 for (size_t i = 0 ; i < enumeration_names.size (); i++) {
886- ret[i] = schema-> get_enumeration (enumeration_names[i]);
938+ ret[i] = array_schema_latest (). get_enumeration (enumeration_names[i]);
887939 }
888940 return ret;
889941}
890942
891- void Array::load_all_enumerations () {
943+ void Array::load_all_enumerations (bool all_schemas ) {
892944 if (!is_open_) {
893945 throw ArrayException (" Unable to load all enumerations; Array is not open." );
894946 }
895947 // Load all enumerations, discarding the returned list of loaded enumerations.
896- for (const auto & schema : array_schemas_all ()) {
897- get_enumerations (schema.second ->get_enumeration_names (), schema.second );
948+ if (all_schemas) {
949+ // Unless we are using array open V3, Array::array_schemas_all_ will not be
950+ // initialized. We throw an exception since this is required to store the
951+ // loaded enumerations.
952+ if (!use_refactored_array_open ()) {
953+ throw ArrayException (
954+ " Unable to load enumerations for all array schemas; The array must "
955+ " be opened using `rest.use_refactored_array_open=true`" );
956+ }
957+
958+ get_enumerations_all_schemas ();
959+ } else {
960+ get_enumerations (array_schema_latest ().get_enumeration_names ());
898961 }
899962}
900963
0 commit comments