From f84be6c6da6f417754873638745d9bd7bf153a88 Mon Sep 17 00:00:00 2001 From: Beka Davis <31743465+bekadavis9@users.noreply.github.com> Date: Fri, 16 Aug 2024 04:26:08 -0400 Subject: [PATCH] ArraySchema CAPI Handle. (#5225) `ArraySchema` CAPI Handle. [sc-51832] --- TYPE: C_API DESC: `ArraySchema` CAPI Handle. --------- Co-authored-by: KiterLuc <67824247+KiterLuc@users.noreply.github.com> --- CMakeLists.txt | 7 + ...est-capi-array-write-ordered-attr-fixed.cc | 6 +- .../test-capi-array-write-ordered-attr-var.cc | 6 +- test/src/test-capi-dimension-label.cc | 12 +- test/src/test-capi-subarray-labels.cc | 5 +- test/src/unit-capi-array.cc | 2 + test/src/unit-capi-enum_values.cc | 3 +- test/src/unit-cppapi-schema-evolution.cc | 2 +- test/support/src/serialization_wrappers.cc | 5 +- tiledb/api/c_api/CMakeLists.txt | 5 +- tiledb/api/c_api/array/CMakeLists.txt | 13 + tiledb/api/c_api/array/array_api.cc | 107 ++ tiledb/api/c_api/array/array_api_external.h | 71 ++ tiledb/api/c_api/array/array_api_internal.h | 40 + tiledb/api/c_api/array/test/CMakeLists.txt | 2 +- .../test/compile_capi_array_stub_main.cc | 35 + .../api/c_api/array/test/unit_capi_array.cc | 29 +- tiledb/api/c_api/array_schema/CMakeLists.txt | 42 + .../c_api/array_schema/array_schema_api.cc | 740 ++++++++++++++ .../array_schema_api_deprecated.h | 68 ++ .../array_schema_api_experimental.h | 156 +++ .../array_schema/array_schema_api_external.h | 684 +++++++++++++ .../array_schema/array_schema_api_internal.h | 259 +++++ .../api/c_api/array_schema/array_type_enum.h | 41 + tiledb/api/c_api/array_schema/layout_enum.h | 47 + .../c_api/array_schema/test/CMakeLists.txt | 37 + .../compile_capi_array_schema_stub_main.cc | 35 + .../test/unit_capi_array_schema.cc | 855 ++++++++++++++++ .../testsupport_capi_array_schema.h | 93 ++ tiledb/sm/c_api/api_argument_validator.h | 13 +- tiledb/sm/c_api/tiledb.cc | 949 +----------------- tiledb/sm/c_api/tiledb.h | 660 +----------- tiledb/sm/c_api/tiledb_deprecated.h | 23 +- tiledb/sm/c_api/tiledb_dimension_label.cc | 57 +- tiledb/sm/c_api/tiledb_enum.h | 24 +- tiledb/sm/c_api/tiledb_experimental.h | 108 +- tiledb/sm/c_api/tiledb_filestore.cc | 20 +- tiledb/sm/c_api/tiledb_struct_def.h | 6 +- tiledb/sm/enums/array_type.h | 10 +- tiledb/sm/enums/layout.h | 10 +- 40 files changed, 3466 insertions(+), 1821 deletions(-) create mode 100644 tiledb/api/c_api/array/array_api.cc create mode 100644 tiledb/api/c_api/array/array_api_external.h create mode 100644 tiledb/api/c_api/array/array_api_internal.h create mode 100644 tiledb/api/c_api/array/test/compile_capi_array_stub_main.cc create mode 100644 tiledb/api/c_api/array_schema/CMakeLists.txt create mode 100644 tiledb/api/c_api/array_schema/array_schema_api.cc create mode 100644 tiledb/api/c_api/array_schema/array_schema_api_deprecated.h create mode 100644 tiledb/api/c_api/array_schema/array_schema_api_experimental.h create mode 100644 tiledb/api/c_api/array_schema/array_schema_api_external.h create mode 100644 tiledb/api/c_api/array_schema/array_schema_api_internal.h create mode 100644 tiledb/api/c_api/array_schema/array_type_enum.h create mode 100644 tiledb/api/c_api/array_schema/layout_enum.h create mode 100644 tiledb/api/c_api/array_schema/test/CMakeLists.txt create mode 100644 tiledb/api/c_api/array_schema/test/compile_capi_array_schema_stub_main.cc create mode 100644 tiledb/api/c_api/array_schema/test/unit_capi_array_schema.cc create mode 100644 tiledb/api/c_api_test_support/testsupport_capi_array_schema.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d3fec8f854c..c3905e54193 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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" @@ -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) diff --git a/test/src/test-capi-array-write-ordered-attr-fixed.cc b/test/src/test-capi-array-write-ordered-attr-fixed.cc index 264046bcac6..57b9e1b8ea1 100644 --- a/test/src/test-capi-array-write-ordered-attr-fixed.cc +++ b/test/src/test-capi-array-write-ordered-attr-fixed.cc @@ -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 @@ -37,6 +37,8 @@ using namespace Catch::Matchers; #include #include #include +#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" @@ -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(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. diff --git a/test/src/test-capi-array-write-ordered-attr-var.cc b/test/src/test-capi-array-write-ordered-attr-var.cc index 12aa7554c31..c608c699c90 100644 --- a/test/src/test-capi-array-write-ordered-attr-var.cc +++ b/test/src/test-capi-array-write-ordered-attr-var.cc @@ -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 @@ -37,6 +37,8 @@ using namespace Catch::Matchers; #include #include #include +#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" @@ -75,7 +77,7 @@ struct VarOrderedAttributeArrayFixture { // exposed in the C-API yet. auto attr = make_shared( 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. diff --git a/test/src/test-capi-dimension-label.cc b/test/src/test-capi-dimension-label.cc index 08e933a5d03..dd94fc9878b 100644 --- a/test/src/test-capi-dimension-label.cc +++ b/test/src/test-capi-dimension-label.cc @@ -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 @@ -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" @@ -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 @@ -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 loaded_tile_extent{loaded_dim_label_array_schema->dimension_ptr(0) + ->tile_extent() + .rvalue_as()}; REQUIRE(tile_extent == loaded_tile_extent); tiledb_array_schema_free(&loaded_dim_label_array_schema); } diff --git a/test/src/test-capi-subarray-labels.cc b/test/src/test-capi-subarray-labels.cc index 6c135930127..0594f0bdb59 100644 --- a/test/src/test-capi-subarray-labels.cc +++ b/test/src/test-capi-subarray-labels.cc @@ -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 @@ -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" @@ -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. diff --git a/test/src/unit-capi-array.cc b/test/src/unit-capi-array.cc index fc643e84bc2..a2888cfe580 100644 --- a/test/src/unit-capi-array.cc +++ b/test/src/unit-capi-array.cc @@ -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" diff --git a/test/src/unit-capi-enum_values.cc b/test/src/unit-capi-enum_values.cc index 24968c7e340..5579c63ba4c 100644 --- a/test/src/unit-capi-enum_values.cc +++ b/test/src/unit-capi-enum_values.cc @@ -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 @@ -32,6 +32,7 @@ */ #include +#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" diff --git a/test/src/unit-cppapi-schema-evolution.cc b/test/src/unit-cppapi-schema-evolution.cc index 44403af0725..5a15fdc8d38 100644 --- a/test/src/unit-cppapi-schema-evolution.cc +++ b/test/src/unit-cppapi-schema-evolution.cc @@ -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 diff --git a/test/support/src/serialization_wrappers.cc b/test/support/src/serialization_wrappers.cc index 1ae4d58ea95..6590523138c 100644 --- a/test/support/src/serialization_wrappers.cc +++ b/test/support/src/serialization_wrappers.cc @@ -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 @@ -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" @@ -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; diff --git a/tiledb/api/c_api/CMakeLists.txt b/tiledb/api/c_api/CMakeLists.txt index e511ee25a45..a5943f9a5d8 100644 --- a/tiledb/api/c_api/CMakeLists.txt +++ b/tiledb/api/c_api/CMakeLists.txt @@ -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 @@ -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) diff --git a/tiledb/api/c_api/array/CMakeLists.txt b/tiledb/api/c_api/array/CMakeLists.txt index 01b40189feb..042a1fdd821 100644 --- a/tiledb/api/c_api/array/CMakeLists.txt +++ b/tiledb/api/c_api/array/CMakeLists.txt @@ -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() diff --git a/tiledb/api/c_api/array/array_api.cc b/tiledb/api/c_api/array/array_api.cc new file mode 100644 index 00000000000..64604685c02 --- /dev/null +++ b/tiledb/api/c_api/array/array_api.cc @@ -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 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( + ctx, array_uri, array_schema); +} diff --git a/tiledb/api/c_api/array/array_api_external.h b/tiledb/api/c_api/array/array_api_external.h new file mode 100644 index 00000000000..5b7b0d70b9a --- /dev/null +++ b/tiledb/api/c_api/array/array_api_external.h @@ -0,0 +1,71 @@ +/** + * @file tiledb/api/c_api/array/array_api_external.h + * + * @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 declares the Array C API for TileDB. + */ + +#ifndef TILEDB_CAPI_ARRAY_EXTERNAL_H +#define TILEDB_CAPI_ARRAY_EXTERNAL_H + +#include "../api_external_common.h" +#include "../array_schema/array_schema_api_external.h" +#include "../context/context_api_external.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Retrieves the schema of an array from the disk, creating an array schema + * struct. + * + * **Example:** + * + * @code{.c} + * tiledb_array_schema_t* array_schema; + * tiledb_array_schema_load(ctx, "s3://tiledb_bucket/my_array", &array_schema); + * // Make sure to free the array schema in the end + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_uri The array whose schema will be retrieved. + * @param[out] array_schema The array schema to be retrieved, or `NULL` upon + * error. + * @return `TILEDB_OK` for success and `TILEDB_OOM` or `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_load( + tiledb_ctx_t* ctx, + const char* array_uri, + tiledb_array_schema_t** array_schema) TILEDB_NOEXCEPT; + +#ifdef __cplusplus +} +#endif + +#endif // TILEDB_CAPI_ARRAY_EXTERNAL_H diff --git a/tiledb/api/c_api/array/array_api_internal.h b/tiledb/api/c_api/array/array_api_internal.h new file mode 100644 index 00000000000..e6b6e03935f --- /dev/null +++ b/tiledb/api/c_api/array/array_api_internal.h @@ -0,0 +1,40 @@ +/** + * @file tiledb/api/c_api/array/array_api_internal.h + * + * @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 declares the internals of the array section of the C API. + */ + +#ifndef TILEDB_CAPI_ARRAY_INTERNAL_H +#define TILEDB_CAPI_ARRAY_INTERNAL_H + +#include "array_api_external.h" + +#include "tiledb/common/common.h" + +#endif // TILEDB_CAPI_ARRAY_INTERNAL_H diff --git a/tiledb/api/c_api/array/test/CMakeLists.txt b/tiledb/api/c_api/array/test/CMakeLists.txt index 95d84a29b2b..afa865016d9 100644 --- a/tiledb/api/c_api/array/test/CMakeLists.txt +++ b/tiledb/api/c_api/array/test/CMakeLists.txt @@ -32,7 +32,7 @@ find_package(Catch2 REQUIRED) # Maturity # # This unit links against the whole library out of necessity. There's not -# yet an `array` object library, much less a C API handle one. +# yet a _complete_ `array` C API handle object library. # commence(unit_test capi_array) this_target_sources(unit_capi_array.cc) diff --git a/tiledb/api/c_api/array/test/compile_capi_array_stub_main.cc b/tiledb/api/c_api/array/test/compile_capi_array_stub_main.cc new file mode 100644 index 00000000000..8907a6f43e3 --- /dev/null +++ b/tiledb/api/c_api/array/test/compile_capi_array_stub_main.cc @@ -0,0 +1,35 @@ +/** + * @file + * tiledb/api/c_api/array/test/compile_capi_array_stub_main.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. + */ + +#include "../array_api_external.h" + +int main() { + tiledb_array_schema_load(nullptr, nullptr, nullptr); + return 0; +} diff --git a/tiledb/api/c_api/array/test/unit_capi_array.cc b/tiledb/api/c_api/array/test/unit_capi_array.cc index b521aacb4c6..29406b84901 100644 --- a/tiledb/api/c_api/array/test/unit_capi_array.cc +++ b/tiledb/api/c_api/array/test/unit_capi_array.cc @@ -33,7 +33,11 @@ #include "tiledb/api/c_api_test_support/testsupport_capi_context.h" #include "tiledb/sm/c_api/tiledb.h" -using tiledb::api::test_support::ordinary_context; +#include "../array_api_external.h" +#include "../array_api_internal.h" + +using namespace tiledb::api::test_support; + const char* TEST_URI = "unit_capi_array"; TEST_CASE( @@ -78,3 +82,26 @@ TEST_CASE( CHECK(tiledb_status(rc) == TILEDB_ERR); } } + +TEST_CASE( + "C API: tiledb_array_schema_load argument validation", "[capi][array]") { + capi_return_t rc; + ordinary_context ctx{}; + const char* array_uri = "array_uri"; + tiledb_array_schema_handle_t* schema{}; + /* + * No "success" section here; too much overhead to set up. + */ + SECTION("null context") { + rc = tiledb_array_schema_load(nullptr, array_uri, &schema); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null array_uri") { + rc = tiledb_array_schema_load(ctx.context, nullptr, &schema); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null schema") { + rc = tiledb_array_schema_load(ctx.context, array_uri, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} diff --git a/tiledb/api/c_api/array_schema/CMakeLists.txt b/tiledb/api/c_api/array_schema/CMakeLists.txt new file mode 100644 index 00000000000..4beb4b49d9f --- /dev/null +++ b/tiledb/api/c_api/array_schema/CMakeLists.txt @@ -0,0 +1,42 @@ +# +# tiledb/api/c_api/array_schema/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 + array_schema_api.cc +) +gather_sources(${SOURCES}) + +commence(object_library capi_array_schema_stub) + this_target_sources(${SOURCES}) + this_target_link_libraries(export) + this_target_object_libraries(array_schema) + this_target_object_libraries(capi_context_stub) +conclude(object_library) + +add_test_subdirectory() diff --git a/tiledb/api/c_api/array_schema/array_schema_api.cc b/tiledb/api/c_api/array_schema/array_schema_api.cc new file mode 100644 index 00000000000..3191dc75c12 --- /dev/null +++ b/tiledb/api/c_api/array_schema/array_schema_api.cc @@ -0,0 +1,740 @@ +/** + * @file tiledb/api/c_api/array_schema/array_schema_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 schema section. + */ + +#include "array_schema_api_deprecated.h" +#include "array_schema_api_experimental.h" +#include "array_schema_api_internal.h" + +#include "tiledb/api/c_api/attribute/attribute_api_internal.h" +#include "tiledb/api/c_api/context/context_api_internal.h" +#include "tiledb/api/c_api/current_domain/current_domain_api_external_experimental.h" +#include "tiledb/api/c_api/current_domain/current_domain_api_internal.h" +#include "tiledb/api/c_api/domain/domain_api_internal.h" +#include "tiledb/api/c_api/enumeration/enumeration_api_internal.h" +#include "tiledb/api/c_api/filter_list/filter_list_api_internal.h" +#include "tiledb/api/c_api/string/string_api_internal.h" +#include "tiledb/api/c_api_support/c_api_support.h" +#include "tiledb/common/memory_tracker.h" + +namespace tiledb::api { + +capi_return_t tiledb_array_type_to_str( + tiledb_array_type_t array_type, const char** str) { + const auto& strval = + tiledb::sm::array_type_str((tiledb::sm::ArrayType)array_type); + *str = strval.c_str(); + return strval.empty() ? TILEDB_ERR : TILEDB_OK; +} + +capi_return_t tiledb_array_type_from_str( + const char* str, tiledb_array_type_t* array_type) { + tiledb::sm::ArrayType val = tiledb::sm::ArrayType::DENSE; + if (!tiledb::sm::array_type_enum(str, &val).ok()) { + return TILEDB_ERR; + } + *array_type = (tiledb_array_type_t)val; + return TILEDB_OK; +} + +capi_return_t tiledb_layout_to_str(tiledb_layout_t layout, const char** str) { + const auto& strval = tiledb::sm::layout_str((tiledb::sm::Layout)layout); + *str = strval.c_str(); + return strval.empty() ? TILEDB_ERR : TILEDB_OK; +} + +capi_return_t tiledb_layout_from_str(const char* str, tiledb_layout_t* layout) { + tiledb::sm::Layout val = tiledb::sm::Layout::ROW_MAJOR; + if (!tiledb::sm::layout_enum(str, &val).ok()) { + return TILEDB_ERR; + } + *layout = (tiledb_layout_t)val; + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_alloc( + tiledb_ctx_t* ctx, + tiledb_array_type_t array_type, + tiledb_array_schema_t** array_schema) { + ensure_output_pointer_is_valid(array_schema); + + // Create ArraySchema object + auto memory_tracker = ctx->resources().create_memory_tracker(); + memory_tracker->set_type(MemoryTrackerType::ARRAY_CREATE); + *array_schema = tiledb_array_schema_t::make_handle( + static_cast(array_type), memory_tracker); + + return TILEDB_OK; +} + +void tiledb_array_schema_free(tiledb_array_schema_t** array_schema) { + ensure_output_pointer_is_valid(array_schema); + ensure_array_schema_is_valid(*array_schema); + tiledb_array_schema_t::break_handle(*array_schema); +} + +capi_return_t tiledb_array_schema_add_attribute( + tiledb_array_schema_t* array_schema, tiledb_attribute_t* attr) { + ensure_array_schema_is_valid(array_schema); + ensure_attribute_is_valid(attr); + + /** Note: The call to make_shared creates a copy of the attribute and + * the user-visible handle to the attr no longer refers to the same object + * that's in the array_schema. + **/ + throw_if_not_ok(array_schema->add_attribute(attr->copy_attribute())); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_set_allows_dups( + tiledb_array_schema_t* array_schema, int allows_dups) { + ensure_array_schema_is_valid(array_schema); + throw_if_not_ok(array_schema->set_allows_dups(allows_dups)); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_allows_dups( + tiledb_array_schema_t* array_schema, int* allows_dups) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(allows_dups); + *allows_dups = (int)array_schema->allows_dups(); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_version( + tiledb_array_schema_t* array_schema, uint32_t* version) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(version); + *version = (uint32_t)array_schema->version(); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_set_domain( + tiledb_array_schema_t* array_schema, tiledb_domain_t* domain) { + ensure_array_schema_is_valid(array_schema); + ensure_domain_is_valid(domain); + throw_if_not_ok(array_schema->set_domain(domain->copy_domain())); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_set_capacity( + tiledb_array_schema_t* array_schema, uint64_t capacity) { + ensure_array_schema_is_valid(array_schema); + array_schema->set_capacity(capacity); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_set_cell_order( + tiledb_array_schema_t* array_schema, tiledb_layout_t cell_order) { + ensure_array_schema_is_valid(array_schema); + throw_if_not_ok(array_schema->set_cell_order( + static_cast(cell_order))); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_set_tile_order( + tiledb_array_schema_t* array_schema, tiledb_layout_t tile_order) { + ensure_array_schema_is_valid(array_schema); + throw_if_not_ok(array_schema->set_tile_order( + static_cast(tile_order))); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_timestamp_range( + tiledb_array_schema_t* array_schema, uint64_t* lo, uint64_t* hi) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(lo); + ensure_output_pointer_is_valid(hi); + + auto timestamp_range = array_schema->timestamp_range(); + *lo = std::get<0>(timestamp_range); + *hi = std::get<1>(timestamp_range); + + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_add_enumeration( + tiledb_array_schema_t* array_schema, tiledb_enumeration_t* enumeration) { + ensure_array_schema_is_valid(array_schema); + ensure_enumeration_is_valid(enumeration); + array_schema->add_enumeration(enumeration->copy()); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_set_coords_filter_list( + tiledb_array_schema_t* array_schema, tiledb_filter_list_t* filter_list) { + ensure_array_schema_is_valid(array_schema); + ensure_filter_list_is_valid(filter_list); + throw_if_not_ok( + array_schema->set_coords_filter_pipeline(filter_list->pipeline())); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_set_offsets_filter_list( + tiledb_array_schema_t* array_schema, tiledb_filter_list_t* filter_list) { + ensure_array_schema_is_valid(array_schema); + ensure_filter_list_is_valid(filter_list); + throw_if_not_ok(array_schema->set_cell_var_offsets_filter_pipeline( + filter_list->pipeline())); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_set_validity_filter_list( + tiledb_array_schema_t* array_schema, tiledb_filter_list_t* filter_list) { + ensure_array_schema_is_valid(array_schema); + ensure_filter_list_is_valid(filter_list); + throw_if_not_ok( + array_schema->set_cell_validity_filter_pipeline(filter_list->pipeline())); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_check( + tiledb_ctx_t* ctx, tiledb_array_schema_t* array_schema) { + ensure_array_schema_is_valid(array_schema); + array_schema->check(ctx->resources().config()); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_array_type( + const tiledb_array_schema_t* array_schema, + tiledb_array_type_t* array_type) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(array_type); + *array_type = static_cast(array_schema->array_type()); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_capacity( + const tiledb_array_schema_t* array_schema, uint64_t* capacity) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(capacity); + *capacity = array_schema->capacity(); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_cell_order( + const tiledb_array_schema_t* array_schema, tiledb_layout_t* cell_order) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(cell_order); + *cell_order = static_cast(array_schema->cell_order()); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_coords_filter_list( + tiledb_array_schema_t* array_schema, tiledb_filter_list_t** filter_list) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(filter_list); + // Copy-construct a separate FilterPipeline object + *filter_list = tiledb_filter_list_t::make_handle( + sm::FilterPipeline{array_schema->coords_filters()}); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_offsets_filter_list( + tiledb_array_schema_t* array_schema, tiledb_filter_list_t** filter_list) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(filter_list); + // Copy-construct a separate FilterPipeline object + *filter_list = tiledb_filter_list_t::make_handle( + sm::FilterPipeline{array_schema->cell_var_offsets_filters()}); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_validity_filter_list( + tiledb_array_schema_t* array_schema, tiledb_filter_list_t** filter_list) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(filter_list); + // Copy-construct a separate FilterPipeline object + *filter_list = tiledb_filter_list_t::make_handle( + sm::FilterPipeline{array_schema->cell_validity_filters()}); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_domain( + const tiledb_array_schema_t* array_schema, tiledb_domain_t** domain) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(domain); + *domain = tiledb_domain_handle_t::make_handle(array_schema->shared_domain()); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_tile_order( + const tiledb_array_schema_t* array_schema, tiledb_layout_t* tile_order) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(tile_order); + *tile_order = static_cast(array_schema->tile_order()); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_attribute_num( + const tiledb_array_schema_t* array_schema, uint32_t* attribute_num) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(attribute_num); + *attribute_num = array_schema->attribute_num(); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_dump( + const tiledb_array_schema_t* array_schema, FILE* out) { + // Note: this API is deprecated. + ensure_array_schema_is_valid(array_schema); + ensure_cstream_handle_is_valid(out); + + std::stringstream ss; + ss << *array_schema->array_schema(); + size_t r = fwrite(ss.str().c_str(), sizeof(char), ss.str().size(), out); + if (r != ss.str().size()) { + throw CAPIException( + "Error writing array schema " + array_schema->array_uri().to_string() + + " to file"); + } + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_dump_str( + const tiledb_array_schema_t* array_schema, tiledb_string_t** out) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(out); + + std::stringstream ss; + ss << *array_schema->array_schema(); + *out = tiledb_string_handle_t::make_handle(ss.str()); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_attribute_from_index( + const tiledb_array_schema_t* array_schema, + uint32_t index, + tiledb_attribute_t** attr) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(attr); + + uint32_t attribute_num = array_schema->attribute_num(); + if (attribute_num == 0) { + *attr = nullptr; + return TILEDB_OK; + } + if (index >= attribute_num) { + std::ostringstream errmsg; + errmsg << "Attribute index: " << index << " out of bounds given " + << attribute_num << " attributes in array " + << array_schema->array_uri().to_string(); + throw CAPIException(errmsg.str()); + } + + auto found_attr = array_schema->shared_attribute(index); + if (!found_attr) { + throw CAPIException("Attribute not found, but index is valid!"); + } + *attr = tiledb_attribute_handle_t::make_handle(found_attr); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_attribute_from_name( + const tiledb_array_schema_t* array_schema, + const char* name, + tiledb_attribute_t** attr) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(attr); + + uint32_t attribute_num = array_schema->attribute_num(); + if (attribute_num == 0) { + *attr = nullptr; + return TILEDB_OK; + } + std::string name_string(name); + auto found_attr = array_schema->shared_attribute(name_string); + if (!found_attr) { + throw CAPIException( + std::string("Attribute name: ") + + (name_string.empty() ? "" : name) + + " does not exist for array " + array_schema->array_uri().to_string()); + } + *attr = tiledb_attribute_handle_t::make_handle(found_attr); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_has_attribute( + const tiledb_array_schema_t* array_schema, + const char* name, + int32_t* has_attr) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(has_attr); + + bool b; + throw_if_not_ok(array_schema->has_attribute(name, &b)); + *has_attr = b ? 1 : 0; + + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_set_current_domain( + tiledb_array_schema_t* array_schema, + tiledb_current_domain_t* current_domain) { + ensure_array_schema_is_valid(array_schema); + ensure_handle_is_valid(current_domain); + array_schema->set_current_domain(current_domain->current_domain()); + return TILEDB_OK; +} + +capi_return_t tiledb_array_schema_get_current_domain( + tiledb_array_schema_t* array_schema, + tiledb_current_domain_t** current_domain) { + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(current_domain); + + // There is always a current domain on an ArraySchema instance, + // when none was set explicitly, there is an empty current domain. + *current_domain = tiledb_current_domain_handle_t::make_handle( + array_schema->get_current_domain()); + return TILEDB_OK; +} + +} // namespace tiledb::api + +using tiledb::api::api_entry_context; +using tiledb::api::api_entry_plain; +using tiledb::api::api_entry_void; +using tiledb::api::api_entry_with_context; + +CAPI_INTERFACE( + array_type_to_str, tiledb_array_type_t array_type, const char** str) { + return api_entry_plain( + array_type, str); +} + +CAPI_INTERFACE( + array_type_from_str, const char* str, tiledb_array_type_t* array_type) { + return api_entry_plain( + str, array_type); +} + +CAPI_INTERFACE(layout_to_str, tiledb_layout_t layout, const char** str) { + return api_entry_plain(layout, str); +} + +CAPI_INTERFACE(layout_from_str, const char* str, tiledb_layout_t* layout) { + return api_entry_plain(str, layout); +} + +CAPI_INTERFACE( + array_schema_alloc, + tiledb_ctx_t* ctx, + tiledb_array_type_t array_type, + tiledb_array_schema_t** array_schema) { + return api_entry_with_context( + ctx, array_type, array_schema); +} + +CAPI_INTERFACE_VOID(array_schema_free, tiledb_array_schema_t** array_schema) { + return api_entry_void(array_schema); +} + +CAPI_INTERFACE( + array_schema_add_attribute, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_attribute_t* attr) { + return api_entry_context( + ctx, array_schema, attr); +} + +CAPI_INTERFACE( + array_schema_set_allows_dups, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + int allows_dups) { + return api_entry_context( + ctx, array_schema, allows_dups); +} + +CAPI_INTERFACE( + array_schema_get_allows_dups, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + int* allows_dups) { + return api_entry_context( + ctx, array_schema, allows_dups); +} + +CAPI_INTERFACE( + array_schema_get_version, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + uint32_t* version) { + return api_entry_context( + ctx, array_schema, version); +} + +CAPI_INTERFACE( + array_schema_set_domain, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_domain_t* domain) { + return api_entry_context( + ctx, array_schema, domain); +} + +CAPI_INTERFACE( + array_schema_set_capacity, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + uint64_t capacity) { + return api_entry_context( + ctx, array_schema, capacity); +} + +CAPI_INTERFACE( + array_schema_set_cell_order, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_layout_t cell_order) { + return api_entry_context( + ctx, array_schema, cell_order); +} + +CAPI_INTERFACE( + array_schema_set_tile_order, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_layout_t tile_order) { + return api_entry_context( + ctx, array_schema, tile_order); +} + +CAPI_INTERFACE( + array_schema_timestamp_range, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + uint64_t* lo, + uint64_t* hi) { + return api_entry_context( + ctx, array_schema, lo, hi); +} + +CAPI_INTERFACE( + array_schema_add_enumeration, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_enumeration_t* enumeration) { + return api_entry_context( + ctx, array_schema, enumeration); +} + +CAPI_INTERFACE( + array_schema_set_coords_filter_list, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_filter_list_t* filter_list) { + return api_entry_context< + tiledb::api::tiledb_array_schema_set_coords_filter_list>( + ctx, array_schema, filter_list); +} + +CAPI_INTERFACE( + array_schema_set_offsets_filter_list, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_filter_list_t* filter_list) { + return api_entry_context< + tiledb::api::tiledb_array_schema_set_offsets_filter_list>( + ctx, array_schema, filter_list); +} + +CAPI_INTERFACE( + array_schema_set_validity_filter_list, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_filter_list_t* filter_list) { + return api_entry_context< + tiledb::api::tiledb_array_schema_set_validity_filter_list>( + ctx, array_schema, filter_list); +} + +CAPI_INTERFACE( + array_schema_check, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema) { + return api_entry_with_context( + ctx, array_schema); +} + +CAPI_INTERFACE( + array_schema_get_array_type, + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + tiledb_array_type_t* array_type) { + return api_entry_context( + ctx, array_schema, array_type); +} + +CAPI_INTERFACE( + array_schema_get_capacity, + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + uint64_t* capacity) { + return api_entry_context( + ctx, array_schema, capacity); +} + +CAPI_INTERFACE( + array_schema_get_cell_order, + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + tiledb_layout_t* cell_order) { + return api_entry_context( + ctx, array_schema, cell_order); +} + +CAPI_INTERFACE( + array_schema_get_coords_filter_list, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_filter_list_t** filter_list) { + return api_entry_context< + tiledb::api::tiledb_array_schema_get_coords_filter_list>( + ctx, array_schema, filter_list); +} + +CAPI_INTERFACE( + array_schema_get_offsets_filter_list, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_filter_list_t** filter_list) { + return api_entry_context< + tiledb::api::tiledb_array_schema_get_offsets_filter_list>( + ctx, array_schema, filter_list); +} + +CAPI_INTERFACE( + array_schema_get_validity_filter_list, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_filter_list_t** filter_list) { + return api_entry_context< + tiledb::api::tiledb_array_schema_get_validity_filter_list>( + ctx, array_schema, filter_list); +} + +CAPI_INTERFACE( + array_schema_get_domain, + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + tiledb_domain_t** domain) { + return api_entry_context( + ctx, array_schema, domain); +} + +CAPI_INTERFACE( + array_schema_get_tile_order, + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + tiledb_layout_t* tile_order) { + return api_entry_context( + ctx, array_schema, tile_order); +} + +CAPI_INTERFACE( + array_schema_get_attribute_num, + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + uint32_t* attribute_num) { + return api_entry_context( + ctx, array_schema, attribute_num); +} + +CAPI_INTERFACE( + array_schema_dump, + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + FILE* out) { + return api_entry_context( + ctx, array_schema, out); +} + +CAPI_INTERFACE( + array_schema_dump_str, + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + tiledb_string_t** out) { + return api_entry_context( + ctx, array_schema, out); +} + +CAPI_INTERFACE( + array_schema_get_attribute_from_index, + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + uint32_t index, + tiledb_attribute_t** attr) { + return api_entry_context< + tiledb::api::tiledb_array_schema_get_attribute_from_index>( + ctx, array_schema, index, attr); +} + +CAPI_INTERFACE( + array_schema_get_attribute_from_name, + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + const char* name, + tiledb_attribute_t** attr) { + return api_entry_context< + tiledb::api::tiledb_array_schema_get_attribute_from_name>( + ctx, array_schema, name, attr); +} + +CAPI_INTERFACE( + array_schema_has_attribute, + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + const char* name, + int32_t* has_attr) { + return api_entry_context( + ctx, array_schema, name, has_attr); +} + +CAPI_INTERFACE( + array_schema_set_current_domain, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_current_domain_t* current_domain) { + return api_entry_context( + ctx, array_schema, current_domain); +} + +CAPI_INTERFACE( + array_schema_get_current_domain, + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_current_domain_t** current_domain) { + return api_entry_context( + ctx, array_schema, current_domain); +} diff --git a/tiledb/api/c_api/array_schema/array_schema_api_deprecated.h b/tiledb/api/c_api/array_schema/array_schema_api_deprecated.h new file mode 100644 index 00000000000..7821b06f331 --- /dev/null +++ b/tiledb/api/c_api/array_schema/array_schema_api_deprecated.h @@ -0,0 +1,68 @@ +/** + * @file tiledb/api/c_api/array_schema/array_schema_api_deprecated.h + * + * @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 declares the deprecated array schema section of the TileDB C API. + */ + +#ifndef TILEDB_CAPI_ARRAY_SCHEMA_DEPRECATED_H +#define TILEDB_CAPI_ARRAY_SCHEMA_DEPRECATED_H + +#include "../api_external_common.h" +#include "array_schema_api_external.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Dumps the array schema in ASCII format in the selected file output. + * + * **Example:** + * + * The following prints the array schema dump in standard output. + * + * @code{.c} + * tiledb_array_schema_dump(ctx, array_schema, stdout); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] out The output handle. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_DEPRECATED_EXPORT capi_return_t tiledb_array_schema_dump( + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + FILE* out) TILEDB_NOEXCEPT; + +#ifdef __cplusplus +} +#endif + +#endif // TILEDB_CAPI_ARRAY_SCHEMA_DEPRECATED_H 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 new file mode 100644 index 00000000000..d0ca102c865 --- /dev/null +++ b/tiledb/api/c_api/array_schema/array_schema_api_experimental.h @@ -0,0 +1,156 @@ +/** + * @file tiledb/api/c_api/array_schema/array_schema_api_experimental.h + * + * @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 declares the array schema section of the experimental TileDB C API. + */ + +#ifndef TILEDB_CAPI_ARRAY_SCHEMA_EXPERIMENTAL_H +#define TILEDB_CAPI_ARRAY_SCHEMA_EXPERIMENTAL_H + +#include "../api_external_common.h" +#include "array_schema_api_external.h" + +#include "tiledb/api/c_api/current_domain/current_domain_api_external_experimental.h" +#include "tiledb/api/c_api/enumeration/enumeration_api_experimental.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Gets timestamp range in an array schema + * + * **Example:** + * + * @code{.c} + * uint64_t timestamp_lo = 0; + * uint64_t timestamp_hi = 0; + * tiledb_array_schema_timestamp_range( + * ctx, array_schema, ×tamp_lo, ×tamp_hi); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema object. + * @param[out] lo The lower bound of timestamp range. + * @param[out] hi The upper bound of timestamp range. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_timestamp_range( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + uint64_t* lo, + uint64_t* hi) TILEDB_NOEXCEPT; + +/** + * Adds an enumeration to an array schema. + * + * **Example:** + * + * @code{.c} + * tiledb_enumeration_t* enumeration; + * tiledb_enumeration_alloc( + * ctx, + * "enumeration_name", + * TILEDB_INT64, + * 1, + * FALSE, + * data, + * data_size, + * nullptr, + * 0, + * &enumeration); + * tiledb_array_schema_add_enumeration(ctx, array_schema, enumeration); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] enumeration The enumeration to add with the attribute + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_add_enumeration( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_enumeration_t* enumeration) TILEDB_NOEXCEPT; + +/** + * Sets the current domain on the array schema. + * + * @pre The schema is sparse. current_domain is not yet supported on dense + * arrays. + * + * **Example:** + * + * @code{.c} + * tiledb_current_domain_t *current_domain; + * tiledb_current_domain_create(ctx, ¤t_domain); + * tiledb_array_schema_set_current_domain(ctx, array_schema, current_domain); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] current_domain The current domain to set on the schema + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_set_current_domain( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_current_domain_t* current_domain) TILEDB_NOEXCEPT; + +/** + * Gets the current domain set on the array schema or + * creates an empty current domain if none was set. + * It is the responsability of the caller to free the resources associated + * with the current domain when the handle isn't needed anymore. + * + * @pre The schema is sparse. current_domain is not yet supported on dense + * arrays. + * + * **Example:** + * + * @code{.c} + * tiledb_current_domain_t *current_domain; + * tiledb_array_schema_get_current_domain(ctx, array_schema, ¤t_domain); + * tiledb_current_domain_free(¤t_domain); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] current_domain The current domain set on the schema + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_current_domain( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_current_domain_t** current_domain) TILEDB_NOEXCEPT; + +#ifdef __cplusplus +} +#endif + +#endif // TILEDB_CAPI_ARRAY_SCHEMA_EXPERIMENTAL_H diff --git a/tiledb/api/c_api/array_schema/array_schema_api_external.h b/tiledb/api/c_api/array_schema/array_schema_api_external.h new file mode 100644 index 00000000000..703c25a772f --- /dev/null +++ b/tiledb/api/c_api/array_schema/array_schema_api_external.h @@ -0,0 +1,684 @@ +/** + * @file tiledb/api/c_api/array_schema/array_schema_api_external.h + * + * @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 declares the ArraySchema C API for TileDB. + */ + +#ifndef TILEDB_CAPI_ARRAY_SCHEMA_EXTERNAL_H +#define TILEDB_CAPI_ARRAY_SCHEMA_EXTERNAL_H + +#include "../api_external_common.h" +#include "../attribute/attribute_api_external.h" +#include "../context/context_api_external.h" +#include "../domain/domain_api_external.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** C API carrier for a TileDB array schema */ +typedef struct tiledb_array_schema_handle_t tiledb_array_schema_t; + +/** Array type. */ +typedef enum { +/** Helper macro for defining array type enums. */ +#define TILEDB_ARRAY_TYPE_ENUM(id) TILEDB_##id +#include "tiledb/api/c_api/array_schema/array_type_enum.h" +#undef TILEDB_ARRAY_TYPE_ENUM +} tiledb_array_type_t; + +/** Tile or cell layout. */ +typedef enum { +/** Helper macro for defining layout type enums. */ +#define TILEDB_LAYOUT_ENUM(id) TILEDB_##id +#include "tiledb/api/c_api/array_schema/layout_enum.h" +#undef TILEDB_LAYOUT_ENUM +} tiledb_layout_t; + +/** + * Returns a string representation of the given array type. + * + * @param[in] array_type Array type + * @param[out] str A constant string representation of the array type + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_type_to_str( + tiledb_array_type_t array_type, const char** str) TILEDB_NOEXCEPT; + +/** + * Parses an array type from the given string. + * + * @param[in] str String representation to parse + * @param[out] array_type The parsed array type + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_type_from_str( + const char* str, tiledb_array_type_t* array_type) TILEDB_NOEXCEPT; + +/** + * Returns a string representation of the given layout. + * + * @param[in] layout Layout + * @param[out] str A constant string representation of the layout + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t +tiledb_layout_to_str(tiledb_layout_t layout, const char** str) TILEDB_NOEXCEPT; + +/** + * Parses a layout from the given string. + * + * @param[in] str String representation to parse + * @param[out] layout The parsed layout + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_layout_from_str( + const char* str, tiledb_layout_t* layout) TILEDB_NOEXCEPT; + +/** + * Creates a TileDB array schema object. + * + * **Example:** + * + * @code{.c} + * tiledb_array_schema_t* array_schema; + * tiledb_array_schema_alloc(ctx, TILEDB_DENSE, &array_schema); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_type The array type. + * @param[out] array_schema The TileDB array schema to be created. + * @return `TILEDB_OK` for success and `TILEDB_OOM` or `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_alloc( + tiledb_ctx_t* ctx, + tiledb_array_type_t array_type, + tiledb_array_schema_t** array_schema) TILEDB_NOEXCEPT; + +/** + * Destroys an array schema, freeing associated memory. + * + * **Example:** + * + * @code{.c} + * tiledb_array_schema_free(&array_schema); + * @endcode + * + * @param[in] array_schema The array schema to be destroyed. + */ +TILEDB_EXPORT void tiledb_array_schema_free( + tiledb_array_schema_t** array_schema) TILEDB_NOEXCEPT; + +/** + * Adds an attribute to an array schema. + * + * **Example:** + * + * @code{.c} + * tiledb_attribute_t* attr; + * tiledb_attribute_alloc(ctx, "my_attr", TILEDB_INT32, &attr); + * tiledb_array_schema_add_attribute(ctx, array_schema, attr); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] attr The attribute to be added. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_add_attribute( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_attribute_t* attr) TILEDB_NOEXCEPT; + +/** + * Sets whether the array can allow coordinate duplicates or not. + * Applicable only to sparse arrays (it errors out if set to `1` for dense + * arrays). + * + * **Example:** + * + * @code{.c} + * int allows_dups = 1; + * tiledb_array_schema_set_allows_dups(ctx, array_schema, allows_dups); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] allows_dups Whether or not the array allows coordinate duplicates. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_set_allows_dups( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + int allows_dups) TILEDB_NOEXCEPT; + +/** + * Gets whether the array can allow coordinate duplicates or not. + * It should always be `0` for dense arrays. + * + * **Example:** + * + * @code{.c} + * int allows_dups; + * tiledb_array_schema_get_allows_dups(ctx, array_schema, &allows_dups); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] allows_dups Whether or not the array allows coordinate + * duplicates. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_allows_dups( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + int* allows_dups) TILEDB_NOEXCEPT; + +/** + * Returns the array schema version. + * + * **Example:** + * + * @code{.c} + * uint32_t version; + * tiledb_array_schema_get_version(ctx, array_schema, &version); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] version The version. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_version( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + uint32_t* version) TILEDB_NOEXCEPT; + +/** + * Sets a domain for the array schema. + * + * @pre The domain has at least one dimension set. + * + * **Example:** + * + * @code{.c} + * tiledb_domain_t* domain; + * tiledb_domain_alloc(ctx, &domain); + * // -- Add dimensions to the domain here -- // + * tiledb_array_schema_set_domain(ctx, array_schema, domain); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] domain The domain to be set. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_set_domain( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_domain_t* domain) TILEDB_NOEXCEPT; + +/** + * Sets the tile capacity. Applies to sparse arrays only. + * + * **Example:** + * + * @code{.c} + * tiledb_array_schema_set_capacity(ctx, array_schema, 10000); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] capacity The capacity of a sparse data tile. Note that + * sparse data tiles exist in sparse fragments, which can be created + * in sparse arrays only. For more details, + * see [tutorials/tiling-sparse.html](tutorials/tiling-sparse.html). + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_set_capacity( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + uint64_t capacity) TILEDB_NOEXCEPT; + +/** + * Sets the cell order. + * + * **Example:** + * + * @code{.c} + * tiledb_array_schema_set_cell_order(ctx, array_schema, TILEDB_ROW_MAJOR); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] cell_order The cell order to be set. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_set_cell_order( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_layout_t cell_order) TILEDB_NOEXCEPT; + +/** + * Sets the tile order. + * + * **Example:** + * + * @code{.c} + * tiledb_array_schema_set_tile_order(ctx, array_schema, TILEDB_COL_MAJOR); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] tile_order The tile order to be set. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_set_tile_order( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_layout_t tile_order) TILEDB_NOEXCEPT; + +/** + * Sets the filter list to use for the coordinates. + * + * **Example:** + * + * @code{.c} + * tiledb_filter_list_t* filter_list; + * tiledb_filter_list_alloc(ctx, &filter_list); + * tiledb_filter_list_add_filter(ctx, filter_list, filter); + * tiledb_array_schema_set_coords_filter_list(ctx, array_schema, filter_list); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] filter_list The filter list to be set. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_set_coords_filter_list( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_filter_list_t* filter_list) TILEDB_NOEXCEPT; + +/** + * Sets the filter list to use for the offsets of variable-sized attribute + * values. + * + * **Example:** + * + * @code{.c} + * tiledb_filter_list_t* filter_list; + * tiledb_filter_list_alloc(ctx, &filter_list); + * tiledb_filter_list_add_filter(ctx, filter_list, filter); + * tiledb_array_schema_set_offsets_filter_list(ctx, array_schema, filter_list); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] filter_list The filter list to be set. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_set_offsets_filter_list( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_filter_list_t* filter_list) TILEDB_NOEXCEPT; + +/** + * Sets the filter list to use for the validity array of nullable attribute + * values. + * + * **Example:** + * + * @code{.c} + * tiledb_filter_list_t* filter_list; + * tiledb_filter_list_alloc(ctx, &filter_list); + * tiledb_filter_list_add_filter(ctx, filter_list, filter); + * tiledb_array_schema_set_validity_filter_list(ctx, array_schema, filter_list); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] filter_list The filter list to be set. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_set_validity_filter_list( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_filter_list_t* filter_list) TILEDB_NOEXCEPT; + +/** + * Checks the correctness of the array schema. + * + * **Example:** + * + * @code{.c} + * tiledb_array_schema_check(ctx, array_schema); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @return `TILEDB_OK` if the array schema is correct and `TILEDB_ERR` upon any + * error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_check( + tiledb_ctx_t* ctx, tiledb_array_schema_t* array_schema) TILEDB_NOEXCEPT; + +/** + * Retrieves the array type. + * + * **Example:** + * + * @code{.c} + * tiledb_array_schema_t* array_schema; + * tiledb_array_schema_load(ctx, "s3://tiledb_bucket/my_array", array_schema); + * tiledb_array_type_t* array_type; + * tiledb_array_schema_get_array_type(ctx, array_schema, &array_type); + * // Make sure to free the array schema in the end + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] array_type The array type to be retrieved. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_array_type( + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + tiledb_array_type_t* array_type) TILEDB_NOEXCEPT; + +/** + * Retrieves the capacity. + * + * **Example:** + * + * @code{.c} + * uint64_t capacity; + * tiledb_array_schema_get_capacity(ctx, array_schema, &capacity); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] capacity The capacity to be retrieved. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_capacity( + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + uint64_t* capacity) TILEDB_NOEXCEPT; + +/** + * Retrieves the cell order. + * + * **Example:** + * + * @code{.c} + * tiledb_layout_t cell_order; + * tiledb_array_schema_get_cell_order(ctx, array_schema, &cell_order); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] cell_order The cell order to be retrieved. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_cell_order( + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + tiledb_layout_t* cell_order) TILEDB_NOEXCEPT; + +/** + * Retrieves the filter list used for the coordinates. + * + * **Example:** + * + * @code{.c} + * tiledb_filter_list_t* filter_list; + * tiledb_array_schema_get_coords_filter_list(ctx, array_schema, &filter_list); + * tiledb_filter_list_free(ctx, &filter_list); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] filter_list The filter list to be retrieved. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_coords_filter_list( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_filter_list_t** filter_list) TILEDB_NOEXCEPT; + +/** + * Retrieves the filter list used for the offsets. + * + * **Example:** + * + * @code{.c} + * tiledb_filter_list_t* filter_list; + * tiledb_array_schema_get_offsets_filter_list(ctx, array_schema, &filter_list); + * tiledb_filter_list_free(ctx, &filter_list); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] filter_list The filter list to be retrieved. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_offsets_filter_list( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_filter_list_t** filter_list) TILEDB_NOEXCEPT; + +/** + * Retrieves the filter list used for validity maps. + * + * **Example:** + * + * @code{.c} + * tiledb_filter_list_t* filter_list; + * tiledb_array_schema_get_validity_filter_list( + * ctx, array_schema, &filter_list); + * tiledb_filter_list_free(ctx, &filter_list); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] filter_list The filter list to be retrieved. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_validity_filter_list( + tiledb_ctx_t* ctx, + tiledb_array_schema_t* array_schema, + tiledb_filter_list_t** filter_list) TILEDB_NOEXCEPT; + +/** + * Retrieves the array domain. + * + * **Example:** + * + * @code{.c} + * tiledb_domain_t* domain; + * tiledb_array_schema_get_domain(ctx, array_schema, &domain); + * tiledb_domain_free(&domain); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] domain The array domain to be retrieved. + * @return `TILEDB_OK` for success and `TILEDB_OOM` or `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_domain( + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + tiledb_domain_t** domain) TILEDB_NOEXCEPT; + +/** + * Retrieves the tile order. + * + * **Example:** + * + * @code{.c} + * tiledb_layout_t tile_order; + * tiledb_array_schema_get_tile_order(ctx, array_schema, &tile_order); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] tile_order The tile order to be retrieved. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_tile_order( + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + tiledb_layout_t* tile_order) TILEDB_NOEXCEPT; + +/** + * Retrieves the number of array attributes. + * + * **Example:** + * + * @code{.c} + * uint32_t attr_num; + * tiledb_array_schema_get_attribute_num(ctx, array_schema, &attr_num); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] attribute_num The number of attributes to be retrieved. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_attribute_num( + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + uint32_t* attribute_num) TILEDB_NOEXCEPT; + +/** + * Retrieves an attribute given its index. + * + * Attributes are ordered the same way they were defined + * when constructing the array schema. + * + * **Example:** + * + * The following retrieves the first attribute in the schema. + * + * @code{.c} + * tiledb_attribute_t* attr; + * tiledb_array_schema_get_attribute_from_index(ctx, array_schema, 0, &attr); + * tiledb_attribute_free(&attr); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] index The index of the attribute to retrieve. + * @param[out] attr The attribute object to retrieve. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_attribute_from_index( + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + uint32_t index, + tiledb_attribute_t** attr) TILEDB_NOEXCEPT; + +/** + * Retrieves an attribute given its name (key). + * + * **Example:** + * + * The following retrieves the attribute named "a" in the schema. + * + * @code{.c} + * tiledb_attribute_t* attr; + * tiledb_array_schema_get_attribute_from_name(ctx, array_schema, "a", &attr); + * tiledb_attribute_free(&attr); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] name The name (key) of the attribute to retrieve. + * @param[out] attr The attribute object to retrieve. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_get_attribute_from_name( + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + const char* name, + tiledb_attribute_t** attr) TILEDB_NOEXCEPT; + +/** + * Checks whether the array schema has an attribute of the given name. + * + * **Example:** + * + * @code{.c} + * int32_t has_attr; + * tiledb_array_schema_has_attribute(ctx, array_schema, "attr_0", &has_attr); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[in] name The name of the attribute to check for. + * @param[out] has_attr Set to `1` if the array schema has an attribute of the + * given name, else `0`. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_has_attribute( + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + const char* name, + int32_t* has_attr) TILEDB_NOEXCEPT; + +/** + * Dumps the array schema in ASCII format in the selected string output. + * + * The output string handle must be freed by the user after use. + * + * **Example:** + * + * @code{.c} + * tiledb_string_t* tdb_string; + * tiledb_array_schema_dump_str(ctx, array_schema, &tdb_string); + * // Use the string + * tiledb_string_free(&tdb_string); + * @endcode + * + * @param[in] ctx The TileDB context. + * @param[in] array_schema The array schema. + * @param[out] out The output string. + * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. + */ +TILEDB_EXPORT capi_return_t tiledb_array_schema_dump_str( + tiledb_ctx_t* ctx, + const tiledb_array_schema_t* array_schema, + tiledb_string_t** out) TILEDB_NOEXCEPT; + +#ifdef __cplusplus +} +#endif + +#endif // TILEDB_CAPI_ARRAY_SCHEMA_EXTERNAL_H diff --git a/tiledb/api/c_api/array_schema/array_schema_api_internal.h b/tiledb/api/c_api/array_schema/array_schema_api_internal.h new file mode 100644 index 00000000000..89ad84399d8 --- /dev/null +++ b/tiledb/api/c_api/array_schema/array_schema_api_internal.h @@ -0,0 +1,259 @@ +/** + * @file tiledb/api/c_api/array_schema/array_schema_api_internal.h + * + * @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 declares the internals of the array_schema section of the C API. + */ + +#ifndef TILEDB_CAPI_ARRAY_SCHEMA_INTERNAL_H +#define TILEDB_CAPI_ARRAY_SCHEMA_INTERNAL_H + +#include "array_schema_api_external.h" + +#include "tiledb/api/c_api_support/handle/handle.h" +#include "tiledb/common/common.h" +#include "tiledb/sm/array_schema/array_schema.h" +#include "tiledb/sm/enums/array_type.h" +#include "tiledb/sm/enums/layout.h" + +using namespace tiledb::sm; + +/** Handle `struct` for API ArraySchema objects. */ +struct tiledb_array_schema_handle_t + : public tiledb::api::CAPIHandle { + /** Type name */ + static constexpr std::string_view object_type_name{"array_schema"}; + + private: + using array_schema_type = shared_ptr; + array_schema_type array_schema_; + + public: + template + explicit tiledb_array_schema_handle_t(Args... args) + : array_schema_{ + make_shared(HERE(), std::forward(args)...)} { + } + + explicit tiledb_array_schema_handle_t(const ArraySchema& array_schema) + : array_schema_{make_shared(HERE(), array_schema)} { + } + + /** + * Constructor from `shared_ptr` copies the shared pointer. + */ + explicit tiledb_array_schema_handle_t(const array_schema_type& x) + : array_schema_(x) { + } + + array_schema_type array_schema() const { + return array_schema_; + } + + Status add_attribute( + shared_ptr attr, bool check_special = true) { + return array_schema_->add_attribute(attr, check_special); + } + + void add_dimension_label( + ArraySchema::dimension_size_type dim_id, + const std::string& name, + DataOrder label_order, + Datatype label_type, + bool check_name = true) { + array_schema_->add_dimension_label( + dim_id, name, label_order, label_type, check_name); + } + + void add_enumeration(shared_ptr enmr) { + return array_schema_->add_enumeration(enmr); + } + + bool allows_dups() const { + return array_schema_->allows_dups(); + } + + ArrayType array_type() const { + return array_schema_->array_type(); + } + + const URI& array_uri() const { + return array_schema_->array_uri(); + } + + ArraySchema::attribute_size_type attribute_num() const { + return array_schema_->attribute_num(); + } + + uint64_t capacity() const { + return array_schema_->capacity(); + } + + Layout cell_order() const { + return array_schema_->cell_order(); + } + + const FilterPipeline& cell_validity_filters() const { + return array_schema_->cell_validity_filters(); + } + + const FilterPipeline& cell_var_offsets_filters() const { + return array_schema_->cell_var_offsets_filters(); + } + + void check(const Config& cfg) const { + array_schema_->check(cfg); + } + + const FilterPipeline& coords_filters() const { + return array_schema_->coords_filters(); + } + + const DimensionLabel& dimension_label( + ArraySchema::dimension_label_size_type i) const { + return array_schema_->dimension_label(i); + } + + const DimensionLabel& dimension_label(const std::string& name) const { + return array_schema_->dimension_label(name); + } + + const Dimension* dimension_ptr(ArraySchema::dimension_size_type i) const { + return array_schema_->dimension_ptr(i); + } + + const Dimension* dimension_ptr(const std::string& name) const { + return array_schema_->dimension_ptr(name); + } + + ArraySchema::dimension_label_size_type dim_label_num() const { + return array_schema_->dim_label_num(); + } + + shared_ptr get_current_domain() const { + return array_schema_->get_current_domain(); + } + + Status has_attribute(const std::string& name, bool* has_attr) const { + return array_schema_->has_attribute(name, has_attr); + } + + bool is_dim_label(const std::string& name) const { + return array_schema_->is_dim_label(name); + } + + Status set_allows_dups(bool allows_dups) { + return array_schema_->set_allows_dups(allows_dups); + } + + void set_capacity(uint64_t capacity) { + array_schema_->set_capacity(capacity); + } + + void set_current_domain(shared_ptr current_domain) { + array_schema_->set_current_domain(current_domain); + } + + void set_dimension_label_filter_pipeline( + const std::string& label_name, const FilterPipeline& pipeline) { + array_schema_->set_dimension_label_filter_pipeline(label_name, pipeline); + } + + void set_dimension_label_tile_extent( + const std::string& label_name, + const Datatype type, + const void* tile_extent) { + array_schema_->set_dimension_label_tile_extent( + label_name, type, tile_extent); + } + + Status set_domain(shared_ptr domain) { + return array_schema_->set_domain(domain); + } + + Status set_cell_order(Layout cell_order) { + return array_schema_->set_cell_order(cell_order); + } + + Status set_cell_validity_filter_pipeline(const FilterPipeline& pipeline) { + return array_schema_->set_cell_validity_filter_pipeline(pipeline); + } + + Status set_cell_var_offsets_filter_pipeline(const FilterPipeline& pipeline) { + return array_schema_->set_cell_var_offsets_filter_pipeline(pipeline); + } + + Status set_coords_filter_pipeline(const FilterPipeline& pipeline) { + return array_schema_->set_coords_filter_pipeline(pipeline); + } + + Status set_tile_order(Layout tile_order) { + return array_schema_->set_tile_order(tile_order); + } + + shared_ptr shared_attribute( + ArraySchema::attribute_size_type id) const { + return array_schema_->shared_attribute(id); + } + + shared_ptr shared_attribute(const std::string& name) const { + return array_schema_->shared_attribute(name); + } + + shared_ptr shared_domain() const { + return array_schema_->shared_domain(); + } + + Layout tile_order() const { + return array_schema_->tile_order(); + } + + std::pair timestamp_range() const { + return array_schema_->timestamp_range(); + } + + format_version_t version() const { + return array_schema_->version(); + } +}; + +namespace tiledb::api { + +/** + * Returns after successfully validating an array schema. + * + * @param array_schema Possibly-valid pointer to an array schema + */ +inline void ensure_array_schema_is_valid( + const tiledb_array_schema_t* array_schema) { + ensure_handle_is_valid(array_schema); +} + +} // namespace tiledb::api + +#endif // TILEDB_CAPI_ARRAY_SCHEMA_INTERNAL_H diff --git a/tiledb/api/c_api/array_schema/array_type_enum.h b/tiledb/api/c_api/array_schema/array_type_enum.h new file mode 100644 index 00000000000..0a53167517c --- /dev/null +++ b/tiledb/api/c_api/array_schema/array_type_enum.h @@ -0,0 +1,41 @@ +/* + * 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. + */ + +/** + * NOTE: The values of these enums are serialized to the array schema and/or + * fragment metadata. Therefore, the values below should never change, + * otherwise backwards compatibility breaks. + */ + +// clang-format is disabled on the first enum so that we can manually indent it +// properly. + +// clang-format off +#ifdef TILEDB_ARRAY_TYPE_ENUM + /** Dense array */ + TILEDB_ARRAY_TYPE_ENUM(DENSE) = 0, + /** Sparse array */ + TILEDB_ARRAY_TYPE_ENUM(SPARSE) = 1, +#endif + // clang-format on diff --git a/tiledb/api/c_api/array_schema/layout_enum.h b/tiledb/api/c_api/array_schema/layout_enum.h new file mode 100644 index 00000000000..c2b24a8c44a --- /dev/null +++ b/tiledb/api/c_api/array_schema/layout_enum.h @@ -0,0 +1,47 @@ +/* + * 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. + */ + +/** + * NOTE: The values of these enums are serialized to the array schema and/or + * fragment metadata. Therefore, the values below should never change, + * otherwise backwards compatibility breaks. + */ + +// clang-format is disabled on the first enum so that we can manually indent it +// properly. + +// clang-format off +#ifdef TILEDB_LAYOUT_ENUM + /** Row-major layout */ + TILEDB_LAYOUT_ENUM(ROW_MAJOR) = 0, + /** Column-major layout */ + TILEDB_LAYOUT_ENUM(COL_MAJOR) = 1, + /** Global-order layout */ + TILEDB_LAYOUT_ENUM(GLOBAL_ORDER) = 2, + /** Unordered layout */ + TILEDB_LAYOUT_ENUM(UNORDERED) = 3, + /** Hilbert layout */ + TILEDB_LAYOUT_ENUM(HILBERT) = 4, +#endif + // clang-format on diff --git a/tiledb/api/c_api/array_schema/test/CMakeLists.txt b/tiledb/api/c_api/array_schema/test/CMakeLists.txt new file mode 100644 index 00000000000..a61b624205b --- /dev/null +++ b/tiledb/api/c_api/array_schema/test/CMakeLists.txt @@ -0,0 +1,37 @@ +# +# tiledb/api/c_api/array_schema/test/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(unit_test) + +commence(unit_test capi_array_schema) + this_target_sources(unit_capi_array_schema.cc) + this_target_object_libraries( + capi_array_schema_stub + capi_attribute_stub + capi_current_domain + capi_domain_stub + ) +conclude(unit_test) diff --git a/tiledb/api/c_api/array_schema/test/compile_capi_array_schema_stub_main.cc b/tiledb/api/c_api/array_schema/test/compile_capi_array_schema_stub_main.cc new file mode 100644 index 00000000000..588594caa46 --- /dev/null +++ b/tiledb/api/c_api/array_schema/test/compile_capi_array_schema_stub_main.cc @@ -0,0 +1,35 @@ +/** + * @file + * tiledb/api/c_api/array_schema/test/compile_capi_array_schema_stub_main.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. + */ + +#include "../array_schema_api_external.h" + +int main() { + tiledb_array_schema_add_attribute(nullptr, nullptr, nullptr); + return 0; +} diff --git a/tiledb/api/c_api/array_schema/test/unit_capi_array_schema.cc b/tiledb/api/c_api/array_schema/test/unit_capi_array_schema.cc new file mode 100644 index 00000000000..8e86cc4c5e6 --- /dev/null +++ b/tiledb/api/c_api/array_schema/test/unit_capi_array_schema.cc @@ -0,0 +1,855 @@ +/** + * @file tiledb/api/c_api/array_schema/test/unit_capi_array_schema.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. + * + * Validates the arguments for the ArraySchema C API. + */ + +#define CATCH_CONFIG_MAIN +#include +#include "../../../c_api_test_support/testsupport_capi_array_schema.h" +#include "../../../c_api_test_support/testsupport_capi_context.h" +#include "../array_schema_api_experimental.h" +#include "../array_schema_api_external.h" +#include "../array_schema_api_internal.h" + +using namespace tiledb::api::test_support; + +TEST_CASE( + "C API: tiledb_array_schema_alloc argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_context ctx{}; + tiledb_array_schema_handle_t* schema{}; + SECTION("success") { + rc = tiledb_array_schema_alloc(ctx.context, TILEDB_DENSE, &schema); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + tiledb_array_schema_free(&schema); + } + SECTION("null context") { + rc = tiledb_array_schema_alloc(nullptr, TILEDB_DENSE, &schema); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + /* + * SECTION("invalid array_type"): All values of `array_type` may be valid + * in certain circumstances. Not checked in the API code and not tested here. + */ + SECTION("null schema") { + rc = tiledb_array_schema_alloc(ctx.context, TILEDB_DENSE, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_free argument validation", + "[capi][array_schema]") { + ordinary_context ctx{}; + tiledb_array_schema_handle_t* schema{}; + auto rc = tiledb_array_schema_alloc(ctx.context, TILEDB_DENSE, &schema); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + SECTION("success") { + REQUIRE_NOTHROW(tiledb_array_schema_free(&schema)); + CHECK(schema == nullptr); + } + SECTION("null schema") { + /* + * `tiledb_array_schema_free` is a void function, otherwise we would check + * for an error. + */ + REQUIRE_NOTHROW(tiledb_array_schema_free(nullptr)); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_add_attribute argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_attribute_t* attr{}; + rc = tiledb_attribute_alloc(x.ctx(), "a", TILEDB_INT32, &attr); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + SECTION("success") { + rc = tiledb_array_schema_add_attribute(x.ctx(), x.schema, attr); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_add_attribute(nullptr, x.schema, attr); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_add_attribute(x.ctx(), nullptr, attr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null attribute") { + rc = tiledb_array_schema_add_attribute(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + REQUIRE_NOTHROW(tiledb_attribute_free(&attr)); + CHECK(attr == nullptr); +} + +TEST_CASE( + "C API: tiledb_array_schema_set_allows_dups argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{TILEDB_DENSE}; + SECTION("success") { + rc = tiledb_array_schema_set_allows_dups(x.ctx(), x.schema, 0); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_set_allows_dups(nullptr, x.schema, 0); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_set_allows_dups(x.ctx(), nullptr, 0); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("invalid allows_dups") { + /* + * This API is applicable _only_ to sparse arrays. + * As such, any non-zero value set on a dense array is considered invalid. + */ + rc = tiledb_array_schema_set_allows_dups(x.ctx(), x.schema, 1); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_get_allows_dups argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + int allows_dups; + SECTION("success") { + rc = tiledb_array_schema_get_allows_dups(x.ctx(), x.schema, &allows_dups); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_allows_dups(nullptr, x.schema, &allows_dups); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_allows_dups(x.ctx(), nullptr, &allows_dups); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null allows_dups") { + rc = tiledb_array_schema_get_allows_dups(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_get_version argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + uint32_t version; + SECTION("success") { + rc = tiledb_array_schema_get_version(x.ctx(), x.schema, &version); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_version(nullptr, x.schema, &version); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_version(x.ctx(), nullptr, &version); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null version") { + rc = tiledb_array_schema_get_version(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_set_domain argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_domain_t* domain{}; + rc = tiledb_domain_alloc(x.ctx(), &domain); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + ordinary_dimension_d1 dim; + rc = tiledb_domain_add_dimension(x.ctx(), domain, dim.dimension); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + SECTION("success") { + rc = tiledb_array_schema_set_domain(x.ctx(), x.schema, domain); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_set_domain(nullptr, x.schema, domain); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_set_domain(x.ctx(), nullptr, domain); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null domain") { + rc = tiledb_array_schema_set_domain(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + REQUIRE_NOTHROW(tiledb_domain_free(&domain)); + CHECK(domain == nullptr); +} + +TEST_CASE( + "C API: tiledb_array_schema_set_capacity argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + SECTION("success") { + rc = tiledb_array_schema_set_capacity(x.ctx(), x.schema, 1); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_set_capacity(nullptr, x.schema, 1); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_set_capacity(x.ctx(), nullptr, 1); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("invalid capacity") { + /* The capacity may not be zero. */ + rc = tiledb_array_schema_set_capacity(x.ctx(), x.schema, 0); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_set_cell_order argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_layout_t layout = TILEDB_ROW_MAJOR; + SECTION("success") { + rc = tiledb_array_schema_set_cell_order(x.ctx(), x.schema, layout); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_set_cell_order(nullptr, x.schema, layout); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_set_cell_order(x.ctx(), nullptr, layout); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("invalid layout") { + /* A cell order of TILEDB_UNORDERED is not yet supported. */ + rc = + tiledb_array_schema_set_cell_order(x.ctx(), x.schema, TILEDB_UNORDERED); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_set_tile_order argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{TILEDB_DENSE}; + tiledb_layout_t layout = TILEDB_ROW_MAJOR; + SECTION("success") { + rc = tiledb_array_schema_set_tile_order(x.ctx(), x.schema, layout); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_set_tile_order(nullptr, x.schema, layout); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_set_tile_order(x.ctx(), nullptr, layout); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("invalid layout") { + /* ordinary_array_schema is dense, which disallows unordered layouts. */ + rc = + tiledb_array_schema_set_tile_order(x.ctx(), x.schema, TILEDB_UNORDERED); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_timestamp_range argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + uint64_t lo; + uint64_t hi; + SECTION("success") { + rc = tiledb_array_schema_timestamp_range(x.ctx(), x.schema, &lo, &hi); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_timestamp_range(nullptr, x.schema, &lo, &hi); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_timestamp_range(x.ctx(), nullptr, &lo, &hi); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null lo") { + rc = tiledb_array_schema_timestamp_range(x.ctx(), x.schema, nullptr, &hi); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null hi") { + rc = tiledb_array_schema_timestamp_range(x.ctx(), x.schema, &lo, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_add_enumeration argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_enumeration_t* enumeration; + int32_t values[5] = {1, 2, 3, 4, 5}; + rc = tiledb_enumeration_alloc( + x.ctx(), + "enumeration", + TILEDB_UINT32, + 1, + 0, + values, + sizeof(uint32_t) * 5, + nullptr, + 0, + &enumeration); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + SECTION("success") { + rc = tiledb_array_schema_add_enumeration(x.ctx(), x.schema, enumeration); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_add_enumeration(nullptr, x.schema, enumeration); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_add_enumeration(x.ctx(), nullptr, enumeration); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null enumeration") { + rc = tiledb_array_schema_add_enumeration(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + REQUIRE_NOTHROW(tiledb_enumeration_free(&enumeration)); + CHECK(enumeration == nullptr); +} + +TEST_CASE( + "C API: tiledb_array_schema_set_coords_filter_list argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_filter_list_t* fl; + rc = tiledb_filter_list_alloc(x.ctx(), &fl); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + SECTION("success") { + rc = tiledb_array_schema_set_coords_filter_list(x.ctx(), x.schema, fl); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_set_coords_filter_list(nullptr, x.schema, fl); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_set_coords_filter_list(x.ctx(), nullptr, fl); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null filter_list") { + rc = tiledb_array_schema_set_coords_filter_list(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + REQUIRE_NOTHROW(tiledb_filter_list_free(&fl)); + CHECK(fl == nullptr); +} + +TEST_CASE( + "C API: tiledb_array_schema_set_offsets_filter_list argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_filter_list_t* fl; + rc = tiledb_filter_list_alloc(x.ctx(), &fl); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + SECTION("success") { + rc = tiledb_array_schema_set_offsets_filter_list(x.ctx(), x.schema, fl); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_set_offsets_filter_list(nullptr, x.schema, fl); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_set_offsets_filter_list(x.ctx(), nullptr, fl); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null filter_list") { + rc = + tiledb_array_schema_set_offsets_filter_list(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + REQUIRE_NOTHROW(tiledb_filter_list_free(&fl)); + CHECK(fl == nullptr); +} + +TEST_CASE( + "C API: tiledb_array_schema_set_validity_filter_list argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_filter_list_t* fl; + rc = tiledb_filter_list_alloc(x.ctx(), &fl); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + SECTION("success") { + rc = tiledb_array_schema_set_validity_filter_list(x.ctx(), x.schema, fl); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_set_validity_filter_list(nullptr, x.schema, fl); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_set_validity_filter_list(x.ctx(), nullptr, fl); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null filter_list") { + rc = tiledb_array_schema_set_validity_filter_list( + x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + REQUIRE_NOTHROW(tiledb_filter_list_free(&fl)); + CHECK(fl == nullptr); +} + +TEST_CASE( + "C API: tiledb_array_schema_check argument validation", + "[capi][array_schema]") { + /* + * No "success" section here; too much overhead to set up. + */ + capi_return_t rc; + ordinary_array_schema x{}; + SECTION("null context") { + rc = tiledb_array_schema_check(nullptr, x.schema); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_check(x.ctx(), nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_get_array_type argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_array_type_t array_type; + SECTION("success") { + rc = tiledb_array_schema_get_array_type(x.ctx(), x.schema, &array_type); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_array_type(nullptr, x.schema, &array_type); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_array_type(x.ctx(), nullptr, &array_type); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null array_type") { + rc = tiledb_array_schema_get_array_type(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_get_capacity argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + uint64_t capacity; + SECTION("success") { + rc = tiledb_array_schema_get_capacity(x.ctx(), x.schema, &capacity); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_capacity(nullptr, x.schema, &capacity); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_capacity(x.ctx(), nullptr, &capacity); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null capacity") { + rc = tiledb_array_schema_get_capacity(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_get_cell_order argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_layout_t cell_order; + SECTION("success") { + rc = tiledb_array_schema_get_cell_order(x.ctx(), x.schema, &cell_order); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_cell_order(nullptr, x.schema, &cell_order); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_cell_order(x.ctx(), nullptr, &cell_order); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null cell_order") { + rc = tiledb_array_schema_get_cell_order(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_get_coords_filter_list argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_filter_list_t* fl; + SECTION("success") { + rc = tiledb_array_schema_get_coords_filter_list(x.ctx(), x.schema, &fl); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_coords_filter_list(nullptr, x.schema, &fl); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_coords_filter_list(x.ctx(), nullptr, &fl); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null filter_list") { + rc = tiledb_array_schema_get_coords_filter_list(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_get_offsets_filter_list argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_filter_list_t* fl; + SECTION("success") { + rc = tiledb_array_schema_get_offsets_filter_list(x.ctx(), x.schema, &fl); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_offsets_filter_list(nullptr, x.schema, &fl); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_offsets_filter_list(x.ctx(), nullptr, &fl); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null filter_list") { + rc = + tiledb_array_schema_get_offsets_filter_list(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_get_validity_filter_list argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_filter_list_t* fl; + SECTION("success") { + rc = tiledb_array_schema_get_validity_filter_list(x.ctx(), x.schema, &fl); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_validity_filter_list(nullptr, x.schema, &fl); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_validity_filter_list(x.ctx(), nullptr, &fl); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null filter_list") { + rc = tiledb_array_schema_get_validity_filter_list( + x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_get_domain argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_domain_t* domain; + SECTION("success") { + rc = tiledb_array_schema_get_domain(x.ctx(), x.schema, &domain); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_domain(nullptr, x.schema, &domain); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_domain(x.ctx(), nullptr, &domain); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null domain") { + rc = tiledb_array_schema_get_domain(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_get_tile_order argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_layout_t tile_order; + SECTION("success") { + rc = tiledb_array_schema_get_tile_order(x.ctx(), x.schema, &tile_order); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_tile_order(nullptr, x.schema, &tile_order); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_tile_order(x.ctx(), nullptr, &tile_order); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null tile_order") { + rc = tiledb_array_schema_get_tile_order(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_get_attribute_num argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + uint32_t attr_num; + SECTION("success") { + rc = tiledb_array_schema_get_attribute_num(x.ctx(), x.schema, &attr_num); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_attribute_num(nullptr, x.schema, &attr_num); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_attribute_num(x.ctx(), nullptr, &attr_num); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null attribute_num") { + rc = tiledb_array_schema_get_attribute_num(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_dump_str argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_string_t* out; + /* + * No "success" section here; omitted to avoid log noise. + */ + SECTION("null context") { + rc = tiledb_array_schema_dump_str(nullptr, x.schema, &out); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_dump_str(x.ctx(), nullptr, &out); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + /* + * SECTION("null file pointer"): `nullptr` is allowed; it's mapped to `stdout` + */ +} + +TEST_CASE( + "C API: tiledb_array_schema_get_attribute_from_index argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema_with_attr x{}; + tiledb_attribute_t* attr; + SECTION("success") { + rc = tiledb_array_schema_get_attribute_from_index( + x.ctx(), x.schema, 0, &attr); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_attribute_from_index( + nullptr, x.schema, 0, &attr); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_attribute_from_index( + x.ctx(), nullptr, 0, &attr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("invalid index") { + rc = tiledb_array_schema_get_attribute_from_index( + x.ctx(), x.schema, 1, &attr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null attribute") { + rc = tiledb_array_schema_get_attribute_from_index( + x.ctx(), x.schema, 0, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_get_attribute_from_name argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema_with_attr x{}; + tiledb_attribute_t* attr; + SECTION("success") { + rc = tiledb_array_schema_get_attribute_from_name( + x.ctx(), x.schema, "a", &attr); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_attribute_from_name( + nullptr, x.schema, "a", &attr); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_attribute_from_name( + x.ctx(), nullptr, "a", &attr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("invalid name") { + rc = tiledb_array_schema_get_attribute_from_name( + x.ctx(), x.schema, "b", &attr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null attribute") { + rc = tiledb_array_schema_get_attribute_from_name( + x.ctx(), x.schema, "a", nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_has_attribute argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema_with_attr x{}; + int32_t has_attr; + SECTION("success") { + rc = tiledb_array_schema_has_attribute(x.ctx(), x.schema, "a", &has_attr); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + CHECK(has_attr == 1); + } + SECTION("null context") { + rc = tiledb_array_schema_has_attribute(nullptr, x.schema, "a", &has_attr); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_has_attribute(x.ctx(), nullptr, "a", &has_attr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("invalid name") { + // Note: this test is successful, but has_attr will equate to false (0). + rc = tiledb_array_schema_has_attribute(x.ctx(), x.schema, "b", &has_attr); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + CHECK(has_attr == 0); + } + SECTION("null has_attr") { + rc = tiledb_array_schema_has_attribute(x.ctx(), x.schema, "a", nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} + +TEST_CASE( + "C API: tiledb_array_schema_set_current_domain argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_current_domain_t* cd{}; + rc = tiledb_current_domain_create(x.ctx(), &cd); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + SECTION("success") { + rc = tiledb_array_schema_set_current_domain(x.ctx(), x.schema, cd); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_set_current_domain(nullptr, x.schema, cd); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_set_current_domain(x.ctx(), nullptr, cd); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null current_domain") { + rc = tiledb_array_schema_set_current_domain(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + REQUIRE_NOTHROW(tiledb_current_domain_free(&cd)); + CHECK(cd == nullptr); +} + +TEST_CASE( + "C API: tiledb_array_schema_get_current_domain argument validation", + "[capi][array_schema]") { + capi_return_t rc; + ordinary_array_schema x{}; + tiledb_current_domain_t* cd; + SECTION("success") { + rc = tiledb_array_schema_get_current_domain(x.ctx(), x.schema, &cd); + REQUIRE(tiledb_status(rc) == TILEDB_OK); + } + SECTION("null context") { + rc = tiledb_array_schema_get_current_domain(nullptr, x.schema, &cd); + REQUIRE(tiledb_status(rc) == TILEDB_INVALID_CONTEXT); + } + SECTION("null schema") { + rc = tiledb_array_schema_get_current_domain(x.ctx(), nullptr, &cd); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } + SECTION("null current_domain") { + rc = tiledb_array_schema_get_current_domain(x.ctx(), x.schema, nullptr); + REQUIRE(tiledb_status(rc) == TILEDB_ERR); + } +} diff --git a/tiledb/api/c_api_test_support/testsupport_capi_array_schema.h b/tiledb/api/c_api_test_support/testsupport_capi_array_schema.h new file mode 100644 index 00000000000..420bb8621b7 --- /dev/null +++ b/tiledb/api/c_api_test_support/testsupport_capi_array_schema.h @@ -0,0 +1,93 @@ +/** + * @file tiledb/api/c_api_test_support/testsupport_capi_array_schema.h + * + * @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 test support for the array schema section of the C API. + */ + +#ifndef TILEDB_TESTSUPPORT_CAPI_ARRAY_SCHEMA_H +#define TILEDB_TESTSUPPORT_CAPI_ARRAY_SCHEMA_H + +#include "testsupport_capi_context.h" +#include "tiledb/api/c_api/array_schema/array_schema_api_external.h" +#include "tiledb/api/c_api/array_schema/array_schema_api_internal.h" + +namespace tiledb::api::test_support { + +/** + * Ordinary array schema base class + */ +class ordinary_array_schema { + public: + ordinary_context context{}; + tiledb_array_schema_handle_t* schema{nullptr}; + + ordinary_array_schema(tiledb_array_type_t array_type = TILEDB_SPARSE) { + auto rc = tiledb_array_schema_alloc(context.context, array_type, &schema); + if (rc != TILEDB_OK) { + throw std::runtime_error("error creating test array_schema"); + } + if (schema == nullptr) { + throw std::logic_error( + "tiledb_array_schema_alloc returned OK but without array_schema"); + } + } + + ~ordinary_array_schema() { + tiledb_array_schema_free(&schema); + } + + [[nodiscard]] tiledb_ctx_handle_t* ctx() const { + return context.context; + } +}; + +struct ordinary_array_schema_with_attr : public ordinary_array_schema { + tiledb_attribute_t* attr{nullptr}; + + ordinary_array_schema_with_attr( + tiledb_array_type_t array_type = TILEDB_SPARSE) + : ordinary_array_schema(array_type) { + auto rc = tiledb_attribute_alloc(context.context, "a", TILEDB_INT32, &attr); + if (rc != TILEDB_OK) { + throw std::runtime_error("error creating test attribute"); + } + rc = tiledb_array_schema_add_attribute(context.context, schema, attr); + if (rc != TILEDB_OK) { + throw std::runtime_error("error adding test attribute to test schema"); + } + } + + ~ordinary_array_schema_with_attr() { + tiledb_attribute_free(&attr); + } +}; + +} // namespace tiledb::api::test_support + +#endif // TILEDB_TESTSUPPORT_CAPI_ARRAY_SCHEMA_H diff --git a/tiledb/sm/c_api/api_argument_validator.h b/tiledb/sm/c_api/api_argument_validator.h index df62b27c37b..1f15be6b4c6 100644 --- a/tiledb/sm/c_api/api_argument_validator.h +++ b/tiledb/sm/c_api/api_argument_validator.h @@ -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 @@ -81,17 +81,6 @@ inline void ensure_subarray_is_valid(const tiledb_subarray_t* p) { } } // namespace tiledb::api -inline int32_t sanity_check( - tiledb_ctx_t* ctx, const tiledb_array_schema_t* array_schema) { - if (array_schema == nullptr || array_schema->array_schema_ == nullptr) { - auto st = Status_Error("Invalid TileDB array schema object"); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_ERR; - } - return TILEDB_OK; -} - inline int32_t sanity_check( tiledb_ctx_t* ctx, const tiledb_array_schema_evolution_t* schema_evolution) { diff --git a/tiledb/sm/c_api/tiledb.cc b/tiledb/sm/c_api/tiledb.cc index f45043b5ca2..04dde23cc33 100644 --- a/tiledb/sm/c_api/tiledb.cc +++ b/tiledb/sm/c_api/tiledb.cc @@ -36,6 +36,8 @@ #include "tiledb_serialization.h" #include "tiledb_struct_def.h" +#include "tiledb/api/c_api/array/array_api_internal.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/api/c_api/buffer/buffer_api_internal.h" #include "tiledb/api/c_api/buffer_list/buffer_list_api_internal.h" @@ -55,17 +57,14 @@ #include "tiledb/common/logger.h" #include "tiledb/common/memory_tracker.h" #include "tiledb/sm/array/array.h" -#include "tiledb/sm/array_schema/array_schema.h" #include "tiledb/sm/array_schema/dimension_label.h" #include "tiledb/sm/c_api/api_argument_validator.h" #include "tiledb/sm/config/config.h" #include "tiledb/sm/config/config_iter.h" #include "tiledb/sm/consolidator/consolidator.h" #include "tiledb/sm/cpp_api/core_interface.h" -#include "tiledb/sm/enums/array_type.h" #include "tiledb/sm/enums/encryption_type.h" #include "tiledb/sm/enums/filesystem.h" -#include "tiledb/sm/enums/layout.h" #include "tiledb/sm/enums/mime_type.h" #include "tiledb/sm/enums/object_type.h" #include "tiledb/sm/enums/query_status.h" @@ -136,37 +135,6 @@ namespace tiledb::api { /* ENUMS TO/FROM STR */ /* ****************************** */ -int32_t tiledb_array_type_to_str( - tiledb_array_type_t array_type, const char** str) { - const auto& strval = - tiledb::sm::array_type_str((tiledb::sm::ArrayType)array_type); - *str = strval.c_str(); - return strval.empty() ? TILEDB_ERR : TILEDB_OK; -} - -int32_t tiledb_array_type_from_str( - const char* str, tiledb_array_type_t* array_type) { - tiledb::sm::ArrayType val = tiledb::sm::ArrayType::DENSE; - if (!tiledb::sm::array_type_enum(str, &val).ok()) - return TILEDB_ERR; - *array_type = (tiledb_array_type_t)val; - return TILEDB_OK; -} - -int32_t tiledb_layout_to_str(tiledb_layout_t layout, const char** str) { - const auto& strval = tiledb::sm::layout_str((tiledb::sm::Layout)layout); - *str = strval.c_str(); - return strval.empty() ? TILEDB_ERR : TILEDB_OK; -} - -int32_t tiledb_layout_from_str(const char* str, tiledb_layout_t* layout) { - tiledb::sm::Layout val = tiledb::sm::Layout::ROW_MAJOR; - if (!tiledb::sm::layout_enum(str, &val).ok()) - return TILEDB_ERR; - *layout = (tiledb_layout_t)val; - return TILEDB_OK; -} - int32_t tiledb_encryption_type_to_str( tiledb_encryption_type_t encryption_type, const char** str) { const auto& strval = tiledb::sm::encryption_type_str( @@ -243,529 +211,6 @@ capi_return_t tiledb_as_built_dump(tiledb_string_t** out) { return TILEDB_OK; } -/* ****************************** */ -/* ARRAY SCHEMA */ -/* ****************************** */ - -int32_t tiledb_array_schema_alloc( - tiledb_ctx_t* ctx, - tiledb_array_type_t array_type, - tiledb_array_schema_t** array_schema) { - // Create array schema struct - *array_schema = new (std::nothrow) tiledb_array_schema_t; - if (*array_schema == nullptr) { - auto st = Status_Error("Failed to allocate TileDB array schema object"); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_OOM; - } - - // Create a new ArraySchema object - auto memory_tracker = ctx->resources().create_memory_tracker(); - memory_tracker->set_type(sm::MemoryTrackerType::ARRAY_CREATE); - (*array_schema)->array_schema_ = make_shared( - HERE(), static_cast(array_type), memory_tracker); - if ((*array_schema)->array_schema_ == nullptr) { - auto st = Status_Error("Failed to allocate TileDB array schema object"); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_OOM; - } - - // Success - return TILEDB_OK; -} - -void tiledb_array_schema_free(tiledb_array_schema_t** array_schema) { - if (array_schema != nullptr && *array_schema != nullptr) { - delete *array_schema; - *array_schema = nullptr; - } -} - -int32_t tiledb_array_schema_add_attribute( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_attribute_t* attr) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) { - return TILEDB_ERR; - } - ensure_attribute_is_valid(attr); - /** Note: The call to make_shared creates a copy of the attribute and - * the user-visible handle to the attr no longer refers to the same object - * that's in the array_schema. - **/ - throw_if_not_ok( - array_schema->array_schema_->add_attribute(attr->copy_attribute())); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_set_allows_dups( - tiledb_ctx_t* ctx, tiledb_array_schema_t* array_schema, int allows_dups) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - throw_if_not_ok(array_schema->array_schema_->set_allows_dups(allows_dups)); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_allows_dups( - tiledb_ctx_t* ctx, tiledb_array_schema_t* array_schema, int* allows_dups) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - *allows_dups = (int)array_schema->array_schema_->allows_dups(); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_version( - tiledb_ctx_t* ctx, tiledb_array_schema_t* array_schema, uint32_t* version) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - *version = (uint32_t)array_schema->array_schema_->version(); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_set_domain( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_domain_t* domain) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - throw_if_not_ok( - array_schema->array_schema_->set_domain(domain->copy_domain())); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_set_capacity( - tiledb_ctx_t* ctx, tiledb_array_schema_t* array_schema, uint64_t capacity) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - array_schema->array_schema_->set_capacity(capacity); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_set_cell_order( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_layout_t cell_order) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - throw_if_not_ok(array_schema->array_schema_->set_cell_order( - static_cast(cell_order))); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_set_tile_order( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_layout_t tile_order) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - throw_if_not_ok(array_schema->array_schema_->set_tile_order( - static_cast(tile_order))); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_timestamp_range( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - uint64_t* lo, - uint64_t* hi) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - - auto timestamp_range = array_schema->array_schema_->timestamp_range(); - *lo = std::get<0>(timestamp_range); - *hi = std::get<1>(timestamp_range); - - return TILEDB_OK; -} - -int32_t tiledb_array_schema_add_enumeration( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_enumeration_t* enumeration) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) { - return TILEDB_ERR; - } - - api::ensure_enumeration_is_valid(enumeration); - - array_schema->array_schema_->add_enumeration(enumeration->copy()); - - return TILEDB_OK; -} - -int32_t tiledb_array_schema_set_coords_filter_list( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t* filter_list) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) { - return TILEDB_ERR; - } - api::ensure_filter_list_is_valid(filter_list); - - throw_if_not_ok(array_schema->array_schema_->set_coords_filter_pipeline( - filter_list->pipeline())); - - return TILEDB_OK; -} - -int32_t tiledb_array_schema_set_offsets_filter_list( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t* filter_list) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) { - return TILEDB_ERR; - } - api::ensure_filter_list_is_valid(filter_list); - - throw_if_not_ok( - array_schema->array_schema_->set_cell_var_offsets_filter_pipeline( - filter_list->pipeline())); - - return TILEDB_OK; -} - -int32_t tiledb_array_schema_set_validity_filter_list( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t* filter_list) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) { - return TILEDB_ERR; - } - api::ensure_filter_list_is_valid(filter_list); - - throw_if_not_ok( - array_schema->array_schema_->set_cell_validity_filter_pipeline( - filter_list->pipeline())); - - return TILEDB_OK; -} - -int32_t tiledb_array_schema_check( - tiledb_ctx_t* ctx, tiledb_array_schema_t* array_schema) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - array_schema->array_schema_->check(ctx->resources().config()); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_load( - tiledb_ctx_t* ctx, - const char* array_uri, - tiledb_array_schema_t** array_schema) { - // Create array schema - *array_schema = new (std::nothrow) tiledb_array_schema_t; - if (*array_schema == nullptr) { - auto st = Status_Error("Failed to allocate TileDB array schema object"); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_OOM; - } - - // Check array name - tiledb::sm::URI uri(array_uri); - if (uri.is_invalid()) { - auto st = Status_Error("Failed to load array schema; Invalid array URI"); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_ERR; - } - - 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()) { - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - delete *array_schema; - return TILEDB_ERR; - } - (*array_schema)->array_schema_ = array_schema_rest.value(); - } 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 array_dir; - try { - array_dir.emplace( - ctx->resources(), - uri, - 0, - UINT64_MAX, - tiledb::sm::ArrayDirectoryMode::SCHEMA_ONLY); - } catch (const std::logic_error& le) { - auto st = Status_ArrayDirectoryError(le.what()); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - delete *array_schema; - return TILEDB_ERR; - } - - auto tracker = ctx->resources().ephemeral_memory_tracker(); - - // Load latest array schema - auto&& array_schema_latest = - array_dir->load_array_schema_latest(key, tracker); - (*array_schema)->array_schema_ = array_schema_latest; - } - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_array_type( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_array_type_t* array_type) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - *array_type = static_cast( - array_schema->array_schema_->array_type()); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_capacity( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - uint64_t* capacity) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - *capacity = array_schema->array_schema_->capacity(); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_cell_order( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_layout_t* cell_order) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - *cell_order = - static_cast(array_schema->array_schema_->cell_order()); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_coords_filter_list( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t** filter_list) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - api::ensure_output_pointer_is_valid(filter_list); - // Copy-construct a separate FilterPipeline object - *filter_list = tiledb_filter_list_t::make_handle( - sm::FilterPipeline{array_schema->array_schema_->coords_filters()}); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_offsets_filter_list( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t** filter_list) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - api::ensure_output_pointer_is_valid(filter_list); - // Copy-construct a separate FilterPipeline object - *filter_list = tiledb_filter_list_t::make_handle(sm::FilterPipeline{ - array_schema->array_schema_->cell_var_offsets_filters()}); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_validity_filter_list( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t** filter_list) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - api::ensure_output_pointer_is_valid(filter_list); - // Copy-construct a separate FilterPipeline object - *filter_list = tiledb_filter_list_t::make_handle( - sm::FilterPipeline{array_schema->array_schema_->cell_validity_filters()}); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_domain( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_domain_t** domain) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) { - return TILEDB_ERR; - } - ensure_output_pointer_is_valid(domain); - *domain = tiledb_domain_handle_t::make_handle( - array_schema->array_schema_->shared_domain()); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_tile_order( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_layout_t* tile_order) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - *tile_order = - static_cast(array_schema->array_schema_->tile_order()); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_attribute_num( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - uint32_t* attribute_num) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - *attribute_num = array_schema->array_schema_->attribute_num(); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_dump( - tiledb_ctx_t* ctx, const tiledb_array_schema_t* array_schema, FILE* out) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; - - ensure_cstream_handle_is_valid(out); - - std::stringstream ss; - - ss << *array_schema->array_schema_; - size_t r = fwrite(ss.str().c_str(), sizeof(char), ss.str().size(), out); - if (r != ss.str().size()) { - throw CAPIException( - "Error writing array schema " + - array_schema->array_schema_->array_uri().to_string() + " to file"); - } - - return TILEDB_OK; -} - -int32_t tiledb_array_schema_dump_str( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_string_t** out) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) { - return TILEDB_ERR; - } - ensure_output_pointer_is_valid(out); - std::stringstream ss; - ss << *array_schema->array_schema_; - *out = tiledb_string_handle_t::make_handle(ss.str()); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_attribute_from_index( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - uint32_t index, - tiledb_attribute_t** attr) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) { - return TILEDB_ERR; - } - ensure_output_pointer_is_valid(attr); - uint32_t attribute_num = array_schema->array_schema_->attribute_num(); - if (attribute_num == 0) { - *attr = nullptr; - return TILEDB_OK; - } - if (index >= attribute_num) { - std::ostringstream errmsg; - errmsg << "Attribute index: " << index << " out of bounds given " - << attribute_num << " attributes in array " - << array_schema->array_schema_->array_uri().to_string(); - auto st = Status_ArraySchemaError(errmsg.str()); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_ERR; - } - - auto found_attr = array_schema->array_schema_->shared_attribute(index); - if (!found_attr) { - throw CAPIStatusException("Attribute not found, but index is valid!"); - } - *attr = tiledb_attribute_handle_t::make_handle(found_attr); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_attribute_from_name( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - const char* name, - tiledb_attribute_t** attr) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) { - return TILEDB_ERR; - } - ensure_output_pointer_is_valid(attr); - uint32_t attribute_num = array_schema->array_schema_->attribute_num(); - if (attribute_num == 0) { - *attr = nullptr; - return TILEDB_OK; - } - std::string name_string(name); - auto found_attr = array_schema->array_schema_->shared_attribute(name_string); - if (!found_attr) { - throw CAPIException( - std::string("Attribute name: ") + - (name_string.empty() ? "" : name) + - " does not exist for array " + - array_schema->array_schema_->array_uri().to_string()); - } - *attr = tiledb_attribute_handle_t::make_handle(found_attr); - return TILEDB_OK; -} - -int32_t tiledb_array_schema_has_attribute( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - const char* name, - int32_t* has_attr) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) { - return TILEDB_ERR; - } - - bool b; - throw_if_not_ok(array_schema->array_schema_->has_attribute(name, &b)); - - *has_attr = b ? 1 : 0; - - return TILEDB_OK; -} - -int32_t tiledb_array_schema_set_current_domain( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_current_domain_t* current_domain) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) { - return TILEDB_ERR; - } - - api::ensure_handle_is_valid(current_domain); - - array_schema->array_schema_->set_current_domain( - current_domain->current_domain()); - - return TILEDB_OK; -} - -int32_t tiledb_array_schema_get_current_domain( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_current_domain_t** current_domain) { - if (sanity_check(ctx, array_schema) == TILEDB_ERR) { - return TILEDB_ERR; - } - - api::ensure_output_pointer_is_valid(current_domain); - - // There is always a current domain on an ArraySchema instance, - // when none was set explicitly, there is an empty current domain. - *current_domain = tiledb_current_domain_handle_t::make_handle( - array_schema->array_schema_->get_current_domain()); - - return TILEDB_OK; -} - /* ********************************* */ /* SCHEMA EVOLUTION */ /* ********************************* */ @@ -2220,25 +1665,17 @@ int32_t tiledb_array_get_schema( if (sanity_check(ctx, array) == TILEDB_ERR) { return TILEDB_ERR; } - - *array_schema = new (std::nothrow) tiledb_array_schema_t; - if (*array_schema == nullptr) { - auto st = Status_Error("Failed to allocate TileDB array schema"); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_OOM; - } + ensure_output_pointer_is_valid(array_schema); // Get schema auto&& [st, array_schema_get] = array->array_->get_array_schema(); if (!st.ok()) { LOG_STATUS_NO_RETURN_VALUE(st); save_error(ctx, st); - delete *array_schema; - *array_schema = nullptr; + tiledb_array_schema_t::break_handle(*array_schema); return TILEDB_ERR; } - (*array_schema)->array_schema_ = array_schema_get.value(); + *array_schema = tiledb_array_schema_t::make_handle(array_schema_get.value()); return TILEDB_OK; } @@ -2267,9 +1704,7 @@ int32_t tiledb_array_create( tiledb_ctx_t* ctx, const char* array_uri, const tiledb_array_schema_t* array_schema) { - // Sanity checks - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; + ensure_array_schema_is_valid(array_schema); // Check array name tiledb::sm::URI uri(array_uri); @@ -2283,7 +1718,7 @@ int32_t tiledb_array_create( if (uri.is_tiledb()) { auto& rest_client = ctx->context().rest_client(); throw_if_not_ok(rest_client.post_array_schema_to_rest( - uri, *(array_schema->array_schema_.get()))); + uri, *(array_schema->array_schema()))); } else { // Create key tiledb::sm::EncryptionKey key; @@ -2291,21 +1726,20 @@ int32_t tiledb_array_create( key.set_key(tiledb::sm::EncryptionType::NO_ENCRYPTION, nullptr, 0)); // Create the array tiledb::sm::Array::create( - ctx->resources(), uri, array_schema->array_schema_, key); + ctx->resources(), uri, array_schema->array_schema(), key); // Create any dimension labels in the array. for (tiledb::sm::ArraySchema::dimension_label_size_type ilabel{0}; - ilabel < array_schema->array_schema_->dim_label_num(); + ilabel < array_schema->dim_label_num(); ++ilabel) { // Get dimension label information and define URI and name. - const auto& dim_label_ref = - array_schema->array_schema_->dimension_label(ilabel); + const auto& dim_label_ref = array_schema->dimension_label(ilabel); if (dim_label_ref.is_external()) continue; if (!dim_label_ref.has_schema()) { - throw StatusException( - Status_Error("Failed to create array. Dimension labels that are " - "not external must have a schema.")); + throw CAPIStatusException( + "Failed to create array. Dimension labels that are " + "not external must have a schema."); } // Create the dimension label array with the same key. @@ -3044,8 +2478,7 @@ int32_t tiledb_serialize_array_schema( int32_t client_side, tiledb_buffer_t** buffer) { // Sanity check - if (sanity_check(ctx, array_schema) == TILEDB_ERR) - return TILEDB_ERR; + ensure_array_schema_is_valid(array_schema); // Create buffer auto buf = tiledb_buffer_handle_t::make_handle(); @@ -3053,7 +2486,7 @@ int32_t tiledb_serialize_array_schema( if (SAVE_ERROR_CATCH( ctx, tiledb::sm::serialization::array_schema_serialize( - *(array_schema->array_schema_.get()), + *(array_schema->array_schema()), (tiledb::sm::SerializationType)serialize_type, &(buf->buffer()), client_side))) { @@ -3073,27 +2506,19 @@ int32_t tiledb_deserialize_array_schema( int32_t, tiledb_array_schema_t** array_schema) { api::ensure_buffer_is_valid(buffer); + ensure_output_pointer_is_valid(array_schema); // Create array schema struct - *array_schema = new (std::nothrow) tiledb_array_schema_t; - if (*array_schema == nullptr) { - auto st = Status_Error("Failed to allocate TileDB array schema object"); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_OOM; - } - try { auto memory_tracker = ctx->resources().create_memory_tracker(); memory_tracker->set_type(sm::MemoryTrackerType::ARRAY_LOAD); - (*array_schema)->array_schema_ = - tiledb::sm::serialization::array_schema_deserialize( - (tiledb::sm::SerializationType)serialize_type, - buffer->buffer(), - memory_tracker); + auto shared_schema = tiledb::sm::serialization::array_schema_deserialize( + (tiledb::sm::SerializationType)serialize_type, + buffer->buffer(), + memory_tracker); + *array_schema = tiledb_array_schema_t::make_handle(shared_schema); } catch (...) { - delete *array_schema; - *array_schema = nullptr; + tiledb_array_schema_t::break_handle(*array_schema); throw; } @@ -4506,21 +3931,14 @@ int32_t tiledb_fragment_info_get_array_schema( tiledb_fragment_info_t* fragment_info, uint32_t fid, tiledb_array_schema_t** array_schema) { - if (sanity_check(ctx, fragment_info) == TILEDB_ERR) + if (sanity_check(ctx, fragment_info) == TILEDB_ERR) { return TILEDB_ERR; - - // Create array schema - *array_schema = new (std::nothrow) tiledb_array_schema_t; - if (*array_schema == nullptr) { - auto st = Status_Error("Failed to allocate TileDB array schema object"); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_OOM; } + ensure_output_pointer_is_valid(array_schema); auto&& array_schema_get = fragment_info->fragment_info_->get_array_schema(fid); - (*array_schema)->array_schema_ = array_schema_get; + *array_schema = tiledb_array_schema_t::make_handle(array_schema_get); return TILEDB_OK; } @@ -4732,25 +4150,6 @@ constexpr auto api_entry = tiledb::api::api_entry_with_context; /* ****************************** */ /* ENUMS TO/FROM STR */ /* ****************************** */ -CAPI_INTERFACE( - array_type_to_str, tiledb_array_type_t array_type, const char** str) { - return api_entry_plain( - array_type, str); -} - -CAPI_INTERFACE( - array_type_from_str, const char* str, tiledb_array_type_t* array_type) { - return api_entry_plain( - str, array_type); -} - -CAPI_INTERFACE(layout_to_str, tiledb_layout_t layout, const char** str) { - return api_entry_plain(layout, str); -} - -CAPI_INTERFACE(layout_from_str, const char* str, tiledb_layout_t* layout) { - return api_entry_plain(str, layout); -} CAPI_INTERFACE( encryption_type_to_str, @@ -4857,304 +4256,6 @@ CAPI_INTERFACE(as_built_dump, tiledb_string_t** out) { return api_entry_plain(out); } -/* ****************************** */ -/* ARRAY SCHEMA */ -/* ****************************** */ - -CAPI_INTERFACE( - array_schema_alloc, - tiledb_ctx_t* ctx, - tiledb_array_type_t array_type, - tiledb_array_schema_t** array_schema) { - return api_entry( - ctx, array_type, array_schema); -} - -CAPI_INTERFACE_VOID(array_schema_free, tiledb_array_schema_t** array_schema) { - return api_entry_void(array_schema); -} - -CAPI_INTERFACE( - array_schema_add_attribute, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_attribute_t* attr) { - return api_entry( - ctx, array_schema, attr); -} - -CAPI_INTERFACE( - array_schema_set_allows_dups, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - int allows_dups) { - return api_entry( - ctx, array_schema, allows_dups); -} - -CAPI_INTERFACE( - array_schema_get_allows_dups, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - int* allows_dups) { - return api_entry( - ctx, array_schema, allows_dups); -} - -CAPI_INTERFACE( - array_schema_get_version, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - uint32_t* version) { - return api_entry( - ctx, array_schema, version); -} - -CAPI_INTERFACE( - array_schema_set_domain, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_domain_t* domain) { - return api_entry( - ctx, array_schema, domain); -} - -CAPI_INTERFACE( - array_schema_set_capacity, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - uint64_t capacity) { - return api_entry( - ctx, array_schema, capacity); -} - -CAPI_INTERFACE( - array_schema_set_cell_order, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_layout_t cell_order) { - return api_entry( - ctx, array_schema, cell_order); -} - -CAPI_INTERFACE( - array_schema_set_tile_order, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_layout_t tile_order) { - return api_entry( - ctx, array_schema, tile_order); -} - -CAPI_INTERFACE( - array_schema_timestamp_range, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - uint64_t* lo, - uint64_t* hi) { - return api_entry( - ctx, array_schema, lo, hi); -} - -CAPI_INTERFACE( - array_schema_add_enumeration, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_enumeration_t* enumeration) { - return api_entry( - ctx, array_schema, enumeration); -} - -CAPI_INTERFACE( - array_schema_set_coords_filter_list, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t* filter_list) { - return api_entry( - ctx, array_schema, filter_list); -} - -CAPI_INTERFACE( - array_schema_set_offsets_filter_list, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t* filter_list) { - return api_entry( - ctx, array_schema, filter_list); -} - -CAPI_INTERFACE( - array_schema_set_validity_filter_list, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t* filter_list) { - return api_entry( - ctx, array_schema, filter_list); -} - -CAPI_INTERFACE( - array_schema_check, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema) { - return api_entry(ctx, array_schema); -} - -CAPI_INTERFACE( - array_schema_load, - tiledb_ctx_t* ctx, - const char* array_uri, - tiledb_array_schema_t** array_schema) { - return api_entry( - ctx, array_uri, array_schema); -} - -CAPI_INTERFACE( - array_schema_get_array_type, - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_array_type_t* array_type) { - return api_entry( - ctx, array_schema, array_type); -} - -CAPI_INTERFACE( - array_schema_get_capacity, - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - uint64_t* capacity) { - return api_entry( - ctx, array_schema, capacity); -} - -CAPI_INTERFACE( - array_schema_get_cell_order, - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_layout_t* cell_order) { - return api_entry( - ctx, array_schema, cell_order); -} - -CAPI_INTERFACE( - array_schema_get_coords_filter_list, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t** filter_list) { - return api_entry( - ctx, array_schema, filter_list); -} - -CAPI_INTERFACE( - array_schema_get_offsets_filter_list, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t** filter_list) { - return api_entry( - ctx, array_schema, filter_list); -} - -CAPI_INTERFACE( - array_schema_get_validity_filter_list, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t** filter_list) { - return api_entry( - ctx, array_schema, filter_list); -} - -CAPI_INTERFACE( - array_schema_get_domain, - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_domain_t** domain) { - return api_entry( - ctx, array_schema, domain); -} - -CAPI_INTERFACE( - array_schema_get_tile_order, - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_layout_t* tile_order) { - return api_entry( - ctx, array_schema, tile_order); -} - -CAPI_INTERFACE( - array_schema_get_attribute_num, - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - uint32_t* attribute_num) { - return api_entry( - ctx, array_schema, attribute_num); -} - -CAPI_INTERFACE( - array_schema_dump, - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - FILE* out) { - return api_entry( - ctx, array_schema, out); -} - -CAPI_INTERFACE( - array_schema_dump_str, - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_string_t** out) { - return api_entry( - ctx, array_schema, out); -} - -CAPI_INTERFACE( - array_schema_get_attribute_from_index, - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - uint32_t index, - tiledb_attribute_t** attr) { - return api_entry( - ctx, array_schema, index, attr); -} - -CAPI_INTERFACE( - array_schema_get_attribute_from_name, - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - const char* name, - tiledb_attribute_t** attr) { - return api_entry( - ctx, array_schema, name, attr); -} - -CAPI_INTERFACE( - array_schema_has_attribute, - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - const char* name, - int32_t* has_attr) { - return api_entry( - ctx, array_schema, name, has_attr); -} - -CAPI_INTERFACE( - array_schema_set_current_domain, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_current_domain_t* current_domain) { - return api_entry( - ctx, array_schema, current_domain); -} - -CAPI_INTERFACE( - array_schema_get_current_domain, - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_current_domain_t** current_domain) { - return api_entry( - ctx, array_schema, current_domain); -} - /* ********************************* */ /* SCHEMA EVOLUTION */ /* ********************************* */ diff --git a/tiledb/sm/c_api/tiledb.h b/tiledb/sm/c_api/tiledb.h index 56baeaf1fc7..c0bd23eb93e 100644 --- a/tiledb/sm/c_api/tiledb.h +++ b/tiledb/sm/c_api/tiledb.h @@ -55,6 +55,8 @@ /* * API sections */ +#include "tiledb/api/c_api/array/array_api_external.h" +#include "tiledb/api/c_api/array_schema/array_schema_api_external.h" #include "tiledb/api/c_api/attribute/attribute_api_external.h" #include "tiledb/api/c_api/buffer/buffer_api_external.h" #include "tiledb/api/c_api/buffer_list/buffer_list_api_external.h" @@ -121,22 +123,6 @@ typedef enum { #undef TILEDB_QUERY_CONDITION_COMBINATION_OP_ENUM } tiledb_query_condition_combination_op_t; -/** Array type. */ -typedef enum { -/** Helper macro for defining array type enums. */ -#define TILEDB_ARRAY_TYPE_ENUM(id) TILEDB_##id -#include "tiledb_enum.h" -#undef TILEDB_ARRAY_TYPE_ENUM -} tiledb_array_type_t; - -/** Tile or cell layout. */ -typedef enum { -/** Helper macro for defining layout type enums. */ -#define TILEDB_LAYOUT_ENUM(id) TILEDB_##id -#include "tiledb_enum.h" -#undef TILEDB_LAYOUT_ENUM -} tiledb_layout_t; - /** Encryption type. */ typedef enum { /** Helper macro for defining encryption enums. */ @@ -157,46 +143,6 @@ typedef enum { /* ENUMS TO/FROM STR */ /* ****************************** */ -/** - * Returns a string representation of the given array type. - * - * @param array_type Array type - * @param str Set to point to a constant string representation of the array type - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_type_to_str( - tiledb_array_type_t array_type, const char** str) TILEDB_NOEXCEPT; - -/** - * Parses a array type from the given string. - * - * @param str String representation to parse - * @param array_type Set to the parsed array type - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_type_from_str( - const char* str, tiledb_array_type_t* array_type) TILEDB_NOEXCEPT; - -/** - * Returns a string representation of the given layout. - * - * @param layout Layout - * @param str Set to point to a constant string representation of the layout - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t -tiledb_layout_to_str(tiledb_layout_t layout, const char** str) TILEDB_NOEXCEPT; - -/** - * Parses a layout from the given string. - * - * @param str String representation to parse - * @param layout Set to the parsed layout - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_layout_from_str( - const char* str, tiledb_layout_t* layout) TILEDB_NOEXCEPT; - /** * Returns a string representation of the given encryption type. * @@ -301,9 +247,6 @@ typedef struct tiledb_array_t tiledb_array_t; /** A subarray object. */ typedef struct tiledb_subarray_t tiledb_subarray_t; -/** A TileDB array schema. */ -typedef struct tiledb_array_schema_t tiledb_array_schema_t; - /** A TileDB query condition object. */ typedef struct tiledb_query_condition_t tiledb_query_condition_t; @@ -313,605 +256,6 @@ typedef struct tiledb_fragment_info_t tiledb_fragment_info_t; /** A consolidation plan object. */ typedef struct tiledb_consolidation_plan_t tiledb_consolidation_plan_t; -/* ********************************* */ -/* ARRAY SCHEMA */ -/* ********************************* */ - -/** - * Creates a TileDB array schema object. - * - * **Example:** - * - * @code{.c} - * tiledb_array_schema_t* array_schema; - * tiledb_array_schema_alloc(ctx, TILEDB_DENSE, &array_schema); - * @endcode - * - * @param ctx The TileDB context. - * @param array_type The array type. - * @param array_schema The TileDB array schema to be created. - * @return `TILEDB_OK` for success and `TILEDB_OOM` or `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_alloc( - tiledb_ctx_t* ctx, - tiledb_array_type_t array_type, - tiledb_array_schema_t** array_schema) TILEDB_NOEXCEPT; - -/** - * Destroys an array schema, freeing associated memory. - * - * **Example:** - * - * @code{.c} - * tiledb_array_schema_free(&array_schema); - * @endcode - * - * @param array_schema The array schema to be destroyed. - */ -TILEDB_EXPORT void tiledb_array_schema_free( - tiledb_array_schema_t** array_schema) TILEDB_NOEXCEPT; - -/** - * Adds an attribute to an array schema. - * - * **Example:** - * - * @code{.c} - * tiledb_attribute_t* attr; - * tiledb_attribute_alloc(ctx, "my_attr", TILEDB_INT32, &attr); - * tiledb_array_schema_add_attribute(ctx, array_schema, attr); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param attr The attribute to be added. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_add_attribute( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_attribute_t* attr) TILEDB_NOEXCEPT; - -/** - * Sets whether the array can allow coordinate duplicates or not. - * Applicable only to sparse arrays (it errors out if set to `1` for dense - * arrays). - * - * **Example:** - * - * @code{.c} - * int allows_dups = 1; - * tiledb_array_schema_set_allows_dups(ctx, array_schema, allows_dups); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param allows_dups Whether or not the array allows coordinate duplicates. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_set_allows_dups( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - int allows_dups) TILEDB_NOEXCEPT; - -/** - * Gets whether the array can allow coordinate duplicates or not. - * It should always be `0` for dense arrays. - * - * **Example:** - * - * @code{.c} - * int allows_dups; - * tiledb_array_schema_get_allows_dups(ctx, array_schema, &allows_dups); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param allows_dups Whether or not the array allows coordinate duplicates. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_allows_dups( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - int* allows_dups) TILEDB_NOEXCEPT; - -/** - * Returns the array schema version. - * - * **Example:** - * - * @code{.c} - * uint32_t version; - * tiledb_array_schema_get_version(ctx, array_schema, &version); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param version The version. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_version( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - uint32_t* version) TILEDB_NOEXCEPT; - -/** - * Sets a domain for the array schema. - * - * **Example:** - * - * @code{.c} - * tiledb_domain_t* domain; - * tiledb_domain_alloc(ctx, &domain); - * // -- Add dimensions to the domain here -- // - * tiledb_array_schema_set_domain(ctx, array_schema, domain); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param domain The domain to be set. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_set_domain( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_domain_t* domain) TILEDB_NOEXCEPT; - -/** - * Sets the tile capacity. Applies to sparse arrays only. - * - * **Example:** - * - * @code{.c} - * tiledb_array_schema_set_capacity(ctx, array_schema, 10000); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param capacity The capacity of a sparse data tile. Note that - * sparse data tiles exist in sparse fragments, which can be created - * in sparse arrays only. For more details, - * see [tutorials/tiling-sparse.html](tutorials/tiling-sparse.html). - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_set_capacity( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - uint64_t capacity) TILEDB_NOEXCEPT; - -/** - * Sets the cell order. - * - * **Example:** - * - * @code{.c} - * tiledb_array_schema_set_cell_order(ctx, array_schema, TILEDB_ROW_MAJOR); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param cell_order The cell order to be set. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_set_cell_order( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_layout_t cell_order) TILEDB_NOEXCEPT; - -/** - * Sets the tile order. - * - * **Example:** - * - * @code{.c} - * tiledb_array_schema_set_cell_order(ctx, array_schema, TILEDB_COL_MAJOR); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param tile_order The tile order to be set. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_set_tile_order( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_layout_t tile_order) TILEDB_NOEXCEPT; - -/** - * Sets the filter list to use for the coordinates. - * - * **Example:** - * - * @code{.c} - * tiledb_filter_list_t* filter_list; - * tiledb_filter_list_alloc(ctx, &filter_list); - * tiledb_filter_list_add_filter(ctx, filter_list, filter); - * tiledb_array_schema_set_coords_filter_list(ctx, array_schema, filter_list); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param filter_list The filter list to be set. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_set_coords_filter_list( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t* filter_list) TILEDB_NOEXCEPT; - -/** - * Sets the filter list to use for the offsets of variable-sized attribute - * values. - * - * **Example:** - * - * @code{.c} - * tiledb_filter_list_t* filter_list; - * tiledb_filter_list_alloc(ctx, &filter_list); - * tiledb_filter_list_add_filter(ctx, filter_list, filter); - * tiledb_array_schema_set_offsets_filter_list(ctx, array_schema, filter_list); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param filter_list The filter list to be set. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_set_offsets_filter_list( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t* filter_list) TILEDB_NOEXCEPT; - -/** - * Sets the filter list to use for the validity array of nullable attribute - * values. - * - * **Example:** - * - * @code{.c} - * tiledb_filter_list_t* filter_list; - * tiledb_filter_list_alloc(ctx, &filter_list); - * tiledb_filter_list_add_filter(ctx, filter_list, filter); - * tiledb_array_schema_set_validity_filter_list(ctx, array_schema, filter_list); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param filter_list The filter list to be set. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_set_validity_filter_list( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t* filter_list) TILEDB_NOEXCEPT; - -/** - * Checks the correctness of the array schema. - * - * **Example:** - * - * @code{.c} - * tiledb_array_schema_check(ctx, array_schema); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @return `TILEDB_OK` if the array schema is correct and `TILEDB_ERR` upon any - * error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_check( - tiledb_ctx_t* ctx, tiledb_array_schema_t* array_schema) TILEDB_NOEXCEPT; - -/** - * Retrieves the schema of an array from the disk, creating an array schema - * struct. - * - * **Example:** - * - * @code{.c} - * tiledb_array_schema_t* array_schema; - * tiledb_array_schema_load(ctx, "s3://tiledb_bucket/my_array", &array_schema); - * // Make sure to free the array schema in the end - * @endcode - * - * @param ctx The TileDB context. - * @param array_uri The array whose schema will be retrieved. - * @param array_schema The array schema to be retrieved, or `NULL` upon error. - * @return `TILEDB_OK` for success and `TILEDB_OOM` or `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_load( - tiledb_ctx_t* ctx, - const char* array_uri, - tiledb_array_schema_t** array_schema) TILEDB_NOEXCEPT; - -/** - * Retrieves the array type. - * - * **Example:** - * - * @code{.c} - * tiledb_array_schema_t* array_schema; - * tiledb_array_schema_load(ctx, "s3://tiledb_bucket/my_array", array_schema); - * tiledb_array_type_t* array_type; - * tiledb_array_schema_get_array_type(ctx, array_schema, &array_type); - * // Make sure to free the array schema in the end - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param array_type The array type to be retrieved. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_array_type( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_array_type_t* array_type) TILEDB_NOEXCEPT; - -/** - * Retrieves the capacity. - * - * **Example:** - * - * @code{.c} - * uint64_t capacity; - * tiledb_array_schema_get_capacity(ctx, array_schema, &capacity); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param capacity The capacity to be retrieved. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_capacity( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - uint64_t* capacity) TILEDB_NOEXCEPT; - -/** - * Retrieves the cell order. - * - * **Example:** - * - * @code{.c} - * tiledb_layout_t cell_order; - * tiledb_array_schema_get_cell_order(ctx, array_schema, &cell_order); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param cell_order The cell order to be retrieved. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_cell_order( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_layout_t* cell_order) TILEDB_NOEXCEPT; - -/** - * Retrieves the filter list used for the coordinates. - * - * **Example:** - * - * @code{.c} - * tiledb_filter_list_t* filter_list; - * tiledb_array_schema_get_coords_filter_list(ctx, array_schema, &filter_list); - * tiledb_filter_list_free(ctx, &filter_list); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param filter_list The filter list to be retrieved. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_coords_filter_list( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t** filter_list) TILEDB_NOEXCEPT; - -/** - * Retrieves the filter list used for the offsets. - * - * **Example:** - * - * @code{.c} - * tiledb_filter_list_t* filter_list; - * tiledb_array_schema_get_offsets_filter_list(ctx, array_schema, &filter_list); - * tiledb_filter_list_free(ctx, &filter_list); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param filter_list The filter list to be retrieved. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_offsets_filter_list( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t** filter_list) TILEDB_NOEXCEPT; - -/** - * Retrieves the filter list used for validity maps. - * - * **Example:** - * - * @code{.c} - * tiledb_filter_list_t* filter_list; - * tiledb_array_schema_get_validity_filter_list(ctx, array_schema, - * &filter_list); tiledb_filter_list_free(ctx, &filter_list); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param filter_list The filter list to be retrieved. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_validity_filter_list( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_filter_list_t** filter_list) TILEDB_NOEXCEPT; - -/** - * Retrieves the array domain. - * - * **Example:** - * - * @code{.c} - * tiledb_domain_t* domain; - * tiledb_array_schema_get_domain(ctx, array_schema, &domain); - * // Make sure to delete domain in the end - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param domain The array domain to be retrieved. - * @return `TILEDB_OK` for success and `TILEDB_OOM` or `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_domain( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_domain_t** domain) TILEDB_NOEXCEPT; - -/** - * Retrieves the tile order. - * - * **Example:** - * - * @code{.c} - * tiledb_layout_t tile_order; - * tiledb_array_schema_get_tile_order(ctx, array_schema, &tile_order); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param tile_order The tile order to be retrieved. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_tile_order( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_layout_t* tile_order) TILEDB_NOEXCEPT; - -/** - * Retrieves the number of array attributes. - * - * **Example:** - * - * @code{.c} - * uint32_t attr_num; - * tiledb_array_schema_get_attribute_num(ctx, array_schema, &attr_num); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param attribute_num The number of attributes to be retrieved. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_attribute_num( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - uint32_t* attribute_num) TILEDB_NOEXCEPT; - -/** - * Retrieves an attribute given its index. - * - * Attributes are ordered the same way they were defined - * when constructing the array schema. - * - * **Example:** - * - * The following retrieves the first attribute in the schema. - * - * @code{.c} - * tiledb_attribute_t* attr; - * tiledb_array_schema_get_attribute_from_index(ctx, array_schema, 0, &attr); - * // Make sure to delete the retrieved attribute in the end. - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param index The index of the attribute to retrieve. - * @param attr The attribute object to retrieve. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_attribute_from_index( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - uint32_t index, - tiledb_attribute_t** attr) TILEDB_NOEXCEPT; - -/** - * Retrieves an attribute given its name (key). - * - * **Example:** - * - * The following retrieves the first attribute in the schema. - * - * @code{.c} - * tiledb_attribute_t* attr; - * tiledb_array_schema_get_attribute_from_name( - * ctx, array_schema, "attr_0", &attr); - * // Make sure to delete the retrieved attribute in the end. - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param name The name (key) of the attribute to retrieve. - * @param attr THe attribute object to retrieve. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_attribute_from_name( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - const char* name, - tiledb_attribute_t** attr) TILEDB_NOEXCEPT; - -/** - * Checks whether the array schema has an attribute of the given name. - * - * **Example:** - * - * @code{.c} - * int32_t has_attr; - * tiledb_array_schema_has_attribute(ctx, array_schema, "attr_0", &has_attr); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param name The name of the attribute to check for. - * @param has_attr Set to `1` if the array schema has an attribute of the - * given name, else `0`. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_has_attribute( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - const char* name, - int32_t* has_attr) TILEDB_NOEXCEPT; - -/** - * Dumps the array schema in ASCII format in the selected string output. - * - * The output string handle must be freed by the user after use. - * - * **Example:** - * - * @code{.c} - * tiledb_string_t* tdb_string; - * tiledb_array_schema_dump_str(ctx, array_schema, &tdb_string); - * // Use the string - * tiledb_string_free(&tdb_string); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param out The output string. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_dump_str( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - tiledb_string_t** out) TILEDB_NOEXCEPT; - /* ********************************* */ /* QUERY */ /* ********************************* */ diff --git a/tiledb/sm/c_api/tiledb_deprecated.h b/tiledb/sm/c_api/tiledb_deprecated.h index c7c8379a9d6..d3bc83291b0 100644 --- a/tiledb/sm/c_api/tiledb_deprecated.h +++ b/tiledb/sm/c_api/tiledb_deprecated.h @@ -36,33 +36,14 @@ #include #include +#include "tiledb/api/c_api/array_schema/array_schema_api_deprecated.h" + #ifdef __cplusplus extern "C" { #endif // No deprecated APIs are declared at the moment. -/** - * Dumps the array schema in ASCII format in the selected file output. - * - * **Example:** - * - * The following prints the array schema dump in standard output. - * - * @code{.c} - * tiledb_array_schema_dump(ctx, array_schema, stdout); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param out The output handle. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_DEPRECATED_EXPORT int32_t tiledb_array_schema_dump( - tiledb_ctx_t* ctx, - const tiledb_array_schema_t* array_schema, - FILE* out) TILEDB_NOEXCEPT; - #ifdef __cplusplus } #endif diff --git a/tiledb/sm/c_api/tiledb_dimension_label.cc b/tiledb/sm/c_api/tiledb_dimension_label.cc index 01f472bf72a..53712a508c1 100644 --- a/tiledb/sm/c_api/tiledb_dimension_label.cc +++ b/tiledb/sm/c_api/tiledb_dimension_label.cc @@ -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 @@ -26,6 +26,7 @@ * THE SOFTWARE. */ +#include "tiledb/api/c_api/array_schema/array_schema_api_internal.h" #include "tiledb/api/c_api/attribute/attribute_api_internal.h" #include "tiledb/api/c_api/dimension/dimension_api_internal.h" #include "tiledb/api/c_api/dimension_label/dimension_label_api_internal.h" @@ -38,16 +39,13 @@ namespace tiledb::api { capi_return_t tiledb_array_schema_add_dimension_label( - tiledb_ctx_t* ctx, tiledb_array_schema_t* array_schema, const uint32_t dim_index, const char* name, tiledb_data_order_t label_order, tiledb_datatype_t label_type) { - if (sanity_check(ctx, array_schema)) { - return TILEDB_ERR; - } - array_schema->array_schema_->add_dimension_label( + ensure_array_schema_is_valid(array_schema); + array_schema->add_dimension_label( dim_index, name, static_cast(label_order), @@ -56,17 +54,13 @@ capi_return_t tiledb_array_schema_add_dimension_label( } capi_return_t tiledb_array_schema_get_dimension_label_from_name( - tiledb_ctx_t* ctx, tiledb_array_schema_t* array_schema, const char* label_name, tiledb_dimension_label_t** dim_label) { - if (sanity_check(ctx, array_schema)) { - return TILEDB_ERR; - } + ensure_array_schema_is_valid(array_schema); tiledb::api::ensure_output_pointer_is_valid(dim_label); *dim_label = tiledb_dimension_label_t::make_handle( - array_schema->array_schema_->array_uri(), - array_schema->array_schema_->dimension_label(label_name)); + array_schema->array_uri(), array_schema->dimension_label(label_name)); return TILEDB_OK; } @@ -74,42 +68,39 @@ capi_return_t tiledb_array_schema_has_dimension_label( const tiledb_array_schema_t* array_schema, const char* name, int32_t* has_dim_label) { - bool is_dim_label = array_schema->array_schema_->is_dim_label(name); + ensure_array_schema_is_valid(array_schema); + bool is_dim_label = array_schema->is_dim_label(name); *has_dim_label = is_dim_label ? 1 : 0; return TILEDB_OK; } capi_return_t tiledb_array_schema_set_dimension_label_filter_list( - tiledb_ctx_t* ctx, tiledb_array_schema_t* array_schema, const char* label_name, tiledb_filter_list_t* filter_list) { - if (sanity_check(ctx, array_schema)) { - return TILEDB_ERR; - } - api::ensure_filter_list_is_valid(filter_list); - array_schema->array_schema_->set_dimension_label_filter_pipeline( + ensure_array_schema_is_valid(array_schema); + ensure_filter_list_is_valid(filter_list); + array_schema->set_dimension_label_filter_pipeline( label_name, filter_list->pipeline()); return TILEDB_OK; } capi_return_t tiledb_array_schema_set_dimension_label_tile_extent( - tiledb_ctx_t* ctx, tiledb_array_schema_t* array_schema, const char* label_name, tiledb_datatype_t type, const void* tile_extent) { - if (sanity_check(ctx, array_schema)) { - return TILEDB_ERR; - } - array_schema->array_schema_->set_dimension_label_tile_extent( + ensure_array_schema_is_valid(array_schema); + array_schema->set_dimension_label_tile_extent( label_name, static_cast(type), tile_extent); return TILEDB_OK; } capi_return_t tiledb_array_schema_get_dimension_label_num( tiledb_array_schema_t* array_schema, uint64_t* dim_label_num) { - *dim_label_num = array_schema->array_schema_->dim_label_num(); + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(dim_label_num); + *dim_label_num = array_schema->dim_label_num(); return TILEDB_OK; } @@ -117,10 +108,11 @@ capi_return_t tiledb_array_schema_get_dimension_label_from_index( tiledb_array_schema_t* array_schema, uint64_t dim_label_index, tiledb_dimension_label_t** dim_label) { - tiledb::api::ensure_output_pointer_is_valid(dim_label); + ensure_array_schema_is_valid(array_schema); + ensure_output_pointer_is_valid(dim_label); *dim_label = tiledb_dimension_label_t::make_handle( - array_schema->array_schema_->array_uri(), - array_schema->array_schema_->dimension_label(dim_label_index)); + array_schema->array_uri(), + array_schema->dimension_label(dim_label_index)); return TILEDB_OK; } @@ -232,7 +224,8 @@ CAPI_INTERFACE( const char* name, tiledb_data_order_t label_order, tiledb_datatype_t label_type) { - return api_entry( + return api_entry_context< + tiledb::api::tiledb_array_schema_add_dimension_label>( ctx, array_schema, dim_index, name, label_order, label_type); } @@ -242,7 +235,7 @@ CAPI_INTERFACE( tiledb_array_schema_t* array_schema, const char* label_name, tiledb_dimension_label_t** dim_label) { - return api_entry_with_context< + return api_entry_context< tiledb::api::tiledb_array_schema_get_dimension_label_from_name>( ctx, array_schema, label_name, dim_label); } @@ -264,7 +257,7 @@ CAPI_INTERFACE( tiledb_array_schema_t* array_schema, const char* label_name, tiledb_filter_list_t* filter_list) { - return api_entry< + return api_entry_context< tiledb::api::tiledb_array_schema_set_dimension_label_filter_list>( ctx, array_schema, label_name, filter_list); } @@ -276,7 +269,7 @@ CAPI_INTERFACE( const char* label_name, tiledb_datatype_t type, const void* tile_extent) { - return api_entry< + return api_entry_context< tiledb::api::tiledb_array_schema_set_dimension_label_tile_extent>( ctx, array_schema, label_name, type, tile_extent); } diff --git a/tiledb/sm/c_api/tiledb_enum.h b/tiledb/sm/c_api/tiledb_enum.h index 9fb10866c03..f70b36719cb 100644 --- a/tiledb/sm/c_api/tiledb_enum.h +++ b/tiledb/sm/c_api/tiledb_enum.h @@ -1,7 +1,7 @@ /* * The MIT License * - * @copyright Copyright (c) 2017-2022 TileDB, Inc. + * @copyright Copyright (c) 2017-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 @@ -31,33 +31,13 @@ // clang-format is disabled on the first enum so that we can manually indent it // properly. // clang-format off -#ifdef TILEDB_ARRAY_TYPE_ENUM - /** Dense array */ - TILEDB_ARRAY_TYPE_ENUM(DENSE) = 0, - /** Sparse array */ - TILEDB_ARRAY_TYPE_ENUM(SPARSE) = 1, -#endif -// clang-format on - -#ifdef TILEDB_LAYOUT_ENUM - /** Row-major layout */ - TILEDB_LAYOUT_ENUM(ROW_MAJOR) = 0, - /** Column-major layout */ - TILEDB_LAYOUT_ENUM(COL_MAJOR) = 1, - /** Global-order layout */ - TILEDB_LAYOUT_ENUM(GLOBAL_ORDER) = 2, - /** Unordered layout */ - TILEDB_LAYOUT_ENUM(UNORDERED) = 3, - /** Hilbert layout */ - TILEDB_LAYOUT_ENUM(HILBERT) = 4, -#endif - #ifdef TILEDB_ENCRYPTION_TYPE_ENUM /** No encryption. */ TILEDB_ENCRYPTION_TYPE_ENUM(NO_ENCRYPTION) = 0, /** AES-256-GCM encryption. */ TILEDB_ENCRYPTION_TYPE_ENUM(AES_256_GCM) = 1, #endif +// clang-format on #ifdef TILEDB_QUERY_STATUS_ENUM /** Query failed */ diff --git a/tiledb/sm/c_api/tiledb_experimental.h b/tiledb/sm/c_api/tiledb_experimental.h index c95ee75d1be..0817c6deb71 100644 --- a/tiledb/sm/c_api/tiledb_experimental.h +++ b/tiledb/sm/c_api/tiledb_experimental.h @@ -5,8 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2017-2021 TileDB, Inc. - * @copyright Copyright (c) 2016 MIT and Intel Corporation + * @copyright Copyright (c) 2017-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 @@ -41,6 +40,7 @@ /* * API sections */ +#include "tiledb/api/c_api/array_schema/array_schema_api_experimental.h" #include "tiledb/api/c_api/attribute/attribute_api_external_experimental.h" #include "tiledb/api/c_api/current_domain/current_domain_api_external_experimental.h" #include "tiledb/api/c_api/enumeration/enumeration_api_experimental.h" @@ -339,110 +339,6 @@ TILEDB_EXPORT capi_return_t tiledb_array_schema_evolution_expand_current_domain( tiledb_array_schema_evolution_t* array_schema_evolution, tiledb_current_domain_t* expanded_domain) TILEDB_NOEXCEPT; -/* ********************************* */ -/* ARRAY SCHEMA */ -/* ********************************* */ - -/** - * Gets timestamp range in an array schema evolution - * - * **Example:** - * - * @code{.c} - * uint64_t timestamp_lo = 0; - * uint64_t timestamp_hi = 0; - * tiledb_array_schema_evolution_timestamp_range(ctx, - * array_schema_evolution, ×tamp_lo, ×tamp_hi); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema object. - * @param lo The lower bound of timestamp range. - * @param hi The upper bound of timestamp range. - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_timestamp_range( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - uint64_t* lo, - uint64_t* hi) TILEDB_NOEXCEPT; - -/** - * Adds an enumeration to an array schema. - * - * **Example:** - * - * @code{.c} - * tiledb_enumeration_t* enumeration; - * tiledb_enumeration_alloc( - * ctx, - * "enumeration_name", - * TILEDB_INT64, - * 1, - * FALSE, - * data, - * data_size, - * nullptr, - * 0, - * &enumeration); - * tiledb_array_schema_add_enumeration(ctx, array_schema, enumeration); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param enumeration The enumeration to add with the attribute - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_add_enumeration( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_enumeration_t* enumeration) TILEDB_NOEXCEPT; - -/** - * Sets the current domain on the array schema - * - * **Example:** - * - * @code{.c} - * tiledb_current_domain_t *current_domain; - * tiledb_current_domain_create(ctx, ¤t_domain); - * tiledb_array_schema_set_current_domain(ctx, array_schema, current_domain); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param current_domain The current domain to set on the schema - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_set_current_domain( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_current_domain_t* current_domain) TILEDB_NOEXCEPT; - -/** - * Gets the current domain set on the array schema or - * creates an empty current domain if none was set. - * It is the responsability of the caller to free the resources associated - * with the current domain when the handle isn't needed anymore. - * - * **Example:** - * - * @code{.c} - * tiledb_current_domain_t *current_domain; - * tiledb_array_schema_get_current_domain(ctx, array_schema, ¤t_domain); - * tiledb_current_domain_free(¤t_domain); - * @endcode - * - * @param ctx The TileDB context. - * @param array_schema The array schema. - * @param current_domain The current domain set on the schema - * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. - */ -TILEDB_EXPORT int32_t tiledb_array_schema_get_current_domain( - tiledb_ctx_t* ctx, - tiledb_array_schema_t* array_schema, - tiledb_current_domain_t** current_domain) TILEDB_NOEXCEPT; - /* ********************************* */ /* ARRAY */ /* ********************************* */ diff --git a/tiledb/sm/c_api/tiledb_filestore.cc b/tiledb/sm/c_api/tiledb_filestore.cc index 13c513af4c8..f0a67ce6d9a 100644 --- a/tiledb/sm/c_api/tiledb_filestore.cc +++ b/tiledb/sm/c_api/tiledb_filestore.cc @@ -31,6 +31,7 @@ * This file defines the C API of TileDB for filestore. **/ +#include "tiledb/api/c_api/array_schema/array_schema_api_internal.h" #include "tiledb/api/c_api/attribute/attribute_api_internal.h" #include "tiledb/api/c_api/config/config_api_internal.h" #include "tiledb/api/c_api/dimension/dimension_api_internal.h" @@ -111,7 +112,6 @@ int32_t tiledb_filestore_schema_create( } } - *array_schema = new tiledb_array_schema_t; try { // Share ownership of the internal ArraySchema ptr // All other calls for adding domains, attributes, etc @@ -119,9 +119,8 @@ int32_t tiledb_filestore_schema_create( // the cpp objects constructed here auto memory_tracker = context.resources().create_memory_tracker(); memory_tracker->set_type(sm::MemoryTrackerType::ARRAY_CREATE); - (*array_schema)->array_schema_ = make_shared( - HERE(), tiledb::sm::ArrayType::DENSE, memory_tracker); - auto& schema = (*array_schema)->array_schema_; + *array_schema = tiledb_array_schema_t::make_handle( + tiledb::sm::ArrayType::DENSE, memory_tracker); // Define the range of the dimension. uint64_t range_lo = 0; @@ -160,13 +159,14 @@ int32_t tiledb_filestore_schema_create( attr->set_filter_pipeline(filter); } - throw_if_not_ok(schema->set_domain(domain)); - throw_if_not_ok(schema->set_tile_order(tiledb::sm::Layout::ROW_MAJOR)); - throw_if_not_ok(schema->set_cell_order(tiledb::sm::Layout::ROW_MAJOR)); - throw_if_not_ok(schema->add_attribute(attr)); + throw_if_not_ok((*array_schema)->set_domain(domain)); + throw_if_not_ok( + (*array_schema)->set_tile_order(tiledb::sm::Layout::ROW_MAJOR)); + throw_if_not_ok( + (*array_schema)->set_cell_order(tiledb::sm::Layout::ROW_MAJOR)); + throw_if_not_ok((*array_schema)->add_attribute(attr)); } catch (const std::exception& e) { - (*array_schema)->array_schema_ = nullptr; - delete *array_schema; + tiledb_array_schema_t::break_handle(*array_schema); throw api::CAPIStatusException( std::string("Internal TileDB uncaught exception; ") + e.what()); } diff --git a/tiledb/sm/c_api/tiledb_struct_def.h b/tiledb/sm/c_api/tiledb_struct_def.h index b11364bda1c..d9d75575609 100644 --- a/tiledb/sm/c_api/tiledb_struct_def.h +++ b/tiledb/sm/c_api/tiledb_struct_def.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2017-2021 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 @@ -59,10 +59,6 @@ struct tiledb_subarray_t { bool is_allocated_ = false; }; -struct tiledb_array_schema_t { - shared_ptr array_schema_; -}; - struct tiledb_array_schema_evolution_t { tiledb::sm::ArraySchemaEvolution* array_schema_evolution_ = nullptr; }; diff --git a/tiledb/sm/enums/array_type.h b/tiledb/sm/enums/array_type.h index 33e3b7c1957..4ce78e3bb1b 100644 --- a/tiledb/sm/enums/array_type.h +++ b/tiledb/sm/enums/array_type.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2017-2021 TileDB, Inc. + * @copyright Copyright (c) 2017-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 @@ -39,13 +39,12 @@ #include "tiledb/common/status.h" #include "tiledb/sm/misc/constants.h" -namespace tiledb { -namespace sm { +namespace tiledb::sm { /** Defines the array type. */ enum class ArrayType : uint8_t { #define TILEDB_ARRAY_TYPE_ENUM(id) id -#include "tiledb/sm/c_api/tiledb_enum.h" +#include "tiledb/api/c_api/array_schema/array_type_enum.h" #undef TILEDB_ARRAY_TYPE_ENUM }; @@ -83,7 +82,6 @@ inline void ensure_array_type_is_valid(uint8_t array_type_enum) { } } -} // namespace sm -} // namespace tiledb +} // namespace tiledb::sm #endif // TILEDB_ARRAY_TYPE_H diff --git a/tiledb/sm/enums/layout.h b/tiledb/sm/enums/layout.h index 796519184a2..4f52af2b5d3 100644 --- a/tiledb/sm/enums/layout.h +++ b/tiledb/sm/enums/layout.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2017-2021 TileDB, Inc. + * @copyright Copyright (c) 2017-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 @@ -41,13 +41,12 @@ using namespace tiledb::common; -namespace tiledb { -namespace sm { +namespace tiledb::sm { /** Defines a layout for the cell or tile order. */ enum class Layout : uint8_t { #define TILEDB_LAYOUT_ENUM(id) id -#include "tiledb/sm/c_api/tiledb_enum.h" +#include "tiledb/api/c_api/array_schema/layout_enum.h" #undef TILEDB_LAYOUT_ENUM }; @@ -101,7 +100,6 @@ inline void ensure_cell_order_is_valid(uint8_t layout_enum) { "[Cell order] Invalid Layout enum " + std::to_string(layout_enum)); } -} // namespace sm -} // namespace tiledb +} // namespace tiledb::sm #endif // TILEDB_LAYOUT_H