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 test for dropping a fixed attribute and adding it back as var-sized #2083

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Changes from 2 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
55 changes: 55 additions & 0 deletions tiledb/tests/test_schema_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,58 @@ 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)

original_data = np.arange(1, 11)
with tiledb.open(uri, "w") as A:
A[:] = {"a": original_data, "b": original_data}

se = tiledb.ArraySchemaEvolution(ctx)
se.drop_attribute("a")
se.array_evolve(uri)

# check schema after dropping attribute
with tiledb.open(uri) as A:
assert not A.schema.has_attr("a")
assert A.schema.attr("b").dtype == np.int32

se = tiledb.ArraySchemaEvolution(ctx)
newattr = tiledb.Attr("a", dtype="S", var=True)
se.add_attribute(newattr)
se.array_evolve(uri)

# check schema after adding attribute back as a var-sized attribute
with tiledb.open(uri) as A:
assert A.schema.has_attr("a")
assert A.schema.attr("a").dtype == "S"
assert A.schema.attr("b").dtype == np.int32

# add new data to the array
new_data = np.array(
["tiledb-string-n.{}".format(i) for i in range(1, 11)], dtype="S"
)
with tiledb.open(uri, "w") as A:
A[:] = {"a": new_data, "b": original_data}
kounelisagis marked this conversation as resolved.
Show resolved Hide resolved

# check data for both attributes
with tiledb.open(uri) as A:
res = A[:]
assert_array_equal(res["a"], new_data)
assert_array_equal(res["b"], original_data)
Loading