diff --git a/test/src/unit-enumerations.cc b/test/src/unit-enumerations.cc index 167a4b1096ca..97a4266926f5 100644 --- a/test/src/unit-enumerations.cc +++ b/test/src/unit-enumerations.cc @@ -1119,6 +1119,69 @@ TEST_CASE_METHOD( REQUIRE(schema->is_enumeration_loaded("test_enmr") == true); } +TEST_CASE_METHOD( + EnumerationFx, + "Array - Load All Enumerations - All Schemas", + "[enumeration][array][load-all-enumerations][all-schemas]") { + create_array(); + auto array = get_array(QueryType::READ); + auto schema = array->array_schema_latest_ptr(); + REQUIRE(schema->is_enumeration_loaded("test_enmr") == false); + std::string schema_name_1 = schema->name(); + + // Evolve once to add an enumeration. + auto ase = make_shared(HERE(), memory_tracker_); + std::vector var_values{"one", "two", "three"}; + auto var_enmr = create_enumeration( + var_values, false, Datatype::STRING_ASCII, "ase_var_enmr"); + ase->add_enumeration(var_enmr); + auto attr4 = make_shared(HERE(), "attr4", Datatype::UINT16); + attr4->set_enumeration_name("ase_var_enmr"); + CHECK_NOTHROW(ase->evolve_schema(schema)); + // Apply evolution to the array and reopen. + CHECK_NOTHROW(Array::evolve_array_schema( + ctx_.resources(), uri_, ase.get(), array->get_encryption_key())); + CHECK(array->reopen().ok()); + CHECK_NOTHROW(array->load_all_enumerations()); + auto all_schemas = array->array_schemas_all(); + schema = array->array_schema_latest_ptr(); + std::string schema_name_2 = schema->name(); + + // Check all schemas. + CHECK(all_schemas[schema_name_1]->is_enumeration_loaded("test_enmr") == true); + CHECK(all_schemas[schema_name_2]->is_enumeration_loaded("test_enmr") == true); + CHECK( + all_schemas[schema_name_2]->is_enumeration_loaded("ase_var_enmr") == + true); + + // Evolve a second time to drop an enumeration. + ase = make_shared(HERE(), memory_tracker_); + ase->drop_enumeration("test_enmr"); + ase->drop_attribute("attr1"); + CHECK_NOTHROW(ase->evolve_schema(schema)); + // Apply evolution to the array and reopen. + CHECK_NOTHROW(Array::evolve_array_schema( + ctx_.resources(), uri_, ase.get(), array->get_encryption_key())); + CHECK(array->reopen().ok()); + CHECK_NOTHROW(array->load_all_enumerations()); + all_schemas = array->array_schemas_all(); + schema = array->array_schema_latest_ptr(); + std::string schema_name_3 = schema->name(); + + // Check all schemas. + CHECK(all_schemas[schema_name_1]->is_enumeration_loaded("test_enmr") == true); + CHECK(all_schemas[schema_name_2]->is_enumeration_loaded("test_enmr") == true); + CHECK( + all_schemas[schema_name_2]->is_enumeration_loaded("ase_var_enmr") == + true); + CHECK_THROWS_WITH( + all_schemas[schema_name_3]->is_enumeration_loaded("test_enmr"), + Catch::Matchers::ContainsSubstring("No enumeration named")); + CHECK( + all_schemas[schema_name_3]->is_enumeration_loaded("ase_var_enmr") == + true); +} + TEST_CASE_METHOD( EnumerationFx, "Array - Load All Enumerations - Repeated", diff --git a/tiledb/sm/array/array.cc b/tiledb/sm/array/array.cc index 972500a29223..231440197334 100644 --- a/tiledb/sm/array/array.cc +++ b/tiledb/sm/array/array.cc @@ -804,6 +804,10 @@ void Array::encryption_type( shared_ptr Array::get_enumeration( const std::string& enumeration_name) { + if (!is_open_) { + throw ArrayException("Unable to load enumerations; Array is not open."); + } + return get_enumerations( {enumeration_name}, opened_array_->array_schema_latest_ptr())[0]; } diff --git a/tiledb/sm/array_schema/array_schema.cc b/tiledb/sm/array_schema/array_schema.cc index 24df5692c67e..1de4e2982f8b 100644 --- a/tiledb/sm/array_schema/array_schema.cc +++ b/tiledb/sm/array_schema/array_schema.cc @@ -1150,7 +1150,7 @@ void ArraySchema::drop_enumeration(const std::string& enmr_name) { } if (attr_enmr_name.value() == enmr_name) { throw ArraySchemaException( - "Unable to drop enumeration '" + enmr_name + "' as it is used by " + + "Unable to drop enumeration '" + enmr_name + "' as it is used by" + " attribute '" + attr->name() + "'."); } }