Skip to content

Commit

Permalink
Additional testing of TILEDB_GEOM_* types. (#4692)
Browse files Browse the repository at this point in the history
TYPE: NO_HISTORY
  • Loading branch information
bekadavis9 authored Feb 5, 2024
1 parent 404f89f commit 00edc26
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 36 deletions.
70 changes: 45 additions & 25 deletions test/src/test-cppapi-aggregates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1624,31 +1624,6 @@ TEMPLATE_LIST_TEST_CASE_METHOD(
array.close();
}

typedef tuple<std::byte> BlobTypeUnderTest;
TEMPLATE_LIST_TEST_CASE_METHOD(
CppAggregatesFx,
"C++ API: Aggregates basic sum, std::byte",
"[cppapi][aggregates][basic][sum][byte]",
BlobTypeUnderTest) {
typedef TestType T;
CppAggregatesFx<T>::generate_test_params();
CppAggregatesFx<T>::create_array_and_write_fragments();
Array array{
CppAggregatesFx<T>::ctx_, CppAggregatesFx<T>::ARRAY_NAME, TILEDB_READ};
Query query(CppAggregatesFx<T>::ctx_, array, TILEDB_READ);

// Add a sum aggregator to the query.
QueryChannel default_channel = QueryExperimental::get_default_channel(query);

REQUIRE_THROWS_WITH(
QueryExperimental::create_unary_aggregate<SumOperator>(query, "a1"),
Catch::Matchers::ContainsSubstring(
"Datatype::BLOB is not a valid Datatype"));

// Close array.
array.close();
}

typedef tuple<
uint8_t,
uint16_t,
Expand Down Expand Up @@ -2664,3 +2639,48 @@ TEST_CASE_METHOD(
QueryExperimental::create_unary_aggregate<SumOperator>(query, "a1"));
CHECK_THROWS(default_channel.apply_aggregate("Something", operation));
}

typedef tuple<std::byte> BlobTypeUnderTest;
TEMPLATE_LIST_TEST_CASE(
"C++ API: Aggregates basic sum, std::byte",
"[cppapi][aggregates][basic][sum][byte]",
BlobTypeUnderTest) {
const std::string array_name = "test_byte_aggregates";
auto datatype = GENERATE(
tiledb_datatype_t::TILEDB_BLOB,
tiledb_datatype_t::TILEDB_GEOM_WKB,
tiledb_datatype_t::TILEDB_GEOM_WKT);

Context ctx;
VFS vfs(ctx);
if (vfs.is_dir(array_name)) {
vfs.remove_dir(array_name);
}

// Create domain.
Domain domain(ctx);
auto d = Dimension::create<uint64_t>(ctx, "d", {{1, 999}}, 2);
domain.add_dimension(d);

// Create array schema.
ArraySchema schema(ctx, TILEDB_SPARSE);
schema.set_domain(domain);
schema.add_attribute(Attribute::create(ctx, "a", datatype));

// Create array and query.
Array::create(array_name, schema);
Array array(ctx, array_name, TILEDB_READ);
Query query(ctx, array, TILEDB_READ);

// Add a sum aggregator to the query.
QueryChannel default_channel = QueryExperimental::get_default_channel(query);
REQUIRE_THROWS_WITH(
QueryExperimental::create_unary_aggregate<SumOperator>(query, "a"),
Catch::Matchers::ContainsSubstring("not a valid Datatype"));

// Clean up.
array.close();
if (vfs.is_dir(array_name)) {
vfs.remove_dir(array_name);
}
}
87 changes: 81 additions & 6 deletions test/src/unit-capi-attributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,30 +302,25 @@ TEST_CASE_METHOD(
for (const auto& fs : fs_vec_) {
std::string temp_dir = fs->temp_dir();
std::string array_name = temp_dir;
std::string attr_name = "a";
// serialization is not supported for memfs arrays
if (serialize_ &&
tiledb::sm::utils::parse::starts_with(array_name, "mem://")) {
continue;
}

std::string attr_name = "a";

// Create new TileDB context with file lock config disabled, rest the
// same.
tiledb_ctx_free(&ctx_);
tiledb_vfs_free(&vfs_);

tiledb_config_t* config = nullptr;
tiledb_error_t* error = nullptr;
REQUIRE(tiledb_config_alloc(&config, &error) == TILEDB_OK);
REQUIRE(error == nullptr);

REQUIRE(vfs_test_init(fs_vec_, &ctx_, &vfs_, config).ok());

tiledb_config_free(&config);

create_temp_dir(temp_dir);

create_dense_vector(array_name, attr_name, datatype);

// Prepare cell buffers
Expand Down Expand Up @@ -366,12 +361,92 @@ TEST_CASE_METHOD(
tiledb_array_free(&array);
tiledb_query_free(&query);

uint64_t ts_open = 0;
if (datatype == TILEDB_BLOB) {
// For the BLOB datatype, test with and without schema evolution.
auto evolve = GENERATE(true, false);
if (evolve) {
// Ensure the BLOB type can evolve to both GEOM types.
auto new_type = GENERATE(TILEDB_GEOM_WKB, TILEDB_GEOM_WKT);
// Add a second attribute on the schema and drop the original.
tiledb_array_schema_evolution_t* schema_evolution;
rc = tiledb_array_schema_evolution_alloc(ctx_, &schema_evolution);
REQUIRE(rc == TILEDB_OK);
tiledb_attribute_t* b;
rc = tiledb_attribute_alloc(ctx_, "b", TILEDB_BLOB, &b);
REQUIRE(rc == TILEDB_OK);
rc = tiledb_array_schema_evolution_add_attribute(
ctx_, schema_evolution, b);
REQUIRE(rc == TILEDB_OK);
rc = tiledb_array_schema_evolution_drop_attribute(
ctx_, schema_evolution, attr_name.c_str());
REQUIRE(rc == TILEDB_OK);
// Set timestamp to avoid race condition
ts_open = tiledb_timestamp_now_ms();
ts_open = ts_open + 1;
rc = tiledb_array_schema_evolution_set_timestamp_range(
ctx_, schema_evolution, ts_open, ts_open);
rc = tiledb_array_evolve(ctx_, array_name.c_str(), schema_evolution);
REQUIRE(rc == TILEDB_OK);

// Add back the original attribute as new_type and drop "b".
tiledb_array_schema_evolution_t* schema_evolution2;
rc = tiledb_array_schema_evolution_alloc(ctx_, &schema_evolution2);
REQUIRE(rc == TILEDB_OK);
tiledb_attribute_t* attr;
rc = tiledb_attribute_alloc(ctx_, attr_name.c_str(), new_type, &attr);
REQUIRE(rc == TILEDB_OK);
rc = tiledb_array_schema_evolution_add_attribute(
ctx_, schema_evolution2, attr);
REQUIRE(rc == TILEDB_OK);
rc = tiledb_array_schema_evolution_drop_attribute(
ctx_, schema_evolution2, "b");
REQUIRE(rc == TILEDB_OK);
// Set timestamp to avoid race condition
ts_open = tiledb_timestamp_now_ms();
ts_open = ts_open + 2;
rc = tiledb_array_schema_evolution_set_timestamp_range(
ctx_, schema_evolution2, ts_open, ts_open);
if (serialize_) {
// Serialize the array schema evolution
tiledb_buffer_t* buffer;
rc = tiledb_serialize_array_schema_evolution(
ctx_,
schema_evolution2,
(tiledb_serialization_type_t)tiledb::sm::SerializationType::CAPNP,
0,
&buffer);
REQUIRE(rc == TILEDB_OK);
rc = tiledb_deserialize_array_schema_evolution(
ctx_,
buffer,
(tiledb_serialization_type_t)tiledb::sm::SerializationType::CAPNP,
1,
&schema_evolution2);
REQUIRE(rc == TILEDB_OK);
tiledb_buffer_free(&buffer);
}
rc = tiledb_array_evolve(ctx_, array_name.c_str(), schema_evolution2);
REQUIRE(rc == TILEDB_OK);

// Clean up
tiledb_attribute_free(&b);
tiledb_attribute_free(&attr);
tiledb_array_schema_evolution_free(&schema_evolution);
tiledb_array_schema_evolution_free(&schema_evolution2);
}
}

int buffer_read[10];
uint64_t buffer_read_size = sizeof(buffer_read);

// Open array
rc = tiledb_array_alloc(ctx_, array_name.c_str(), &array);
CHECK(rc == TILEDB_OK);
if (ts_open != 0) {
rc = tiledb_array_set_open_timestamp_end(ctx_, array, ts_open + 2);
REQUIRE(rc == TILEDB_OK);
}
rc = tiledb_array_open(ctx_, array, TILEDB_READ);
CHECK(rc == TILEDB_OK);

Expand Down
15 changes: 10 additions & 5 deletions test/src/unit-cppapi-array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* The MIT License
*
* @copyright Copyright (c) 2017-2023 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
Expand Down Expand Up @@ -1210,20 +1210,25 @@ TEST_CASE(
vfs.remove_dir(array_name);
}

auto datatype = GENERATE(
tiledb_datatype_t::TILEDB_BLOB,
tiledb_datatype_t::TILEDB_GEOM_WKB,
tiledb_datatype_t::TILEDB_GEOM_WKT);

// Create
Domain domain(ctx);
domain.add_dimension(Dimension::create<int>(ctx, "rows", {{0, 0}}, 1));
ArraySchema schema(ctx, TILEDB_DENSE);
schema.set_domain(domain).set_order({{TILEDB_ROW_MAJOR, TILEDB_ROW_MAJOR}});
schema.add_attribute(
Attribute::create(ctx, "a", tiledb_datatype_t::TILEDB_BLOB));
schema.add_attribute(Attribute::create(ctx, "a", datatype));
Array::create(array_name, schema);

// Write
std::byte data_w{1};
Array array_w(ctx, array_name, TILEDB_WRITE);
Query query_w(ctx, array_w);
query_w.set_layout(TILEDB_GLOBAL_ORDER).set_data_buffer("a", &data_w, 1);
query_w.set_layout(TILEDB_GLOBAL_ORDER)
.set_data_buffer("a", (void*)(&data_w), 1);

SECTION("no serialization") {
serialize = false;
Expand Down Expand Up @@ -1255,7 +1260,7 @@ TEST_CASE(
std::byte data;
query.set_layout(TILEDB_ROW_MAJOR)
.set_subarray(subarray)
.set_data_buffer("a", &data, 1);
.set_data_buffer("a", (void*)(&data), 1);
query.submit();
array.close();

Expand Down

0 comments on commit 00edc26

Please sign in to comment.