Skip to content

Commit

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

[sc-51832]

---
TYPE: C_API
DESC: `ArraySchema` CAPI Handle.

---------

Co-authored-by: KiterLuc <[email protected]>
  • Loading branch information
bekadavis9 and KiterLuc authored Aug 16, 2024
1 parent 5b92634 commit f84be6c
Show file tree
Hide file tree
Showing 40 changed files with 3,466 additions and 1,821 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ endif()

list(APPEND TILEDB_C_API_RELATIVE_HEADERS
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/api_external_common.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/array/array_api_external.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/array_schema/array_schema_api_deprecated.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/array_schema/array_schema_api_experimental.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/array_schema/array_schema_api_external.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/array_schema/array_type_enum.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/array_schema/layout_enum.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/attribute/attribute_api_external.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/attribute/attribute_api_external_experimental.h"
"${CMAKE_SOURCE_DIR}/tiledb/api/c_api/buffer/buffer_api_external.h"
Expand Down Expand Up @@ -521,6 +527,7 @@ if (TILEDB_TESTS)
# C API basics
add_dependencies(tests unit_capi_config unit_capi_context)
add_dependencies(tests unit_capi_array)
add_dependencies(tests unit_capi_array_schema)
add_dependencies(tests unit_capi_buffer)
add_dependencies(tests unit_capi_buffer_list)
add_dependencies(tests unit_capi_data_order)
Expand Down
6 changes: 4 additions & 2 deletions test/src/test-capi-array-write-ordered-attr-fixed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* The MIT License
*
* @copyright Copyright (c) 2022 TileDB Inc.
* @copyright Copyright (c) 2022-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 @@ -37,6 +37,8 @@ using namespace Catch::Matchers;
#include <test/support/src/helpers.h>
#include <test/support/src/vfs_helpers.h>
#include <test/support/tdb_catch.h>
#include "tiledb/api/c_api/array_schema/array_schema_api_internal.h"
#include "tiledb/api/c_api/attribute/attribute_api_internal.h"
#include "tiledb/sm/array_schema/array_schema.h"
#include "tiledb/sm/array_schema/attribute.h"
#include "tiledb/sm/c_api/tiledb.h"
Expand Down Expand Up @@ -74,7 +76,7 @@ struct FixedOrderedAttributeArrayFixture {
// Define the attribute: skip C-API since ordered attributes aren't
// exposed in the C-API yet.
auto attr = make_shared<sm::Attribute>(HERE(), "a", type, 1, order);
auto st = schema->array_schema_->add_attribute(attr);
auto st = schema->add_attribute(attr);
REQUIRE(st.ok());

// Create the array and clean-up.
Expand Down
6 changes: 4 additions & 2 deletions test/src/test-capi-array-write-ordered-attr-var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* The MIT License
*
* @copyright Copyright (c) 2022 TileDB Inc.
* @copyright Copyright (c) 2022-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 @@ -37,6 +37,8 @@ using namespace Catch::Matchers;
#include <test/support/src/helpers.h>
#include <test/support/src/vfs_helpers.h>
#include <test/support/tdb_catch.h>
#include "tiledb/api/c_api/array_schema/array_schema_api_internal.h"
#include "tiledb/api/c_api/attribute/attribute_api_internal.h"
#include "tiledb/sm/array_schema/array_schema.h"
#include "tiledb/sm/array_schema/attribute.h"
#include "tiledb/sm/c_api/tiledb.h"
Expand Down Expand Up @@ -75,7 +77,7 @@ struct VarOrderedAttributeArrayFixture {
// exposed in the C-API yet.
auto attr = make_shared<sm::Attribute>(
HERE(), "a", Datatype::STRING_ASCII, constants::var_num, order);
auto st = schema->array_schema_->add_attribute(attr);
auto st = schema->add_attribute(attr);
REQUIRE(st.ok());

// Create the array and clean-up.
Expand Down
12 changes: 6 additions & 6 deletions test/src/test-capi-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) 2022 TileDB, Inc.
* @copyright Copyright (c) 2022-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 All @@ -32,6 +32,7 @@

#include "test/support/src/helpers.h"
#include "test/support/src/vfs_helpers.h"
#include "tiledb/api/c_api/array_schema/array_schema_api_internal.h"
#include "tiledb/api/c_api/context/context_api_internal.h"
#include "tiledb/sm/c_api/tiledb.h"
#include "tiledb/sm/c_api/tiledb_experimental.h"
Expand Down Expand Up @@ -359,7 +360,7 @@ TEST_CASE_METHOD(

// Check array schema and number of dimension labels.
require_tiledb_ok(tiledb_array_schema_check(ctx, array_schema));
auto dim_label_num = array_schema->array_schema_->dim_label_num();
auto dim_label_num = array_schema->dim_label_num();
REQUIRE(dim_label_num == 1);

// Create array
Expand All @@ -384,10 +385,9 @@ TEST_CASE_METHOD(
tiledb_array_schema_t* loaded_dim_label_array_schema{nullptr};
require_tiledb_ok(tiledb_array_schema_load(
ctx, dim_label_uri, &loaded_dim_label_array_schema));
uint64_t loaded_tile_extent{
loaded_dim_label_array_schema->array_schema_->dimension_ptr(0)
->tile_extent()
.rvalue_as<uint64_t>()};
uint64_t loaded_tile_extent{loaded_dim_label_array_schema->dimension_ptr(0)
->tile_extent()
.rvalue_as<uint64_t>()};
REQUIRE(tile_extent == loaded_tile_extent);
tiledb_array_schema_free(&loaded_dim_label_array_schema);
}
Expand Down
5 changes: 3 additions & 2 deletions test/src/test-capi-subarray-labels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* The MIT License
*
* @copyright Copyright (c) 2022 TileDB, Inc.
* @copyright Copyright (c) 2022-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 All @@ -32,6 +32,7 @@

#include "test/support/src/helpers.h"
#include "test/support/src/vfs_helpers.h"
#include "tiledb/api/c_api/array_schema/array_schema_api_internal.h"
#include "tiledb/api/c_api/context/context_api_internal.h"
#include "tiledb/sm/c_api/tiledb.h"
#include "tiledb/sm/c_api/tiledb_experimental.h"
Expand Down Expand Up @@ -103,7 +104,7 @@ class SampleLabelledArrayTestFixture : public TemporaryDirectoryFixture {

// Check array schema and number of dimension labels.
require_tiledb_ok(tiledb_array_schema_check(ctx, array_schema));
auto dim_label_num = array_schema->array_schema_->dim_label_num();
auto dim_label_num = array_schema->dim_label_num();
REQUIRE(dim_label_num == 2);

// Create array and free array schema.
Expand Down
2 changes: 2 additions & 0 deletions test/src/unit-capi-array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#else
#include "tiledb/sm/filesystem/posix.h"
#endif
#include "tiledb/api/c_api/array_schema/array_schema_api_external.h"
#include "tiledb/api/c_api/array_schema/array_schema_api_internal.h"
#include "tiledb/api/c_api/buffer/buffer_api_internal.h"
#include "tiledb/api/c_api/context/context_api_internal.h"
#include "tiledb/common/stdx_string.h"
Expand Down
3 changes: 2 additions & 1 deletion test/src/unit-capi-enum_values.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* The MIT License
*
* @copyright Copyright (c) 2017-2022 TileDB Inc.
* @copyright Copyright (c) 2017-2024 TileDB Inc.
* @copyright Copyright (c) 2016 MIT and Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -32,6 +32,7 @@
*/

#include <test/support/tdb_catch.h>
#include "tiledb/api/c_api/array_schema/array_schema_api_external.h"
#include "tiledb/sm/c_api/tiledb.h"
#include "tiledb/sm/enums/filter_type.h"

Expand Down
2 changes: 1 addition & 1 deletion test/src/unit-cppapi-schema-evolution.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
5 changes: 3 additions & 2 deletions test/support/src/serialization_wrappers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* The MIT License
*
* @copyright Copyright (c) 2022 TileDB, Inc.
* @copyright Copyright (c) 2022-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 All @@ -32,6 +32,7 @@
*/

#include "test/support/src/helpers.h"
#include "tiledb/api/c_api/array_schema/array_schema_api_internal.h"
#include "tiledb/sm/c_api/tiledb.h"
#include "tiledb/sm/c_api/tiledb_serialization.h"
#include "tiledb/sm/c_api/tiledb_struct_def.h"
Expand Down Expand Up @@ -206,7 +207,7 @@ 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_, &builder)
.ok());
// Deserialize
tiledb_subarray_t* deserialized_subarray;
Expand Down
5 changes: 4 additions & 1 deletion tiledb/api/c_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# The MIT License
#
# Copyright (c) 2022-2023 TileDB, Inc.
# Copyright (c) 2022-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 @@ -52,6 +52,9 @@ target_include_directories(export INTERFACE ${TILEDB_SOURCE_ROOT}/tiledb/sm/c_ap
# `array`: no dependencies
add_subdirectory(array)

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

# `buffer`: no dependencies
add_subdirectory(buffer)

Expand Down
13 changes: 13 additions & 0 deletions tiledb/api/c_api/array/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,18 @@
#

include(common NO_POLICY_SCOPE)
include(object_library)

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

commence(object_library capi_array_stub)
this_target_sources(${SOURCES})
this_target_link_libraries(export)
this_target_object_libraries(array)
this_target_object_libraries(capi_context_stub)
conclude(object_library)

add_test_subdirectory()
107 changes: 107 additions & 0 deletions tiledb/api/c_api/array/array_api.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* @file tiledb/api/c_api/array/array_api.cc
*
* @section LICENSE
*
* The MIT License
*
* @copyright 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.
*
* @section DESCRIPTION
*
* This file defines C API functions for the array section.
*/

#include "array_api_internal.h"
#include "tiledb/sm/c_api/tiledb.h"

#include "tiledb/api/c_api/array_schema/array_schema_api_internal.h"
#include "tiledb/api/c_api/context/context_api_internal.h"
#include "tiledb/api/c_api_support/c_api_support.h"
#include "tiledb/sm/array/array_directory.h"
#include "tiledb/sm/enums/encryption_type.h"
#include "tiledb/sm/rest/rest_client.h"

namespace tiledb::api {

capi_return_t tiledb_array_schema_load(
tiledb_ctx_t* ctx,
const char* array_uri,
tiledb_array_schema_t** array_schema) {
ensure_output_pointer_is_valid(array_schema);

auto uri = tiledb::sm::URI(array_uri);
if (uri.is_invalid()) {
throw CAPIException("Invalid input uri.");
}

if (uri.is_tiledb()) {
auto& rest_client = ctx->context().rest_client();
auto&& [st, array_schema_rest] =
rest_client.get_array_schema_from_rest(uri);
if (!st.ok()) {
throw CAPIException("Failed to load array schema; " + st.message());
}
*array_schema =
tiledb_array_schema_t::make_handle(*(array_schema_rest->get()));
} else {
// Create key
tiledb::sm::EncryptionKey key;
throw_if_not_ok(
key.set_key(tiledb::sm::EncryptionType::NO_ENCRYPTION, nullptr, 0));

// Load URIs from the array directory
optional<tiledb::sm::ArrayDirectory> array_dir;
try {
array_dir.emplace(
ctx->resources(),
uri,
0,
UINT64_MAX,
tiledb::sm::ArrayDirectoryMode::SCHEMA_ONLY);
} catch (const std::logic_error& le) {
throw CAPIException(
"Failed to load array schema; " +
Status_ArrayDirectoryError(le.what()).message());
}

// Load latest array schema
auto tracker = ctx->resources().ephemeral_memory_tracker();
auto&& array_schema_latest =
array_dir->load_array_schema_latest(key, tracker);
*array_schema =
tiledb_array_schema_t::make_handle(*(array_schema_latest.get()));
}
return TILEDB_OK;
}

} // namespace tiledb::api

using tiledb::api::api_entry_with_context;

CAPI_INTERFACE(
array_schema_load,
tiledb_ctx_t* ctx,
const char* array_uri,
tiledb_array_schema_t** array_schema) {
return api_entry_with_context<tiledb::api::tiledb_array_schema_load>(
ctx, array_uri, array_schema);
}
Loading

0 comments on commit f84be6c

Please sign in to comment.