From 0b1c7705772499e3db9a84f61ca7919ee7470c10 Mon Sep 17 00:00:00 2001 From: Agisilaos Kounelis Date: Wed, 16 Oct 2024 13:04:45 +0300 Subject: [PATCH] Add test for dropping a fixed attribute and adding it back as var-sized --- tiledb/tests/test_schema_evolution.py | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tiledb/tests/test_schema_evolution.py b/tiledb/tests/test_schema_evolution.py index 5110e8ab1e..42aadaca85 100644 --- a/tiledb/tests/test_schema_evolution.py +++ b/tiledb/tests/test_schema_evolution.py @@ -227,3 +227,39 @@ def test_schema_evolution_extend_check_bad_type(): with pytest.raises(tiledb.TileDBError): enmr.extend([1, 2, 3]) enmr.extend([True, False]) + + +@pytest.mark.skipif( + tiledb.libtiledb.version() < (2, 27), + reason="Dropping a fixed-sized attribute and adding it back" + "as a var-sized attribute is not supported in TileDB < 2.27", +) +def test_schema_evolution_drop_fixed_attribute_and_add_back_as_var_sized(tmp_path): + ctx = tiledb.default_ctx() + uri = str(tmp_path) + attrs = [ + tiledb.Attr(name="a", dtype=np.int32), + tiledb.Attr(name="b", dtype=np.int32), + ] + dims = [tiledb.Dim(domain=(1, 10), dtype=np.int32)] + domain = tiledb.Domain(*dims) + schema = tiledb.ArraySchema(domain=domain, attrs=attrs, sparse=False) + tiledb.Array.create(uri, schema) + + data = np.arange(1, 11) + with tiledb.open(uri, "w") as A: + A[:] = {"a": data, "b": data} + + se = tiledb.ArraySchemaEvolution(ctx) + se.drop_attribute("a") + se.array_evolve(uri) + + se = tiledb.ArraySchemaEvolution(ctx) + newattr = tiledb.Attr("a", dtype="S0", var=True) + se.add_attribute(newattr) + se.array_evolve(uri) + + with tiledb.open(uri) as A: + res = A[:] + assert_array_equal(res["a"], data) + assert_array_equal(res["b"], data)