Skip to content

Commit 00edc26

Browse files
authored
Additional testing of TILEDB_GEOM_* types. (#4692)
TYPE: NO_HISTORY
1 parent 404f89f commit 00edc26

File tree

3 files changed

+136
-36
lines changed

3 files changed

+136
-36
lines changed

test/src/test-cppapi-aggregates.cc

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,31 +1624,6 @@ TEMPLATE_LIST_TEST_CASE_METHOD(
16241624
array.close();
16251625
}
16261626

1627-
typedef tuple<std::byte> BlobTypeUnderTest;
1628-
TEMPLATE_LIST_TEST_CASE_METHOD(
1629-
CppAggregatesFx,
1630-
"C++ API: Aggregates basic sum, std::byte",
1631-
"[cppapi][aggregates][basic][sum][byte]",
1632-
BlobTypeUnderTest) {
1633-
typedef TestType T;
1634-
CppAggregatesFx<T>::generate_test_params();
1635-
CppAggregatesFx<T>::create_array_and_write_fragments();
1636-
Array array{
1637-
CppAggregatesFx<T>::ctx_, CppAggregatesFx<T>::ARRAY_NAME, TILEDB_READ};
1638-
Query query(CppAggregatesFx<T>::ctx_, array, TILEDB_READ);
1639-
1640-
// Add a sum aggregator to the query.
1641-
QueryChannel default_channel = QueryExperimental::get_default_channel(query);
1642-
1643-
REQUIRE_THROWS_WITH(
1644-
QueryExperimental::create_unary_aggregate<SumOperator>(query, "a1"),
1645-
Catch::Matchers::ContainsSubstring(
1646-
"Datatype::BLOB is not a valid Datatype"));
1647-
1648-
// Close array.
1649-
array.close();
1650-
}
1651-
16521627
typedef tuple<
16531628
uint8_t,
16541629
uint16_t,
@@ -2664,3 +2639,48 @@ TEST_CASE_METHOD(
26642639
QueryExperimental::create_unary_aggregate<SumOperator>(query, "a1"));
26652640
CHECK_THROWS(default_channel.apply_aggregate("Something", operation));
26662641
}
2642+
2643+
typedef tuple<std::byte> BlobTypeUnderTest;
2644+
TEMPLATE_LIST_TEST_CASE(
2645+
"C++ API: Aggregates basic sum, std::byte",
2646+
"[cppapi][aggregates][basic][sum][byte]",
2647+
BlobTypeUnderTest) {
2648+
const std::string array_name = "test_byte_aggregates";
2649+
auto datatype = GENERATE(
2650+
tiledb_datatype_t::TILEDB_BLOB,
2651+
tiledb_datatype_t::TILEDB_GEOM_WKB,
2652+
tiledb_datatype_t::TILEDB_GEOM_WKT);
2653+
2654+
Context ctx;
2655+
VFS vfs(ctx);
2656+
if (vfs.is_dir(array_name)) {
2657+
vfs.remove_dir(array_name);
2658+
}
2659+
2660+
// Create domain.
2661+
Domain domain(ctx);
2662+
auto d = Dimension::create<uint64_t>(ctx, "d", {{1, 999}}, 2);
2663+
domain.add_dimension(d);
2664+
2665+
// Create array schema.
2666+
ArraySchema schema(ctx, TILEDB_SPARSE);
2667+
schema.set_domain(domain);
2668+
schema.add_attribute(Attribute::create(ctx, "a", datatype));
2669+
2670+
// Create array and query.
2671+
Array::create(array_name, schema);
2672+
Array array(ctx, array_name, TILEDB_READ);
2673+
Query query(ctx, array, TILEDB_READ);
2674+
2675+
// Add a sum aggregator to the query.
2676+
QueryChannel default_channel = QueryExperimental::get_default_channel(query);
2677+
REQUIRE_THROWS_WITH(
2678+
QueryExperimental::create_unary_aggregate<SumOperator>(query, "a"),
2679+
Catch::Matchers::ContainsSubstring("not a valid Datatype"));
2680+
2681+
// Clean up.
2682+
array.close();
2683+
if (vfs.is_dir(array_name)) {
2684+
vfs.remove_dir(array_name);
2685+
}
2686+
}

test/src/unit-capi-attributes.cc

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,30 +302,25 @@ TEST_CASE_METHOD(
302302
for (const auto& fs : fs_vec_) {
303303
std::string temp_dir = fs->temp_dir();
304304
std::string array_name = temp_dir;
305+
std::string attr_name = "a";
305306
// serialization is not supported for memfs arrays
306307
if (serialize_ &&
307308
tiledb::sm::utils::parse::starts_with(array_name, "mem://")) {
308309
continue;
309310
}
310311

311-
std::string attr_name = "a";
312-
313312
// Create new TileDB context with file lock config disabled, rest the
314313
// same.
315314
tiledb_ctx_free(&ctx_);
316315
tiledb_vfs_free(&vfs_);
317-
318316
tiledb_config_t* config = nullptr;
319317
tiledb_error_t* error = nullptr;
320318
REQUIRE(tiledb_config_alloc(&config, &error) == TILEDB_OK);
321319
REQUIRE(error == nullptr);
322-
323320
REQUIRE(vfs_test_init(fs_vec_, &ctx_, &vfs_, config).ok());
324-
325321
tiledb_config_free(&config);
326322

327323
create_temp_dir(temp_dir);
328-
329324
create_dense_vector(array_name, attr_name, datatype);
330325

331326
// Prepare cell buffers
@@ -366,12 +361,92 @@ TEST_CASE_METHOD(
366361
tiledb_array_free(&array);
367362
tiledb_query_free(&query);
368363

364+
uint64_t ts_open = 0;
365+
if (datatype == TILEDB_BLOB) {
366+
// For the BLOB datatype, test with and without schema evolution.
367+
auto evolve = GENERATE(true, false);
368+
if (evolve) {
369+
// Ensure the BLOB type can evolve to both GEOM types.
370+
auto new_type = GENERATE(TILEDB_GEOM_WKB, TILEDB_GEOM_WKT);
371+
// Add a second attribute on the schema and drop the original.
372+
tiledb_array_schema_evolution_t* schema_evolution;
373+
rc = tiledb_array_schema_evolution_alloc(ctx_, &schema_evolution);
374+
REQUIRE(rc == TILEDB_OK);
375+
tiledb_attribute_t* b;
376+
rc = tiledb_attribute_alloc(ctx_, "b", TILEDB_BLOB, &b);
377+
REQUIRE(rc == TILEDB_OK);
378+
rc = tiledb_array_schema_evolution_add_attribute(
379+
ctx_, schema_evolution, b);
380+
REQUIRE(rc == TILEDB_OK);
381+
rc = tiledb_array_schema_evolution_drop_attribute(
382+
ctx_, schema_evolution, attr_name.c_str());
383+
REQUIRE(rc == TILEDB_OK);
384+
// Set timestamp to avoid race condition
385+
ts_open = tiledb_timestamp_now_ms();
386+
ts_open = ts_open + 1;
387+
rc = tiledb_array_schema_evolution_set_timestamp_range(
388+
ctx_, schema_evolution, ts_open, ts_open);
389+
rc = tiledb_array_evolve(ctx_, array_name.c_str(), schema_evolution);
390+
REQUIRE(rc == TILEDB_OK);
391+
392+
// Add back the original attribute as new_type and drop "b".
393+
tiledb_array_schema_evolution_t* schema_evolution2;
394+
rc = tiledb_array_schema_evolution_alloc(ctx_, &schema_evolution2);
395+
REQUIRE(rc == TILEDB_OK);
396+
tiledb_attribute_t* attr;
397+
rc = tiledb_attribute_alloc(ctx_, attr_name.c_str(), new_type, &attr);
398+
REQUIRE(rc == TILEDB_OK);
399+
rc = tiledb_array_schema_evolution_add_attribute(
400+
ctx_, schema_evolution2, attr);
401+
REQUIRE(rc == TILEDB_OK);
402+
rc = tiledb_array_schema_evolution_drop_attribute(
403+
ctx_, schema_evolution2, "b");
404+
REQUIRE(rc == TILEDB_OK);
405+
// Set timestamp to avoid race condition
406+
ts_open = tiledb_timestamp_now_ms();
407+
ts_open = ts_open + 2;
408+
rc = tiledb_array_schema_evolution_set_timestamp_range(
409+
ctx_, schema_evolution2, ts_open, ts_open);
410+
if (serialize_) {
411+
// Serialize the array schema evolution
412+
tiledb_buffer_t* buffer;
413+
rc = tiledb_serialize_array_schema_evolution(
414+
ctx_,
415+
schema_evolution2,
416+
(tiledb_serialization_type_t)tiledb::sm::SerializationType::CAPNP,
417+
0,
418+
&buffer);
419+
REQUIRE(rc == TILEDB_OK);
420+
rc = tiledb_deserialize_array_schema_evolution(
421+
ctx_,
422+
buffer,
423+
(tiledb_serialization_type_t)tiledb::sm::SerializationType::CAPNP,
424+
1,
425+
&schema_evolution2);
426+
REQUIRE(rc == TILEDB_OK);
427+
tiledb_buffer_free(&buffer);
428+
}
429+
rc = tiledb_array_evolve(ctx_, array_name.c_str(), schema_evolution2);
430+
REQUIRE(rc == TILEDB_OK);
431+
432+
// Clean up
433+
tiledb_attribute_free(&b);
434+
tiledb_attribute_free(&attr);
435+
tiledb_array_schema_evolution_free(&schema_evolution);
436+
tiledb_array_schema_evolution_free(&schema_evolution2);
437+
}
438+
}
439+
369440
int buffer_read[10];
370441
uint64_t buffer_read_size = sizeof(buffer_read);
371442

372443
// Open array
373444
rc = tiledb_array_alloc(ctx_, array_name.c_str(), &array);
374445
CHECK(rc == TILEDB_OK);
446+
if (ts_open != 0) {
447+
rc = tiledb_array_set_open_timestamp_end(ctx_, array, ts_open + 2);
448+
REQUIRE(rc == TILEDB_OK);
449+
}
375450
rc = tiledb_array_open(ctx_, array, TILEDB_READ);
376451
CHECK(rc == TILEDB_OK);
377452

test/src/unit-cppapi-array.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* The MIT License
77
*
8-
* @copyright Copyright (c) 2017-2023 TileDB Inc.
8+
* @copyright Copyright (c) 2017-2024 TileDB Inc.
99
*
1010
* Permission is hereby granted, free of charge, to any person obtaining a copy
1111
* of this software and associated documentation files (the "Software"), to deal
@@ -1210,20 +1210,25 @@ TEST_CASE(
12101210
vfs.remove_dir(array_name);
12111211
}
12121212

1213+
auto datatype = GENERATE(
1214+
tiledb_datatype_t::TILEDB_BLOB,
1215+
tiledb_datatype_t::TILEDB_GEOM_WKB,
1216+
tiledb_datatype_t::TILEDB_GEOM_WKT);
1217+
12131218
// Create
12141219
Domain domain(ctx);
12151220
domain.add_dimension(Dimension::create<int>(ctx, "rows", {{0, 0}}, 1));
12161221
ArraySchema schema(ctx, TILEDB_DENSE);
12171222
schema.set_domain(domain).set_order({{TILEDB_ROW_MAJOR, TILEDB_ROW_MAJOR}});
1218-
schema.add_attribute(
1219-
Attribute::create(ctx, "a", tiledb_datatype_t::TILEDB_BLOB));
1223+
schema.add_attribute(Attribute::create(ctx, "a", datatype));
12201224
Array::create(array_name, schema);
12211225

12221226
// Write
12231227
std::byte data_w{1};
12241228
Array array_w(ctx, array_name, TILEDB_WRITE);
12251229
Query query_w(ctx, array_w);
1226-
query_w.set_layout(TILEDB_GLOBAL_ORDER).set_data_buffer("a", &data_w, 1);
1230+
query_w.set_layout(TILEDB_GLOBAL_ORDER)
1231+
.set_data_buffer("a", (void*)(&data_w), 1);
12271232

12281233
SECTION("no serialization") {
12291234
serialize = false;
@@ -1255,7 +1260,7 @@ TEST_CASE(
12551260
std::byte data;
12561261
query.set_layout(TILEDB_ROW_MAJOR)
12571262
.set_subarray(subarray)
1258-
.set_data_buffer("a", &data, 1);
1263+
.set_data_buffer("a", (void*)(&data), 1);
12591264
query.submit();
12601265
array.close();
12611266

0 commit comments

Comments
 (0)