Skip to content

Commit

Permalink
Add test for loading enumerations for all schemas.
Browse files Browse the repository at this point in the history
+ Fix test failure in CI.
  • Loading branch information
shaunrd0 committed Aug 14, 2024
1 parent 83e018d commit 30d4a81
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
63 changes: 63 additions & 0 deletions test/src/unit-enumerations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArraySchemaEvolution>(HERE(), memory_tracker_);
std::vector<std::string> 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<Attribute>(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<ArraySchemaEvolution>(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",
Expand Down
4 changes: 4 additions & 0 deletions tiledb/sm/array/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,10 @@ void Array::encryption_type(

shared_ptr<const Enumeration> 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];
}
Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/array_schema/array_schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() + "'.");
}
}
Expand Down

0 comments on commit 30d4a81

Please sign in to comment.