Skip to content

Commit

Permalink
Wrap tiledb_array_consolidate_fragments from pybind11 (#1948)
Browse files Browse the repository at this point in the history
* Wrap tiledb_array_consolidate_fragments from pybind11

* Add test
  • Loading branch information
kounelisagis authored Apr 18, 2024
1 parent d4cb13d commit 410a88a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tiledb/cc/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ void init_array(py::module &m) {
// TODO non_empty_domain_var

.def("query_type", &Array::query_type)
.def("consolidate_fragments",
[](Array &self, const Context &ctx,
const std::vector<std::string> &fragment_uris, Config *config) {
std::vector<const char *> c_strings;
c_strings.reserve(fragment_uris.size());
for (const auto &str : fragment_uris) {
c_strings.push_back(str.c_str());
}
ctx.handle_error(tiledb_array_consolidate_fragments(
ctx.ptr().get(), self.uri().c_str(), c_strings.data(),
fragment_uris.size(), config->ptr().get()));
})
.def("consolidate_metadata",
py::overload_cast<const Context &, const std::string &,
tiledb_encryption_type_t, const std::string &,
Expand Down
33 changes: 33 additions & 0 deletions tiledb/tests/cc/test_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tiledb
import tiledb.cc as lt
from tiledb.datatypes import DataType
from tiledb.main import PyFragmentInfo


def test_config():
Expand Down Expand Up @@ -160,6 +161,38 @@ def test_array():
arr.close()


def test_consolidate_fragments():
uri = tempfile.mkdtemp()
ctx = lt.Context()
config = lt.Config()

tiledb.from_numpy(uri, np.random.rand(4)).close()

with tiledb.open(uri, "w") as A:
A[:] = np.random.rand(4)

with tiledb.open(uri, "w") as A:
A[:] = np.random.rand(4)

schema = tiledb.ArraySchema.load(uri, ctx=ctx)
fragment_info = PyFragmentInfo(uri, schema, False, ctx)

assert fragment_info.get_num_fragments() == 3

uris = fragment_info.get_uri()
# get fragment name form alone, not the full path(s) (the part of each uri after the last /)
# https://github.com/TileDB-Inc/TileDB-Py/pull/1946
uris = [uri.split("/")[-1] for uri in uris]

arr = lt.Array(ctx, uri, lt.QueryType.WRITE)
arr.consolidate_fragments(ctx, uris, config)
arr.close()

fragment_info = PyFragmentInfo(uri, schema, False, ctx)
# Fragmentinfo doesn't see the consolidated range
assert fragment_info.get_num_fragments() == 1


def test_array_config():
uri = tempfile.mkdtemp()

Expand Down

0 comments on commit 410a88a

Please sign in to comment.