Skip to content

Commit

Permalink
Add ctx to CurrentDomain CAPI, adjust CPPAPI. (#5219)
Browse files Browse the repository at this point in the history
This adds a ctx parameter to all CurrentDomain CAPI calls so that
internal exceptions are propagated correctly through the capi handle
layer.
I also adjusted the CPP CurrentDomain API, the only current user of
these calls.

---
TYPE: C_API | CPP_API
DESC: Add ctx to CurrentDomain CAPI, adjust CPPAPI.
  • Loading branch information
robertbindar authored Aug 8, 2024
1 parent 58dbc08 commit b8ca549
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 78 deletions.
10 changes: 5 additions & 5 deletions examples/c_api/current_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void create_array() {
tiledb_ndrectangle_set_range_for_name(ctx, ndrect, "d1", &range);

// Assign the rectangle to the current domain
tiledb_current_domain_set_ndrectangle(current_domain, ndrect);
tiledb_current_domain_set_ndrectangle(ctx, current_domain, ndrect);

// Create a single attribute "a" so each cell can store an integer
tiledb_attribute_t* a;
Expand Down Expand Up @@ -119,21 +119,21 @@ void print_current_domain() {

// Check if current domain is empty
uint32_t is_empty;
tiledb_current_domain_get_is_empty(current_domain, &is_empty);
tiledb_current_domain_get_is_empty(ctx, current_domain, &is_empty);

if (is_empty) {
printf("Current domain: empty\n");
} else {
// Get current domain type
tiledb_current_domain_type_t current_domain_type;
tiledb_current_domain_get_type(current_domain, &current_domain_type);
tiledb_current_domain_get_type(ctx, current_domain, &current_domain_type);

if (current_domain_type == TILEDB_NDRECTANGLE) {
printf("Current domain type: NDRECTANGLE\n");

// Get the ND rectangle
tiledb_ndrectangle_t* ndrect;
tiledb_current_domain_get_ndrectangle(current_domain, &ndrect);
tiledb_current_domain_get_ndrectangle(ctx, current_domain, &ndrect);

tiledb_range_t range;
tiledb_ndrectangle_get_range_from_name(ctx, ndrect, "d1", &range);
Expand Down Expand Up @@ -203,7 +203,7 @@ void expand_current_domain() {
tiledb_ndrectangle_set_range_for_name(ctx, ndrect, "d1", &range);

// Set the rectangle to the current domain
tiledb_current_domain_set_ndrectangle(new_current_domain, ndrect);
tiledb_current_domain_set_ndrectangle(ctx, new_current_domain, ndrect);

// Expand the current domain
tiledb_array_schema_evolution_expand_current_domain(
Expand Down
13 changes: 7 additions & 6 deletions test/src/unit-capi-array_schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,8 @@ TEST_CASE_METHOD(
tiledb_array_schema_get_current_domain(ctx_, schema, &crd) == TILEDB_OK);

uint32_t is_empty = 0;
REQUIRE(tiledb_current_domain_get_is_empty(crd, &is_empty) == TILEDB_OK);
REQUIRE(
tiledb_current_domain_get_is_empty(ctx_, crd, &is_empty) == TILEDB_OK);
CHECK(is_empty == 1);

REQUIRE(tiledb_current_domain_free(&crd) == TILEDB_OK);
Expand Down Expand Up @@ -2537,7 +2538,7 @@ TEST_CASE_METHOD(

tiledb_ndrectangle_t* ndr = nullptr;
REQUIRE(tiledb_ndrectangle_alloc(ctx_, domain, &ndr) == TILEDB_OK);
REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK);
REQUIRE(tiledb_current_domain_set_ndrectangle(ctx_, crd, ndr) == TILEDB_OK);

REQUIRE(
tiledb_array_schema_set_current_domain(ctx_, schema, crd) == TILEDB_OK);
Expand Down Expand Up @@ -2604,7 +2605,7 @@ TEST_CASE_METHOD(
REQUIRE(
tiledb_array_schema_get_current_domain(ctx_, schema, &crd) == TILEDB_OK);

REQUIRE(tiledb_current_domain_get_ndrectangle(crd, &ndr) == TILEDB_OK);
REQUIRE(tiledb_current_domain_get_ndrectangle(ctx_, crd, &ndr) == TILEDB_OK);
tiledb_range_t outrange;
REQUIRE(
tiledb_ndrectangle_get_range_from_name(ctx_, ndr, "d1", &outrange) ==
Expand Down Expand Up @@ -2672,7 +2673,7 @@ TEST_CASE_METHOD(
REQUIRE(
tiledb_ndrectangle_set_range_for_name(ctx_, ndr, "d1", &range) ==
TILEDB_OK);
REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK);
REQUIRE(tiledb_current_domain_set_ndrectangle(ctx_, crd, ndr) == TILEDB_OK);
REQUIRE(
tiledb_array_schema_set_current_domain(ctx_, schema, crd) == TILEDB_OK);

Expand Down Expand Up @@ -2712,7 +2713,7 @@ TEST_CASE_METHOD(
REQUIRE(
tiledb_ndrectangle_set_range_for_name(ctx_, ndr, "d1", &range) ==
TILEDB_OK);
REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK);
REQUIRE(tiledb_current_domain_set_ndrectangle(ctx_, crd, ndr) == TILEDB_OK);

REQUIRE(
tiledb_array_schema_evolution_expand_current_domain(ctx_, evo, crd) ==
Expand Down Expand Up @@ -2752,7 +2753,7 @@ TEST_CASE_METHOD(
REQUIRE(
tiledb_array_schema_get_current_domain(ctx_, schema, &crd) == TILEDB_OK);

REQUIRE(tiledb_current_domain_get_ndrectangle(crd, &ndr) == TILEDB_OK);
REQUIRE(tiledb_current_domain_get_ndrectangle(ctx_, crd, &ndr) == TILEDB_OK);
tiledb_range_t outrange;
REQUIRE(
tiledb_ndrectangle_get_range_from_name(ctx_, ndr, "d1", &outrange) ==
Expand Down
10 changes: 6 additions & 4 deletions test/src/unit-current-domain-rest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void RestCurrentDomainFx::create_sparse_array(const std::string& array_name) {
tiledb_ndrectangle_set_range_for_name(ctx_c_, ndr, "d2", &range_var) ==
TILEDB_OK);

REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK);
REQUIRE(tiledb_current_domain_set_ndrectangle(ctx_c_, crd, ndr) == TILEDB_OK);
REQUIRE(
tiledb_array_schema_set_current_domain(ctx_c_, array_schema, crd) ==
TILEDB_OK);
Expand Down Expand Up @@ -169,7 +169,8 @@ TEST_CASE_METHOD(
tiledb_array_schema_get_current_domain(ctx_c_, schema, &crd) ==
TILEDB_OK);

REQUIRE(tiledb_current_domain_get_ndrectangle(crd, &ndr) == TILEDB_OK);
REQUIRE(
tiledb_current_domain_get_ndrectangle(ctx_c_, crd, &ndr) == TILEDB_OK);
tiledb_range_t outrange;
tiledb_range_t outrange_var;
REQUIRE(
Expand Down Expand Up @@ -239,7 +240,7 @@ TEST_CASE_METHOD(
tiledb_ndrectangle_set_range_for_name(ctx_c_, ndr, "d2", &range_var) ==
TILEDB_OK);

REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK);
REQUIRE(tiledb_current_domain_set_ndrectangle(ctx_c_, crd, ndr) == TILEDB_OK);
REQUIRE(
tiledb_array_schema_evolution_expand_current_domain(ctx_c_, evo, crd) ==
TILEDB_OK);
Expand All @@ -262,7 +263,8 @@ TEST_CASE_METHOD(
tiledb_array_schema_get_current_domain(ctx_c_, schema, &crd) ==
TILEDB_OK);

REQUIRE(tiledb_current_domain_get_ndrectangle(crd, &ndr) == TILEDB_OK);
REQUIRE(
tiledb_current_domain_get_ndrectangle(ctx_c_, crd, &ndr) == TILEDB_OK);
tiledb_range_t outrange;
REQUIRE(
tiledb_ndrectangle_get_range_from_name(ctx_c_, ndr, "d1", &outrange) ==
Expand Down
21 changes: 13 additions & 8 deletions tiledb/api/c_api/current_domain/current_domain_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ capi_return_t tiledb_current_domain_get_type(

} // namespace tiledb::api

using tiledb::api::api_entry_context;
using tiledb::api::api_entry_plain;
using tiledb::api::api_entry_with_context;

Expand All @@ -124,32 +125,36 @@ CAPI_INTERFACE(current_domain_free, tiledb_current_domain_t** current_domain) {

CAPI_INTERFACE(
current_domain_set_ndrectangle,
tiledb_ctx_t* ctx,
tiledb_current_domain_t* current_domain,
tiledb_ndrectangle_t* ndr) {
return api_entry_plain<tiledb::api::tiledb_current_domain_set_ndrectangle>(
current_domain, ndr);
return api_entry_context<tiledb::api::tiledb_current_domain_set_ndrectangle>(
ctx, current_domain, ndr);
}

CAPI_INTERFACE(
current_domain_get_ndrectangle,
tiledb_ctx_t* ctx,
tiledb_current_domain_t* current_domain,
tiledb_ndrectangle_t** ndr) {
return api_entry_plain<tiledb::api::tiledb_current_domain_get_ndrectangle>(
current_domain, ndr);
return api_entry_context<tiledb::api::tiledb_current_domain_get_ndrectangle>(
ctx, current_domain, ndr);
}

CAPI_INTERFACE(
current_domain_get_is_empty,
tiledb_ctx_t* ctx,
tiledb_current_domain_t* current_domain,
uint32_t* is_empty) {
return api_entry_plain<tiledb::api::tiledb_current_domain_get_is_empty>(
current_domain, is_empty);
return api_entry_context<tiledb::api::tiledb_current_domain_get_is_empty>(
ctx, current_domain, is_empty);
}

CAPI_INTERFACE(
current_domain_get_type,
tiledb_ctx_t* ctx,
tiledb_current_domain_t* current_domain,
tiledb_current_domain_type_t* type) {
return api_entry_plain<tiledb::api::tiledb_current_domain_get_type>(
current_domain, type);
return api_entry_context<tiledb::api::tiledb_current_domain_get_type>(
ctx, current_domain, type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,19 @@ TILEDB_EXPORT capi_return_t tiledb_current_domain_free(
* range.max_size = sizeof(max);
* tiledb_ndrectangle_set_range_for_name(ctx, ndr, "dim", &range);
*
* tiledb_current_domain_set_ndrectangle(current_domain, ndr);
* tiledb_current_domain_set_ndrectangle(ctx, current_domain, ndr);
*
* tiledb_ndrectangle_free(&ndr);
* tiledb_current_domain_free(&current_domain);
* @endcode
*
* @param ctx A TileDB context
* @param current_domain The current domain to modify
* @param ndr The N-dimensional rectangle to be set
* @return `TILEDB_OK` for success and `TILEDB_ERR` for error.
*/
TILEDB_EXPORT capi_return_t tiledb_current_domain_set_ndrectangle(
tiledb_ctx_t* ctx,
tiledb_current_domain_t* current_domain,
tiledb_ndrectangle_t* ndr) TILEDB_NOEXCEPT;

Expand All @@ -131,14 +133,16 @@ TILEDB_EXPORT capi_return_t tiledb_current_domain_set_ndrectangle(
*
* @code{.c}
* tiledb_ndrectangle_t *ndr;
* tiledb_current_domain_get_ndrectangle(current_domain, &ndr);
* tiledb_current_domain_get_ndrectangle(ctx, current_domain, &ndr);
* @endcode
*
* @param ctx A TileDB context
* @param current_domain The current domain to query
* @param ndr The N-dimensional rectangle of the current domain
* @return `TILEDB_OK` for success and `TILEDB_ERR` for error.
*/
TILEDB_EXPORT capi_return_t tiledb_current_domain_get_ndrectangle(
tiledb_ctx_t* ctx,
tiledb_current_domain_t* current_domain,
tiledb_ndrectangle_t** ndr) TILEDB_NOEXCEPT;

Expand All @@ -149,14 +153,16 @@ TILEDB_EXPORT capi_return_t tiledb_current_domain_get_ndrectangle(
*
* @code{.c}
* uint32_t empty = 0;
* tiledb_current_domain_get_is_empty(current_domain, &empty);
* tiledb_current_domain_get_is_empty(ctx, current_domain, &empty);
* @endcode
*
* @param ctx A TileDB context
* @param current_domain The current domain to query
* @param is_empty True if nothing is set on the current domain
* @return `TILEDB_OK` for success and `TILEDB_ERR` for error.
*/
TILEDB_EXPORT capi_return_t tiledb_current_domain_get_is_empty(
tiledb_ctx_t* ctx,
tiledb_current_domain_t* current_domain,
uint32_t* is_empty) TILEDB_NOEXCEPT;

Expand All @@ -167,14 +173,16 @@ TILEDB_EXPORT capi_return_t tiledb_current_domain_get_is_empty(
*
* @code{.c}
* tiledb_current_domain_type_t type;
* tiledb_current_domain_get_type(current_domain, &type);
* tiledb_current_domain_get_type(ctx, current_domain, &type);
* @endcode
*
* @param ctx A TileDB context
* @param current_domain The current domain to query
* @param type The type of representation set on the current domain
* @return `TILEDB_OK` for success and `TILEDB_ERR` for error.
*/
TILEDB_EXPORT capi_return_t tiledb_current_domain_get_type(
tiledb_ctx_t* ctx,
tiledb_current_domain_t* current_domain,
tiledb_current_domain_type_t* type) TILEDB_NOEXCEPT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
int main() {
tiledb_current_domain_create(nullptr, nullptr);
tiledb_current_domain_free(nullptr);
tiledb_current_domain_set_ndrectangle(nullptr, nullptr);
tiledb_current_domain_get_ndrectangle(nullptr, nullptr);
tiledb_current_domain_get_is_empty(nullptr, nullptr);
tiledb_current_domain_get_type(nullptr, nullptr);
tiledb_current_domain_set_ndrectangle(nullptr, nullptr, nullptr);
tiledb_current_domain_get_ndrectangle(nullptr, nullptr, nullptr);
tiledb_current_domain_get_is_empty(nullptr, nullptr, nullptr);
tiledb_current_domain_get_type(nullptr, nullptr, nullptr);

return 0;
}
46 changes: 32 additions & 14 deletions tiledb/api/c_api/current_domain/test/unit_capi_current_domain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,34 @@ TEST_CASE_METHOD(
crd = nullptr;
CHECK(tiledb_current_domain_create(ctx, &crd) == TILEDB_OK);

CHECK(tiledb_current_domain_set_ndrectangle(nullptr, nullptr) == TILEDB_ERR);
CHECK(tiledb_current_domain_set_ndrectangle(crd, nullptr) == TILEDB_ERR);
CHECK(
tiledb_current_domain_set_ndrectangle(nullptr, nullptr, nullptr) ==
TILEDB_INVALID_CONTEXT);
CHECK(
tiledb_current_domain_set_ndrectangle(ctx, nullptr, nullptr) ==
TILEDB_ERR);
CHECK(tiledb_current_domain_set_ndrectangle(ctx, crd, nullptr) == TILEDB_ERR);

CHECK(tiledb_current_domain_get_ndrectangle(nullptr, nullptr) == TILEDB_ERR);
CHECK(tiledb_current_domain_get_ndrectangle(crd, nullptr) == TILEDB_ERR);
CHECK(
tiledb_current_domain_get_ndrectangle(nullptr, nullptr, nullptr) ==
TILEDB_INVALID_CONTEXT);
CHECK(
tiledb_current_domain_get_ndrectangle(ctx, nullptr, nullptr) ==
TILEDB_ERR);
CHECK(tiledb_current_domain_get_ndrectangle(ctx, crd, nullptr) == TILEDB_ERR);

CHECK(tiledb_current_domain_get_is_empty(nullptr, nullptr) == TILEDB_ERR);
CHECK(tiledb_current_domain_get_is_empty(crd, nullptr) == TILEDB_ERR);
CHECK(
tiledb_current_domain_get_is_empty(nullptr, nullptr, nullptr) ==
TILEDB_INVALID_CONTEXT);
CHECK(
tiledb_current_domain_get_is_empty(ctx, nullptr, nullptr) == TILEDB_ERR);
CHECK(tiledb_current_domain_get_is_empty(ctx, crd, nullptr) == TILEDB_ERR);

CHECK(tiledb_current_domain_get_type(nullptr, nullptr) == TILEDB_ERR);
CHECK(tiledb_current_domain_get_type(crd, nullptr) == TILEDB_ERR);
CHECK(
tiledb_current_domain_get_type(nullptr, nullptr, nullptr) ==
TILEDB_INVALID_CONTEXT);
CHECK(tiledb_current_domain_get_type(ctx, nullptr, nullptr) == TILEDB_ERR);
CHECK(tiledb_current_domain_get_type(ctx, crd, nullptr) == TILEDB_ERR);

tiledb_current_domain_free(&crd);
}
Expand All @@ -126,22 +143,23 @@ TEST_CASE_METHOD(
REQUIRE(tiledb_ndrectangle_alloc(ctx, domain_, &ndr) == TILEDB_OK);

uint32_t is_empty = 0;
REQUIRE(tiledb_current_domain_get_is_empty(crd, &is_empty) == TILEDB_OK);
REQUIRE(tiledb_current_domain_get_is_empty(ctx, crd, &is_empty) == TILEDB_OK);
CHECK(is_empty == 1);

tiledb_current_domain_type_t type;
CHECK(tiledb_current_domain_get_type(crd, &type) == TILEDB_ERR);
CHECK(tiledb_current_domain_get_type(ctx, crd, &type) == TILEDB_ERR);

REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK);
REQUIRE(tiledb_current_domain_set_ndrectangle(ctx, crd, ndr) == TILEDB_OK);

REQUIRE(tiledb_current_domain_get_is_empty(crd, &is_empty) == TILEDB_OK);
REQUIRE(tiledb_current_domain_get_is_empty(ctx, crd, &is_empty) == TILEDB_OK);
CHECK(is_empty == 0);

REQUIRE(tiledb_current_domain_get_type(crd, &type) == TILEDB_OK);
REQUIRE(tiledb_current_domain_get_type(ctx, crd, &type) == TILEDB_OK);
CHECK(type == TILEDB_NDRECTANGLE);

tiledb_ndrectangle_t* out_ndr = nullptr;
REQUIRE(tiledb_current_domain_get_ndrectangle(crd, &out_ndr) == TILEDB_OK);
REQUIRE(
tiledb_current_domain_get_ndrectangle(ctx, crd, &out_ndr) == TILEDB_OK);
CHECK(out_ndr != nullptr);

// Verify that they point to the same tiledb::sm::NDRectangle instance.
Expand Down
Loading

0 comments on commit b8ca549

Please sign in to comment.