Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schema evolution fixed-to-var attribute test. #5304

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 77 additions & 4 deletions test/src/unit-cppapi-schema-evolution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@

#include <limits>

using namespace tiledb;

TEST_CASE(
"C++ API: SchemaEvolution, add and drop attributes",
"[cppapi][schema][evolution][add][drop][rest]") {
using namespace tiledb;
test::VFSTestSetup vfs_test_setup;
Context ctx{vfs_test_setup.ctx()};
auto array_uri{vfs_test_setup.array_uri("test_schema_evolution_array")};
Expand Down Expand Up @@ -101,7 +102,6 @@ TEST_CASE(
TEST_CASE(
"C++ API: SchemaEvolution, check error when dropping dimension",
"[cppapi][schema][evolution][drop][rest]") {
using namespace tiledb;
test::VFSTestSetup vfs_test_setup;
Context ctx{vfs_test_setup.ctx()};
auto array_uri{vfs_test_setup.array_uri("test_schema_evolution_array")};
Expand Down Expand Up @@ -135,7 +135,6 @@ TEST_CASE(
TEST_CASE(
"C++ API: SchemaEvolution, add attributes and read",
"[cppapi][schema][evolution][add][rest]") {
using namespace tiledb;
test::VFSTestSetup vfs_test_setup;
Context ctx{vfs_test_setup.ctx()};

Expand Down Expand Up @@ -669,7 +668,6 @@ TEST_CASE(
TEST_CASE(
"C++ API: SchemaEvolution, add and drop attributes",
"[cppapi][schema][evolution][add][query-condition][rest]") {
using namespace tiledb;
test::VFSTestSetup vfs_test_setup;
Context ctx{vfs_test_setup.ctx()};
auto layout = GENERATE(
Expand Down Expand Up @@ -808,6 +806,81 @@ TEST_CASE(
}
}

TEST_CASE(
"C++ API: SchemaEvolution, drop fixed attribute and add back as var-sized",
"[!mayfail][cppapi][schema][evolution][add][drop]") {
test::VFSTestSetup vfs_test_setup;
Context ctx{vfs_test_setup.ctx()};
auto array_uri{
vfs_test_setup.array_uri("test_schema_evolution_drop_fixed_add_var")};
tiledb_array_type_t array_type = TILEDB_DENSE;
bool allows_dups = false;
auto layout = GENERATE(TILEDB_UNORDERED, TILEDB_GLOBAL_ORDER);

SECTION("sparse") {
array_type = TILEDB_SPARSE;
allows_dups = GENERATE(true, false);
}

// Create array
Domain domain(ctx);
auto d = Dimension::create<int>(ctx, "d", {{1, 10}}, 1);
domain.add_dimension(d);
auto a = Attribute::create<int>(ctx, "a");
auto b = Attribute::create<int>(ctx, "b");
ArraySchema schema(ctx, array_type);
schema.set_domain(domain);
schema.set_allows_dups(allows_dups);
CHECK(allows_dups == schema.allows_dups());
schema.add_attribute(a);
schema.add_attribute(b);
schema.set_cell_order(TILEDB_ROW_MAJOR);
schema.set_tile_order(TILEDB_COL_MAJOR);
Array::create(array_uri, schema);

// Write a fragment to the array
std::vector<int> data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Array array_w(ctx, array_uri, TILEDB_WRITE);
Query query_w(ctx, array_w, TILEDB_WRITE);
query_w.set_layout(TILEDB_GLOBAL_ORDER)
.set_data_buffer("a", data)
.set_data_buffer("b", data);
if (array_type == TILEDB_SPARSE) {
query_w.set_data_buffer("d", data);
}
query_w.submit_and_finalize();
array_w.close();

// Evolve schema to drop attribute "a"
ArraySchemaEvolution schema_evolution = ArraySchemaEvolution(ctx);
uint64_t now = tiledb_timestamp_now_ms() + 1;
schema_evolution.set_timestamp_range(std::make_pair(now, now));
schema_evolution.drop_attribute("a");
schema_evolution.array_evolve(array_uri);
std::this_thread::sleep_for(std::chrono::milliseconds(100));

// Evolve schema to add back attribute "a" as a string
auto a_new = Attribute::create<std::string>(ctx, "a");
now = tiledb_timestamp_now_ms() + 1;
schema_evolution.set_timestamp_range(std::make_pair(now, now));
schema_evolution.add_attribute(a_new);
schema_evolution.array_evolve(array_uri);

// Read the array
std::string buffer;
std::vector<uint64_t> offsets = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Array array_r(ctx, array_uri, TILEDB_READ);
Subarray subarray(ctx, array_r);
subarray.add_range(0, 1, 10);
Query query_r(ctx, array_r, TILEDB_READ);
query_r.set_layout(layout)
.set_subarray(subarray)
.set_data_buffer("a", buffer)
.set_offsets_buffer("a", offsets);
query_r.submit();
array_r.close();
}

TEST_CASE(
"SchemaEvolution Error Handling Tests",
"[cppapi][schema][evolution][errors][rest]") {
Expand Down
Loading