Skip to content

Commit

Permalink
Follow up on requested changes from #5359 (#5368)
Browse files Browse the repository at this point in the history
#5359 was merged and then there were some additional changes requested.
This pull request implements those changes.
- [fix a comment
typo](#5359 (comment))
- [avoid nested C API calls and fix memory
leak](#5359 (comment))
- [add a test with schema
evolution](#5359 (comment))

---
TYPE: BUG
DESC: Follow up on #5359
  • Loading branch information
rroelke authored Nov 14, 2024
1 parent 8133b35 commit 808640a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
28 changes: 28 additions & 0 deletions test/src/unit-cppapi-enumerations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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<uint16_t>(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",
Expand Down
34 changes: 20 additions & 14 deletions tiledb/api/c_api/array_schema/array_schema_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() ? "<anonymous>" : 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
*
Expand Down

0 comments on commit 808640a

Please sign in to comment.