diff --git a/test/src/unit-cppapi-schema-evolution.cc b/test/src/unit-cppapi-schema-evolution.cc index 370adac1518..07bcd729385 100644 --- a/test/src/unit-cppapi-schema-evolution.cc +++ b/test/src/unit-cppapi-schema-evolution.cc @@ -46,10 +46,11 @@ #include +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")}; @@ -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")}; @@ -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()}; @@ -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( @@ -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(ctx, "d", {{1, 10}}, 1); + domain.add_dimension(d); + auto a = Attribute::create(ctx, "a"); + auto b = Attribute::create(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 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(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 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]") {