|
19 | 19 | import uuid |
20 | 20 | from collections.abc import Generator |
21 | 21 | from pathlib import Path, PosixPath |
| 22 | +from typing import Any |
22 | 23 |
|
23 | 24 | import pytest |
24 | 25 | from pytest_lazy_fixtures import lf |
|
44 | 45 | from pyiceberg.table.sorting import INITIAL_SORT_ORDER_ID, SortField, SortOrder |
45 | 46 | from pyiceberg.transforms import BucketTransform, DayTransform, IdentityTransform |
46 | 47 | from pyiceberg.types import IntegerType, LongType, NestedField, TimestampType, UUIDType |
| 48 | +from pyiceberg.view import View |
| 49 | +from pyiceberg.view.metadata import ViewMetadata |
47 | 50 | from tests.conftest import ( |
48 | 51 | clean_up, |
49 | 52 | does_support_atomic_concurrent_updates, |
@@ -617,6 +620,55 @@ def test_register_table_existing(test_catalog: Catalog, table_schema_nested: Sch |
617 | 620 | test_catalog.register_table(identifier, metadata_location=table.metadata_location) |
618 | 621 |
|
619 | 622 |
|
| 623 | +@pytest.mark.integration |
| 624 | +def test_rest_list_views( |
| 625 | + rest_catalog: RestCatalog, example_view_metadata_v1: dict[str, Any], database_name: str, view_name: str |
| 626 | +) -> None: |
| 627 | + identifier = (database_name, view_name) |
| 628 | + |
| 629 | + rest_catalog.create_namespace_if_not_exists(database_name) |
| 630 | + view = View(identifier, ViewMetadata.model_validate(example_view_metadata_v1)) |
| 631 | + |
| 632 | + assert identifier not in rest_catalog.list_views(database_name) |
| 633 | + |
| 634 | + rest_catalog.create_view(identifier, view.schema(), view.current_version()) |
| 635 | + |
| 636 | + assert identifier in rest_catalog.list_views(database_name) |
| 637 | + |
| 638 | + |
| 639 | +@pytest.mark.integration |
| 640 | +def test_rest_create_view( |
| 641 | + rest_catalog: RestCatalog, example_view_metadata_v1: dict[str, Any], database_name: str, view_name: str |
| 642 | +) -> None: |
| 643 | + identifier = (database_name, view_name) |
| 644 | + |
| 645 | + rest_catalog.create_namespace_if_not_exists(database_name) |
| 646 | + view = View(identifier, ViewMetadata.model_validate(example_view_metadata_v1)) |
| 647 | + |
| 648 | + assert not rest_catalog.view_exists(identifier) |
| 649 | + |
| 650 | + rest_catalog.create_view(identifier, view.schema(), view.current_version()) |
| 651 | + |
| 652 | + assert rest_catalog.view_exists(identifier) |
| 653 | + assert rest_catalog.load_view(identifier).schema() == view.schema() |
| 654 | + |
| 655 | + |
| 656 | +@pytest.mark.integration |
| 657 | +def test_rest_drop_view( |
| 658 | + rest_catalog: RestCatalog, example_view_metadata_v1: dict[str, Any], database_name: str, view_name: str |
| 659 | +) -> None: |
| 660 | + identifier = (database_name, view_name) |
| 661 | + |
| 662 | + rest_catalog.create_namespace_if_not_exists(database_name) |
| 663 | + view = View(identifier, ViewMetadata.model_validate(example_view_metadata_v1)) |
| 664 | + |
| 665 | + rest_catalog.create_view(identifier, view.schema(), view.current_version()) |
| 666 | + assert rest_catalog.view_exists(identifier) |
| 667 | + |
| 668 | + rest_catalog.drop_view(identifier) |
| 669 | + assert not rest_catalog.view_exists(identifier) |
| 670 | + |
| 671 | + |
620 | 672 | @pytest.mark.integration |
621 | 673 | @pytest.mark.skip(reason="Requires Iceberg REST Fixtures 1.11.x") |
622 | 674 | def test_rest_custom_namespace_separator(rest_catalog: RestCatalog, table_schema_simple: Schema) -> None: |
|
0 commit comments