|
1 | 1 | import os
|
| 2 | +import pathlib |
2 | 3 |
|
3 | 4 | import numpy as np
|
4 | 5 | import pytest
|
@@ -265,6 +266,82 @@ def test_group_named_members(self):
|
265 | 266 | assert len(grp) == 0
|
266 | 267 | grp.close()
|
267 | 268 |
|
| 269 | + def test_pass_context(self): |
| 270 | + foo = self.path("foo") |
| 271 | + bar = self.path("foo/bar") |
| 272 | + |
| 273 | + tiledb.group_create(foo) |
| 274 | + tiledb.group_create(bar) |
| 275 | + |
| 276 | + ctx = tiledb.Ctx() |
| 277 | + with tiledb.Group(foo, mode="w", ctx=ctx) as G: |
| 278 | + G.add(bar, name="bar") |
| 279 | + |
| 280 | + with tiledb.Group(foo, mode="r", ctx=ctx) as G: |
| 281 | + assert "bar" in G |
| 282 | + |
| 283 | + def test_relative(self): |
| 284 | + group1 = self.path("group1") |
| 285 | + group2_1 = self.path("group1/group2_1") |
| 286 | + group2_2 = self.path("group1/group2_2") |
| 287 | + |
| 288 | + tiledb.group_create(group2_1) |
| 289 | + tiledb.group_create(group2_2) |
| 290 | + |
| 291 | + with tiledb.Group(group1, mode="w") as G: |
| 292 | + G.add(group2_1, name="group2_1", relative=False) |
| 293 | + G.add("group2_2", name="group2_2", relative=True) |
| 294 | + |
| 295 | + with tiledb.Group(group1, mode="r") as G: |
| 296 | + assert G.is_relative("group2_1") is False |
| 297 | + assert G.is_relative("group2_2") is True |
| 298 | + |
| 299 | + def test_set_config(self): |
| 300 | + group_uri = self.path("foo") |
| 301 | + array_uri_1 = self.path("foo/a") |
| 302 | + array_uri_2 = self.path("foo/b") |
| 303 | + |
| 304 | + tiledb.group_create(group_uri) |
| 305 | + |
| 306 | + dom = tiledb.Domain(tiledb.Dim("id", dtype="ascii")) |
| 307 | + attr = tiledb.Attr("value", dtype=np.int64) |
| 308 | + sch = tiledb.ArraySchema(domain=dom, attrs=(attr,), sparse=True) |
| 309 | + |
| 310 | + tiledb.Array.create(array_uri_1, sch) |
| 311 | + tiledb.Array.create(array_uri_2, sch) |
| 312 | + |
| 313 | + cfg = tiledb.Config({"sm.group.timestamp_end": 2000}) |
| 314 | + with tiledb.Group(group_uri, "w", cfg) as G: |
| 315 | + G.add(name="a", uri="a", relative=True) |
| 316 | + |
| 317 | + cfg = tiledb.Config({"sm.group.timestamp_end": 3000}) |
| 318 | + with tiledb.Group(group_uri, "w", cfg) as G: |
| 319 | + G.add(name="b", uri="b", relative=True) |
| 320 | + |
| 321 | + ms = np.arange(1000, 4000, 1000, dtype=np.int64) |
| 322 | + |
| 323 | + for sz, m in enumerate(ms): |
| 324 | + cfg = tiledb.Config({"sm.group.timestamp_end": m}) |
| 325 | + |
| 326 | + G = tiledb.Group(group_uri) |
| 327 | + |
| 328 | + # Cannot set config on open group |
| 329 | + with self.assertRaises(ValueError): |
| 330 | + G.set_config(cfg) |
| 331 | + |
| 332 | + G.close() |
| 333 | + G.set_config(cfg) |
| 334 | + |
| 335 | + G.open() |
| 336 | + assert len(G) == sz |
| 337 | + G.close() |
| 338 | + |
| 339 | + for sz, m in enumerate(ms): |
| 340 | + cfg = tiledb.Config({"sm.group.timestamp_end": m}) |
| 341 | + |
| 342 | + with tiledb.Group(group_uri, config=cfg) as G: |
| 343 | + assert len(G) == sz |
| 344 | + |
268 | 345 |
|
269 | 346 | class GroupMetadataTest(GroupTestCase):
|
270 | 347 | @pytest.mark.parametrize(
|
@@ -489,78 +566,49 @@ def test_basic(self, test_vals):
|
489 | 566 | self.assert_metadata_roundtrip(grp.meta, test_vals)
|
490 | 567 | grp.close()
|
491 | 568 |
|
492 |
| - def test_pass_context(self): |
493 |
| - foo = self.path("foo") |
494 |
| - bar = self.path("foo/bar") |
495 |
| - |
496 |
| - tiledb.group_create(foo) |
497 |
| - tiledb.group_create(bar) |
498 |
| - |
499 |
| - ctx = tiledb.Ctx() |
500 |
| - with tiledb.Group(foo, mode="w", ctx=ctx) as G: |
501 |
| - G.add(bar, name="bar") |
502 |
| - |
503 |
| - with tiledb.Group(foo, mode="r", ctx=ctx) as G: |
504 |
| - assert "bar" in G |
505 |
| - |
506 |
| - def test_relative(self): |
507 |
| - group1 = self.path("group1") |
508 |
| - group2_1 = self.path("group1/group2_1") |
509 |
| - group2_2 = self.path("group1/group2_2") |
510 |
| - |
511 |
| - tiledb.group_create(group2_1) |
512 |
| - tiledb.group_create(group2_2) |
513 |
| - |
514 |
| - with tiledb.Group(group1, mode="w") as G: |
515 |
| - G.add(group2_1, name="group2_1", relative=False) |
516 |
| - G.add("group2_2", name="group2_2", relative=True) |
517 |
| - |
518 |
| - with tiledb.Group(group1, mode="r") as G: |
519 |
| - assert G.is_relative("group2_1") is False |
520 |
| - assert G.is_relative("group2_2") is True |
521 |
| - |
522 |
| - def test_set_config(self): |
523 |
| - group_uri = self.path("foo") |
524 |
| - array_uri_1 = self.path("foo/a") |
525 |
| - array_uri_2 = self.path("foo/b") |
| 569 | + def test_consolidation_and_vac(self): |
| 570 | + vfs = tiledb.VFS() |
| 571 | + path = self.path("test_consolidation_and_vac") |
| 572 | + tiledb.Group.create(path) |
526 | 573 |
|
527 |
| - tiledb.group_create(group_uri) |
| 574 | + cfg = tiledb.Config({"sm.group.timestamp_end": 1}) |
| 575 | + with tiledb.Group(path, "w", cfg) as grp: |
| 576 | + grp.meta["meta"] = 1 |
528 | 577 |
|
529 |
| - dom = tiledb.Domain(tiledb.Dim("id", dtype="ascii")) |
530 |
| - attr = tiledb.Attr("value", dtype=np.int64) |
531 |
| - sch = tiledb.ArraySchema(domain=dom, attrs=(attr,), sparse=True) |
| 578 | + cfg = tiledb.Config({"sm.group.timestamp_end": 2}) |
| 579 | + with tiledb.Group(path, "w", cfg) as grp: |
| 580 | + grp.meta["meta"] = 2 |
532 | 581 |
|
533 |
| - tiledb.Array.create(array_uri_1, sch) |
534 |
| - tiledb.Array.create(array_uri_2, sch) |
| 582 | + cfg = tiledb.Config({"sm.group.timestamp_end": 3}) |
| 583 | + with tiledb.Group(path, "w", cfg) as grp: |
| 584 | + grp.meta["meta"] = 3 |
535 | 585 |
|
536 |
| - cfg = tiledb.Config({"sm.group.timestamp_end": 2000}) |
537 |
| - with tiledb.Group(group_uri, "w", cfg) as G: |
538 |
| - G.add(name="a", uri="a", relative=True) |
| 586 | + meta_path = pathlib.Path(path) / "__meta" |
| 587 | + assert len(vfs.ls(meta_path)) == 3 |
539 | 588 |
|
540 |
| - cfg = tiledb.Config({"sm.group.timestamp_end": 3000}) |
541 |
| - with tiledb.Group(group_uri, "w", cfg) as G: |
542 |
| - G.add(name="b", uri="b", relative=True) |
| 589 | + tiledb.Group.consolidate_metadata(path, cfg) |
| 590 | + tiledb.Group.vacuum_metadata(path, cfg) |
543 | 591 |
|
544 |
| - ms = np.arange(1000, 4000, 1000, dtype=np.int64) |
| 592 | + assert len(vfs.ls(meta_path)) == 1 |
545 | 593 |
|
546 |
| - for sz, m in enumerate(ms): |
547 |
| - cfg = tiledb.Config({"sm.group.timestamp_end": m}) |
| 594 | + def test_consolidation_and_vac_no_config(self): |
| 595 | + vfs = tiledb.VFS() |
| 596 | + path = self.path("test_consolidation_and_vac") |
| 597 | + tiledb.Group.create(path) |
548 | 598 |
|
549 |
| - G = tiledb.Group(group_uri) |
| 599 | + with tiledb.Group(path, "w") as grp: |
| 600 | + grp.meta["meta"] = 1 |
550 | 601 |
|
551 |
| - # Cannot set config on open group |
552 |
| - with self.assertRaises(ValueError): |
553 |
| - G.set_config(cfg) |
| 602 | + with tiledb.Group(path, "w") as grp: |
| 603 | + grp.meta["meta"] = 2 |
554 | 604 |
|
555 |
| - G.close() |
556 |
| - G.set_config(cfg) |
| 605 | + with tiledb.Group(path, "w") as grp: |
| 606 | + grp.meta["meta"] = 3 |
557 | 607 |
|
558 |
| - G.open() |
559 |
| - assert len(G) == sz |
560 |
| - G.close() |
| 608 | + meta_path = pathlib.Path(path) / "__meta" |
| 609 | + assert len(vfs.ls(meta_path)) == 3 |
561 | 610 |
|
562 |
| - for sz, m in enumerate(ms): |
563 |
| - cfg = tiledb.Config({"sm.group.timestamp_end": m}) |
| 611 | + tiledb.Group.consolidate_metadata(path) |
| 612 | + tiledb.Group.vacuum_metadata(path) |
564 | 613 |
|
565 |
| - with tiledb.Group(group_uri, config=cfg) as G: |
566 |
| - assert len(G) == sz |
| 614 | + assert len(vfs.ls(meta_path)) == 1 |
0 commit comments