Skip to content

Commit

Permalink
Subarray CAPI Handle. (#5334)
Browse files Browse the repository at this point in the history
`Subarray` CAPI Handle.

[sc-53777]

---
TYPE: NO_HISTORY
DESC: `Subarray` CAPI Handle.
  • Loading branch information
bekadavis9 authored Oct 9, 2024
1 parent cf28026 commit 5bf1baf
Show file tree
Hide file tree
Showing 23 changed files with 2,291 additions and 1,012 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ list(APPEND TILEDB_C_API_RELATIVE_HEADERS
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/query_field/query_field_api_external_experimental.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/query_plan/query_plan_api_external_experimental.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/string/string_api_external.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/subarray/subarray_api_experimental.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/subarray/subarray_api_external.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/vfs/vfs_api_enum.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/vfs/vfs_api_external.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/vfs/vfs_api_experimental.h"
Expand Down
4 changes: 2 additions & 2 deletions test/src/test-cppapi-dense-array-dimension-label.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* The MIT License
*
* @copyright Copyright (c) 2023 TileDB, Inc.
* @copyright Copyright (c) 2023-2024 TileDB, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -592,5 +592,5 @@ TEST_CASE(
CHECK(query.ptr()->query_->subarray()->range_num() == 1);
CHECK(
query.ptr()->query_->subarray()->ranges_for_dim(0) ==
expected_subarray.ptr()->subarray_->ranges_for_dim(0));
expected_subarray.ptr()->ranges_for_dim(0));
}
5 changes: 2 additions & 3 deletions test/src/unit-Subarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "test/support/src/helpers.h"
#include "test/support/src/vfs_helpers.h"
#include "tiledb/api/c_api/array/array_api_internal.h"
#include "tiledb/sm/c_api/tiledb_struct_def.h"
#include "tiledb/sm/subarray/subarray_partitioner.h"

#ifdef _WIN32
Expand Down Expand Up @@ -963,10 +962,10 @@ TEST_CASE_METHOD(
Range(&range_data[0], &range_data[1], sizeof(int64_t)),
Range(&range_data[2], &range_data[3], sizeof(int64_t)),
Range(&range_data[4], &range_data[5], sizeof(int64_t))};
subarray->subarray_->set_attribute_ranges("b", input_ranges);
subarray->set_attribute_ranges("b", input_ranges);

// Get attribute ranges and verify results
const auto& output_ranges = subarray->subarray_->get_attribute_ranges("b");
const auto& output_ranges = subarray->get_attribute_ranges("b");
for (uint32_t ii = 0; ii < 3; ++ii) {
CHECK(input_ranges[ii] == output_ranges[ii]);
}
Expand Down
22 changes: 11 additions & 11 deletions test/src/unit-cppapi-subarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,29 +468,29 @@ TEST_CASE(
SECTION("- Upper bound OOB") {
int range[] = {0, 100};
auto r = Range(&range[0], &range[1], sizeof(int));
CHECK_NOTHROW(subarray.ptr().get()->subarray_->add_range_unsafe(0, r));
CHECK_NOTHROW(subarray.ptr().get()->add_range_unsafe(0, r));
}

SECTION("- Lower bound OOB") {
int range[] = {-1, 2};
auto r = Range(&range[0], &range[1], sizeof(int));
CHECK_NOTHROW(subarray.ptr().get()->subarray_->add_range_unsafe(0, r));
CHECK_NOTHROW(subarray.ptr().get()->add_range_unsafe(0, r));
}

SECTION("- Second range OOB") {
int range[] = {1, 4};
auto r = Range(&range[0], &range[1], sizeof(int));
CHECK_NOTHROW(subarray.ptr().get()->subarray_->add_range_unsafe(0, r));
CHECK_NOTHROW(subarray.ptr().get()->add_range_unsafe(0, r));
int range2[] = {10, 20};
auto r2 = Range(&range2[0], &range2[1], sizeof(int));
CHECK_NOTHROW(subarray.ptr().get()->subarray_->add_range_unsafe(1, r2));
CHECK_NOTHROW(subarray.ptr().get()->add_range_unsafe(1, r2));
}

SECTION("- Valid ranges") {
int range[] = {0, 1};
auto r = Range(&range[0], &range[1], sizeof(int));
CHECK_NOTHROW(subarray.ptr().get()->subarray_->add_range_unsafe(0, r));
CHECK_NOTHROW(subarray.ptr().get()->subarray_->add_range_unsafe(1, r));
CHECK_NOTHROW(subarray.ptr().get()->add_range_unsafe(0, r));
CHECK_NOTHROW(subarray.ptr().get()->add_range_unsafe(1, r));
expected = TILEDB_OK;
}

Expand Down Expand Up @@ -822,14 +822,14 @@ TEST_CASE(
// since the other CHECKS(range_num == 1) succeed whether or not the
//.set_subarray() was done (accidental discovery.)
CHECK(!subarray_equiv<int>(
*default_subarray_from_query.ptr().get()->subarray_,
*subarray.ptr().get()->subarray_));
*default_subarray_from_query.ptr()->subarray().get(),
*subarray.ptr()->subarray().get()));
query.set_subarray(subarray);
tiledb::Subarray retrieved_query_subarray(query.ctx(), query.array());
query.update_subarray_from_query(&retrieved_query_subarray);
CHECK(subarray_equiv<int>(
*retrieved_query_subarray.ptr().get()->subarray_,
*subarray.ptr().get()->subarray_));
*retrieved_query_subarray.ptr()->subarray().get(),
*subarray.ptr()->subarray().get()));
// Test range num
auto range_num = retrieved_query_subarray.range_num(0);
CHECK(range_num == 1);
Expand Down Expand Up @@ -1293,7 +1293,7 @@ TEST_CASE(
tiledb_subarray_serialize(ctx.ptr().get(), array.ptr().get(), &ptr);
subarray.replace_subarray_data(ptr);
}
CHECK(coalesce == subarray.ptr()->subarray_->coalesce_ranges());
CHECK(coalesce == subarray.ptr()->coalesce_ranges());

subarray.add_range(0, 1, 10);
subarray.add_range(0, 11, 20);
Expand Down
20 changes: 10 additions & 10 deletions test/src/unit-ordered-dim-label-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct CPPOrderedDimLabelReaderFixedFx {
}

Subarray subarray(ctx_, array);
subarray.ptr()->subarray_->set_attribute_ranges("labels", input_ranges);
subarray.ptr()->set_attribute_ranges("labels", input_ranges);
if (serialize_) {
auto subarray_ptr = subarray.ptr().get();
tiledb_subarray_serialize(
Expand Down Expand Up @@ -173,7 +173,7 @@ struct CPPOrderedDimLabelReaderFixedFx {
&second_label, &first_label, sizeof(LabelT));

Subarray subarray(ctx_, array);
subarray.ptr()->subarray_->set_attribute_ranges("labels", input_ranges);
subarray.ptr()->set_attribute_ranges("labels", input_ranges);
if (serialize_) {
auto subarray_ptr = subarray.ptr().get();
tiledb_subarray_serialize(
Expand Down Expand Up @@ -256,7 +256,7 @@ TEST_CASE_METHOD(
input_ranges.emplace_back(&val, &val, sizeof(double));

Subarray subarray(ctx_, array);
subarray.ptr()->subarray_->set_attribute_ranges("labels", input_ranges);
subarray.ptr()->set_attribute_ranges("labels", input_ranges);
if (serialize_) {
auto subarray_ptr = subarray.ptr().get();
tiledb_subarray_serialize(
Expand Down Expand Up @@ -295,7 +295,7 @@ TEST_CASE_METHOD(
input_ranges.emplace_back(&val, &val, sizeof(double));

Subarray subarray(ctx_, array);
subarray.ptr()->subarray_->set_attribute_ranges("labels", input_ranges);
subarray.ptr()->set_attribute_ranges("labels", input_ranges);
if (serialize_) {
auto subarray_ptr = subarray.ptr().get();
tiledb_subarray_serialize(
Expand Down Expand Up @@ -335,7 +335,7 @@ TEST_CASE_METHOD(
input_ranges.emplace_back(&val, &val, sizeof(double));

Subarray subarray(ctx_, array);
subarray.ptr()->subarray_->set_attribute_ranges("labels", input_ranges);
subarray.ptr()->set_attribute_ranges("labels", input_ranges);
if (serialize_) {
auto subarray_ptr = subarray.ptr().get();
tiledb_subarray_serialize(
Expand Down Expand Up @@ -376,7 +376,7 @@ TEST_CASE_METHOD(

Subarray subarray(ctx_, array);
subarray.add_range(0, 1, 1);
subarray.ptr()->subarray_->set_attribute_ranges("labels", input_ranges);
subarray.ptr()->set_attribute_ranges("labels", input_ranges);
if (serialize_) {
auto subarray_ptr = subarray.ptr().get();
tiledb_subarray_serialize(
Expand Down Expand Up @@ -412,7 +412,7 @@ TEST_CASE_METHOD(
input_ranges.emplace_back(&ranges[0], &ranges[1], sizeof(double));

Subarray subarray(ctx_, array);
subarray.ptr()->subarray_->set_attribute_ranges("labels", input_ranges);
subarray.ptr()->set_attribute_ranges("labels", input_ranges);
if (serialize_) {
auto subarray_ptr = subarray.ptr().get();
tiledb_subarray_serialize(
Expand Down Expand Up @@ -777,7 +777,7 @@ struct CPPOrderedDimLabelReaderVarFx {
}

Subarray subarray(ctx_, array);
subarray.ptr()->subarray_->set_attribute_ranges("labels", input_ranges);
subarray.ptr()->set_attribute_ranges("labels", input_ranges);
if (serialize_) {
auto subarray_ptr = subarray.ptr().get();
tiledb_subarray_serialize(
Expand Down Expand Up @@ -831,7 +831,7 @@ struct CPPOrderedDimLabelReaderVarFx {
labels_data.data() + 4, 4, labels_data.data(), 4);

Subarray subarray(ctx_, array);
subarray.ptr()->subarray_->set_attribute_ranges("labels", input_ranges);
subarray.ptr()->set_attribute_ranges("labels", input_ranges);
if (serialize_) {
auto subarray_ptr = subarray.ptr().get();
tiledb_subarray_serialize(
Expand Down Expand Up @@ -1057,7 +1057,7 @@ TEST_CASE_METHOD(
}

Subarray subarray(ctx_, array);
subarray.ptr()->subarray_->set_attribute_ranges("labels", input_ranges);
subarray.ptr()->set_attribute_ranges("labels", input_ranges);
if (serialize_) {
auto subarray_ptr = subarray.ptr().get();
tiledb_subarray_serialize(
Expand Down
2 changes: 1 addition & 1 deletion test/support/src/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
#include "test/support/src/coords_workaround.h"
#include "test/support/src/mem_helpers.h"
#include "tiledb.h"
#include "tiledb/api/c_api/subarray/subarray_api_internal.h"
#include "tiledb/common/common.h"
#include "tiledb/common/random/random_label.h"
#include "tiledb/sm/array/array.h"
#include "tiledb/sm/cpp_api/tiledb"
#include "tiledb/sm/enums/layout.h"
#include "tiledb/sm/enums/serialization_type.h"
#include "tiledb/sm/stats/stats.h"
#include "tiledb/sm/subarray/subarray.h"
#include "tiledb_serialization.h"

#include <mutex>
Expand Down
6 changes: 4 additions & 2 deletions test/support/src/serialization_wrappers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,16 @@ void tiledb_subarray_serialize(
tiledb_array_schema_t* array_schema = nullptr;
tiledb_array_get_schema(ctx, array, &array_schema);
REQUIRE(tiledb::sm::serialization::subarray_to_capnp(
*(array_schema->array_schema()), (*subarray)->subarray_, &builder)
*(array_schema->array_schema()),
(*subarray)->subarray().get(),
&builder)
.ok());
// Deserialize
tiledb_subarray_t* deserialized_subarray;
tiledb::test::require_tiledb_ok(
ctx, tiledb_subarray_alloc(ctx, array, &deserialized_subarray));
REQUIRE(tiledb::sm::serialization::subarray_from_capnp(
builder, deserialized_subarray->subarray_)
builder, deserialized_subarray->subarray().get())
.ok());
*subarray = deserialized_subarray;
#endif
Expand Down
3 changes: 3 additions & 0 deletions tiledb/api/c_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ add_subdirectory(object)
# `query`: no dependencies yet but will have some
add_subdirectory(query)

# `subarray`: depends on `context`
add_subdirectory(subarray)

# `string`: no dependencies
add_subdirectory(string)

Expand Down
42 changes: 42 additions & 0 deletions tiledb/api/c_api/subarray/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# tiledb/api/c_api/subarray/CMakeLists.txt
#
# The MIT License
#
# Copyright (c) 2024 TileDB, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

include(common NO_POLICY_SCOPE)
include(object_library)

list(APPEND SOURCES
subarray_api.cc
)
gather_sources(${SOURCES})

commence(object_library capi_subarray_stub)
this_target_sources(${SOURCES})
this_target_link_libraries(export)
this_target_object_libraries(subarray)
this_target_object_libraries(capi_context_stub)
conclude(object_library)

add_test_subdirectory()
Loading

0 comments on commit 5bf1baf

Please sign in to comment.