|
| 1 | +/** |
| 2 | + * @file unit-current-domain-rest.cc |
| 3 | + * |
| 4 | + * @section LICENSE |
| 5 | + * |
| 6 | + * The MIT License |
| 7 | + * |
| 8 | + * @copyright Copyright (c) 2024 TileDB Inc. |
| 9 | + * |
| 10 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | + * of this software and associated documentation files (the "Software"), to deal |
| 12 | + * in the Software without restriction, including without limitation the rights |
| 13 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 | + * copies of the Software, and to permit persons to whom the Software is |
| 15 | + * furnished to do so, subject to the following conditions: |
| 16 | + * |
| 17 | + * The above copyright notice and this permission notice shall be included in |
| 18 | + * all copies or substantial portions of the Software. |
| 19 | + * |
| 20 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 26 | + * THE SOFTWARE. |
| 27 | + * |
| 28 | + * @section DESCRIPTION |
| 29 | + * |
| 30 | + * Fuctional test for Current Domain locally and via REST. |
| 31 | + */ |
| 32 | + |
| 33 | +#include "test/support/src/vfs_helpers.h" |
| 34 | +#include "test/support/tdb_catch.h" |
| 35 | +#include "tiledb/sm/c_api/tiledb_struct_def.h" |
| 36 | +#include "tiledb/sm/cpp_api/tiledb" |
| 37 | +#include "tiledb/sm/cpp_api/tiledb_experimental" |
| 38 | + |
| 39 | +using namespace tiledb::test; |
| 40 | + |
| 41 | +struct RestCurrentDomainFx { |
| 42 | + RestCurrentDomainFx(); |
| 43 | + |
| 44 | + void create_sparse_array(const std::string& array_name); |
| 45 | + |
| 46 | + VFSTestSetup vfs_test_setup_; |
| 47 | + |
| 48 | + // TileDB context |
| 49 | + tiledb_ctx_t* ctx_c_; |
| 50 | + std::string uri_; |
| 51 | +}; |
| 52 | + |
| 53 | +RestCurrentDomainFx::RestCurrentDomainFx() |
| 54 | + : ctx_c_(vfs_test_setup_.ctx_c) { |
| 55 | +} |
| 56 | + |
| 57 | +void RestCurrentDomainFx::create_sparse_array(const std::string& array_name) { |
| 58 | + uri_ = vfs_test_setup_.array_uri(array_name); |
| 59 | + |
| 60 | + // Create dimensions |
| 61 | + uint64_t tile_extents[] = {2}; |
| 62 | + uint64_t dim_domain[] = {1, 10}; |
| 63 | + |
| 64 | + tiledb_dimension_t* d1; |
| 65 | + int rc = tiledb_dimension_alloc( |
| 66 | + ctx_c_, "d1", TILEDB_UINT64, &dim_domain[0], &tile_extents[0], &d1); |
| 67 | + CHECK(rc == TILEDB_OK); |
| 68 | + |
| 69 | + tiledb_dimension_t* d2; |
| 70 | + rc = tiledb_dimension_alloc(ctx_c_, "d2", TILEDB_STRING_ASCII, 0, 0, &d2); |
| 71 | + CHECK(rc == TILEDB_OK); |
| 72 | + |
| 73 | + // Create domain |
| 74 | + tiledb_domain_t* domain; |
| 75 | + rc = tiledb_domain_alloc(ctx_c_, &domain); |
| 76 | + CHECK(rc == TILEDB_OK); |
| 77 | + rc = tiledb_domain_add_dimension(ctx_c_, domain, d1); |
| 78 | + CHECK(rc == TILEDB_OK); |
| 79 | + rc = tiledb_domain_add_dimension(ctx_c_, domain, d2); |
| 80 | + CHECK(rc == TILEDB_OK); |
| 81 | + |
| 82 | + // Create attributes |
| 83 | + tiledb_attribute_t* a; |
| 84 | + rc = tiledb_attribute_alloc(ctx_c_, "a", TILEDB_INT32, &a); |
| 85 | + CHECK(rc == TILEDB_OK); |
| 86 | + |
| 87 | + // Create array schema |
| 88 | + tiledb_array_schema_t* array_schema; |
| 89 | + rc = tiledb_array_schema_alloc(ctx_c_, TILEDB_SPARSE, &array_schema); |
| 90 | + CHECK(rc == TILEDB_OK); |
| 91 | + rc = tiledb_array_schema_set_cell_order( |
| 92 | + ctx_c_, array_schema, TILEDB_ROW_MAJOR); |
| 93 | + CHECK(rc == TILEDB_OK); |
| 94 | + rc = tiledb_array_schema_set_tile_order( |
| 95 | + ctx_c_, array_schema, TILEDB_ROW_MAJOR); |
| 96 | + CHECK(rc == TILEDB_OK); |
| 97 | + rc = tiledb_array_schema_set_capacity(ctx_c_, array_schema, 4); |
| 98 | + CHECK(rc == TILEDB_OK); |
| 99 | + rc = tiledb_array_schema_set_domain(ctx_c_, array_schema, domain); |
| 100 | + CHECK(rc == TILEDB_OK); |
| 101 | + rc = tiledb_array_schema_add_attribute(ctx_c_, array_schema, a); |
| 102 | + CHECK(rc == TILEDB_OK); |
| 103 | + |
| 104 | + tiledb_current_domain_t* crd = nullptr; |
| 105 | + REQUIRE(tiledb_current_domain_create(ctx_c_, &crd) == TILEDB_OK); |
| 106 | + tiledb_ndrectangle_t* ndr = nullptr; |
| 107 | + REQUIRE(tiledb_ndrectangle_alloc(ctx_c_, domain, &ndr) == TILEDB_OK); |
| 108 | + |
| 109 | + tiledb_range_t range; |
| 110 | + uint64_t min = 2; |
| 111 | + uint64_t max = 5; |
| 112 | + range.min = &min; |
| 113 | + range.min_size = sizeof(uint64_t); |
| 114 | + range.max = &max; |
| 115 | + range.max_size = sizeof(uint64_t); |
| 116 | + REQUIRE( |
| 117 | + tiledb_ndrectangle_set_range_for_name(ctx_c_, ndr, "d1", &range) == |
| 118 | + TILEDB_OK); |
| 119 | + |
| 120 | + tiledb_range_t range_var; |
| 121 | + std::string min_var("ab"); |
| 122 | + std::string max_var("cd"); |
| 123 | + range_var.min = min_var.data(); |
| 124 | + range_var.min_size = 2; |
| 125 | + range_var.max = max_var.data(); |
| 126 | + range_var.max_size = 2; |
| 127 | + REQUIRE( |
| 128 | + tiledb_ndrectangle_set_range_for_name(ctx_c_, ndr, "d2", &range_var) == |
| 129 | + TILEDB_OK); |
| 130 | + |
| 131 | + REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK); |
| 132 | + REQUIRE( |
| 133 | + tiledb_array_schema_set_current_domain(ctx_c_, array_schema, crd) == |
| 134 | + TILEDB_OK); |
| 135 | + |
| 136 | + // Check array schema |
| 137 | + rc = tiledb_array_schema_check(ctx_c_, array_schema); |
| 138 | + CHECK(rc == TILEDB_OK); |
| 139 | + |
| 140 | + // Create array |
| 141 | + rc = tiledb_array_create(ctx_c_, uri_.c_str(), array_schema); |
| 142 | + CHECK(rc == TILEDB_OK); |
| 143 | + |
| 144 | + // Clean up |
| 145 | + REQUIRE(tiledb_ndrectangle_free(&ndr) == TILEDB_OK); |
| 146 | + REQUIRE(tiledb_current_domain_free(&crd) == TILEDB_OK); |
| 147 | + tiledb_attribute_free(&a); |
| 148 | + tiledb_dimension_free(&d1); |
| 149 | + tiledb_domain_free(&domain); |
| 150 | + tiledb_array_schema_free(&array_schema); |
| 151 | +} |
| 152 | + |
| 153 | +TEST_CASE_METHOD( |
| 154 | + RestCurrentDomainFx, |
| 155 | + "C API: Current Domain basic behavior", |
| 156 | + "[current_domain][rest]") { |
| 157 | + create_sparse_array("currentdomain_array"); |
| 158 | + |
| 159 | + // Open array, read back current domain from schema and check |
| 160 | + tiledb_array_schema_t* schema; |
| 161 | + tiledb_array_t* array; |
| 162 | + tiledb_current_domain_t* crd; |
| 163 | + tiledb_ndrectangle_t* ndr; |
| 164 | + |
| 165 | + REQUIRE(tiledb_array_alloc(ctx_c_, uri_.c_str(), &array) == TILEDB_OK); |
| 166 | + REQUIRE(tiledb_array_open(ctx_c_, array, TILEDB_READ) == TILEDB_OK); |
| 167 | + REQUIRE(tiledb_array_get_schema(ctx_c_, array, &schema) == TILEDB_OK); |
| 168 | + REQUIRE( |
| 169 | + tiledb_array_schema_get_current_domain(ctx_c_, schema, &crd) == |
| 170 | + TILEDB_OK); |
| 171 | + |
| 172 | + REQUIRE(tiledb_current_domain_get_ndrectangle(crd, &ndr) == TILEDB_OK); |
| 173 | + tiledb_range_t outrange; |
| 174 | + tiledb_range_t outrange_var; |
| 175 | + REQUIRE( |
| 176 | + tiledb_ndrectangle_get_range_from_name(ctx_c_, ndr, "d1", &outrange) == |
| 177 | + TILEDB_OK); |
| 178 | + CHECK(*(uint64_t*)outrange.min == 2); |
| 179 | + CHECK(*(uint64_t*)outrange.max == 5); |
| 180 | + CHECK(outrange.min_size == sizeof(uint64_t)); |
| 181 | + CHECK(outrange.max_size == sizeof(uint64_t)); |
| 182 | + |
| 183 | + REQUIRE( |
| 184 | + tiledb_ndrectangle_get_range_from_name( |
| 185 | + ctx_c_, ndr, "d2", &outrange_var) == TILEDB_OK); |
| 186 | + CHECK(std::memcmp(outrange_var.min, "ab", 2) == 0); |
| 187 | + CHECK(std::memcmp(outrange_var.max, "cd", 2) == 0); |
| 188 | + CHECK(outrange_var.min_size == 2); |
| 189 | + CHECK(outrange_var.max_size == 2); |
| 190 | + |
| 191 | + REQUIRE(tiledb_ndrectangle_free(&ndr) == TILEDB_OK); |
| 192 | + REQUIRE(tiledb_current_domain_free(&crd) == TILEDB_OK); |
| 193 | + tiledb_array_schema_free(&schema); |
| 194 | + REQUIRE(tiledb_array_close(ctx_c_, array) == TILEDB_OK); |
| 195 | + tiledb_array_free(&array); |
| 196 | +} |
| 197 | + |
| 198 | +TEST_CASE_METHOD( |
| 199 | + RestCurrentDomainFx, |
| 200 | + "C API: Current Domain basic schema evolution", |
| 201 | + "[current_domain][evolution][rest]") { |
| 202 | + create_sparse_array("currentdomain_array"); |
| 203 | + tiledb_array_t* array; |
| 204 | + tiledb_array_schema_t* schema; |
| 205 | + tiledb_domain_t* domain; |
| 206 | + tiledb_current_domain_t* crd; |
| 207 | + tiledb_ndrectangle_t* ndr; |
| 208 | + |
| 209 | + REQUIRE(tiledb_array_alloc(ctx_c_, uri_.c_str(), &array) == TILEDB_OK); |
| 210 | + REQUIRE(tiledb_array_open(ctx_c_, array, TILEDB_READ) == TILEDB_OK); |
| 211 | + REQUIRE(tiledb_array_get_schema(ctx_c_, array, &schema) == TILEDB_OK); |
| 212 | + REQUIRE(tiledb_array_schema_get_domain(ctx_c_, schema, &domain) == TILEDB_OK); |
| 213 | + |
| 214 | + tiledb_array_schema_evolution_t* evo; |
| 215 | + REQUIRE(tiledb_array_schema_evolution_alloc(ctx_c_, &evo) == TILEDB_OK); |
| 216 | + REQUIRE(tiledb_current_domain_create(ctx_c_, &crd) == TILEDB_OK); |
| 217 | + REQUIRE(tiledb_ndrectangle_alloc(ctx_c_, domain, &ndr) == TILEDB_OK); |
| 218 | + |
| 219 | + tiledb_range_t range; |
| 220 | + uint64_t min = 2; |
| 221 | + uint64_t max = 7; |
| 222 | + range.min = &min; |
| 223 | + range.min_size = sizeof(uint64_t); |
| 224 | + range.max = &max; |
| 225 | + range.max_size = sizeof(uint64_t); |
| 226 | + |
| 227 | + REQUIRE( |
| 228 | + tiledb_ndrectangle_set_range_for_name(ctx_c_, ndr, "d1", &range) == |
| 229 | + TILEDB_OK); |
| 230 | + |
| 231 | + tiledb_range_t range_var; |
| 232 | + std::string min_var("aa"); |
| 233 | + std::string max_var("ce"); |
| 234 | + range_var.min = min_var.data(); |
| 235 | + range_var.min_size = 2; |
| 236 | + range_var.max = max_var.data(); |
| 237 | + range_var.max_size = 2; |
| 238 | + REQUIRE( |
| 239 | + tiledb_ndrectangle_set_range_for_name(ctx_c_, ndr, "d2", &range_var) == |
| 240 | + TILEDB_OK); |
| 241 | + |
| 242 | + REQUIRE(tiledb_current_domain_set_ndrectangle(crd, ndr) == TILEDB_OK); |
| 243 | + REQUIRE( |
| 244 | + tiledb_array_schema_evolution_expand_current_domain(ctx_c_, evo, crd) == |
| 245 | + TILEDB_OK); |
| 246 | + |
| 247 | + REQUIRE(tiledb_array_evolve(ctx_c_, uri_.c_str(), evo) == TILEDB_OK); |
| 248 | + |
| 249 | + REQUIRE(tiledb_ndrectangle_free(&ndr) == TILEDB_OK); |
| 250 | + REQUIRE(tiledb_current_domain_free(&crd) == TILEDB_OK); |
| 251 | + tiledb_array_schema_evolution_free(&evo); |
| 252 | + tiledb_domain_free(&domain); |
| 253 | + tiledb_array_schema_free(&schema); |
| 254 | + REQUIRE(tiledb_array_close(ctx_c_, array) == TILEDB_OK); |
| 255 | + tiledb_array_free(&array); |
| 256 | + |
| 257 | + // Open array, read back current domain from schema and check |
| 258 | + REQUIRE(tiledb_array_alloc(ctx_c_, uri_.c_str(), &array) == TILEDB_OK); |
| 259 | + REQUIRE(tiledb_array_open(ctx_c_, array, TILEDB_READ) == TILEDB_OK); |
| 260 | + REQUIRE(tiledb_array_get_schema(ctx_c_, array, &schema) == TILEDB_OK); |
| 261 | + REQUIRE( |
| 262 | + tiledb_array_schema_get_current_domain(ctx_c_, schema, &crd) == |
| 263 | + TILEDB_OK); |
| 264 | + |
| 265 | + REQUIRE(tiledb_current_domain_get_ndrectangle(crd, &ndr) == TILEDB_OK); |
| 266 | + tiledb_range_t outrange; |
| 267 | + REQUIRE( |
| 268 | + tiledb_ndrectangle_get_range_from_name(ctx_c_, ndr, "d1", &outrange) == |
| 269 | + TILEDB_OK); |
| 270 | + CHECK(*(uint64_t*)outrange.min == 2); |
| 271 | + CHECK(*(uint64_t*)outrange.max == 7); |
| 272 | + CHECK(outrange.min_size == sizeof(uint64_t)); |
| 273 | + CHECK(outrange.max_size == sizeof(uint64_t)); |
| 274 | + |
| 275 | + tiledb_range_t outrange_var; |
| 276 | + REQUIRE( |
| 277 | + tiledb_ndrectangle_get_range_from_name( |
| 278 | + ctx_c_, ndr, "d2", &outrange_var) == TILEDB_OK); |
| 279 | + CHECK(std::memcmp(outrange_var.min, "aa", 2) == 0); |
| 280 | + CHECK(std::memcmp(outrange_var.max, "ce", 2) == 0); |
| 281 | + CHECK(outrange_var.min_size == 2); |
| 282 | + CHECK(outrange_var.max_size == 2); |
| 283 | + |
| 284 | + REQUIRE(tiledb_ndrectangle_free(&ndr) == TILEDB_OK); |
| 285 | + REQUIRE(tiledb_current_domain_free(&crd) == TILEDB_OK); |
| 286 | + tiledb_array_schema_free(&schema); |
| 287 | + REQUIRE(tiledb_array_close(ctx_c_, array) == TILEDB_OK); |
| 288 | + tiledb_array_free(&array); |
| 289 | +} |
0 commit comments