diff --git a/test/src/unit-cppapi-enumerations.cc b/test/src/unit-cppapi-enumerations.cc index 63e94753a92..03222cc2378 100644 --- a/test/src/unit-cppapi-enumerations.cc +++ b/test/src/unit-cppapi-enumerations.cc @@ -902,6 +902,34 @@ TEST_CASE_METHOD( REQUIRE(rc != TILEDB_OK); } +TEST_CASE_METHOD( + CPPEnumerationFx, + "C API: ArraySchemaEvolution - Add Enumeration, retrieve with " + "ArraySchema::get_enumeration_from_name", + "[enumeration][array-schema-evolution][array-schema-get-enumeration-from-" + "name][rest]") { + create_array(); + + // Evolve once to add an enumeration. + ArraySchemaEvolution ase(ctx_); + std::vector var_values{"one", "two", "three"}; + auto var_enmr = Enumeration::create(ctx_, "ase_var_enmr", var_values); + ase.add_enumeration(var_enmr); + auto attr4 = Attribute::create(ctx_, "attr4"); + AttributeExperimental::set_enumeration_name(ctx_, attr4, "ase_var_enmr"); + ase.add_attribute(attr4); + // Apply evolution to the array and reopen. + ase.array_evolve(uri_); + + auto schema = Array::load_schema(ctx_, uri_); + auto actual_enumeration = ArraySchemaExperimental::get_enumeration_from_name( + ctx_, schema, "ase_var_enmr"); + + CHECK(test::is_equivalent_enumeration( + *var_enmr.ptr()->enumeration(), + *actual_enumeration.ptr()->enumeration())); +} + TEST_CASE_METHOD( CPPEnumerationFx, "CPP: Enumeration Query - Basic", diff --git a/tiledb/api/c_api/array_schema/array_schema_api.cc b/tiledb/api/c_api/array_schema/array_schema_api.cc index dfaf4d093f4..ea343ecf5a0 100644 --- a/tiledb/api/c_api/array_schema/array_schema_api.cc +++ b/tiledb/api/c_api/array_schema/array_schema_api.cc @@ -210,24 +210,30 @@ capi_return_t tiledb_array_schema_get_enumeration_from_attribute_name( ensure_array_schema_is_valid(array_schema); ensure_output_pointer_is_valid(enumeration); - tiledb_attribute_t* attribute; - capi_return_t getattr = tiledb_array_schema_get_attribute_from_name( - ctx, array_schema, attribute_name, &attribute); - if (tiledb_status(getattr) != TILEDB_OK) { - return getattr; + if (attribute_name == nullptr) { + throw CAPIException("'attribute_name' must not be null"); + } + std::string attribute_name_string(attribute_name); + auto found_attr = array_schema->shared_attribute(attribute_name_string); + if (!found_attr) { + throw CAPIException( + std::string("Attribute name: ") + + (attribute_name_string.empty() ? "" : attribute_name) + + " does not exist for array " + array_schema->array_uri().to_string()); } - tiledb_string_t* enumeration_name_inner; - capi_return_t getenmr = tiledb_attribute_get_enumeration_name( - ctx, attribute, &enumeration_name_inner); - if (tiledb_status(getenmr) != TILEDB_OK) { - return getenmr; + auto enumeration_name = found_attr->get_enumeration_name(); + if (!enumeration_name.has_value()) { + *enumeration = nullptr; + return TILEDB_OK; } - std::string enumeration_name(enumeration_name_inner->view()); - return api_entry_with_context< - tiledb::api::tiledb_array_schema_get_enumeration_from_name>( - ctx, array_schema, enumeration_name.c_str(), enumeration); + array_schema->load_enumeration(ctx, enumeration_name->c_str()); + + auto ptr = array_schema->get_enumeration(enumeration_name->c_str()); + *enumeration = tiledb_enumeration_handle_t::make_handle(ptr); + + return TILEDB_OK; } capi_return_t tiledb_array_schema_add_enumeration( diff --git a/tiledb/api/c_api/array_schema/array_schema_api_experimental.h b/tiledb/api/c_api/array_schema/array_schema_api_experimental.h index ca2cd467c4e..02e98aecc0c 100644 --- a/tiledb/api/c_api/array_schema/array_schema_api_experimental.h +++ b/tiledb/api/c_api/array_schema/array_schema_api_experimental.h @@ -68,7 +68,7 @@ TILEDB_EXPORT capi_return_t tiledb_array_schema_timestamp_range( uint64_t* hi) TILEDB_NOEXCEPT; /** - * Retrieves an enumeration from an array schema using the enumeration name, + * Retrieves an enumeration from an array schema using the enumeration name. * * **Example:** *