Skip to content

Commit 28d6072

Browse files
committed
Move the integration test for HiveCatalog.list_views to the common suite
1 parent 664ee3b commit 28d6072

2 files changed

Lines changed: 56 additions & 55 deletions

File tree

tests/integration/test_catalog.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
# under the License.
1717

1818
import os
19+
import time
1920
import uuid
2021
from collections.abc import Generator
2122
from pathlib import Path, PosixPath
2223
from typing import Any
2324

2425
import pytest
26+
from pyspark.sql import SparkSession
2527
from pytest_lazy_fixtures import lf
2628

2729
from pyiceberg.catalog import Catalog, MetastoreCatalog, load_catalog
@@ -917,3 +919,57 @@ def test_load_missing_table(test_catalog: Catalog, database_name: str, table_nam
917919

918920
with pytest.raises(NoSuchTableError):
919921
test_catalog.load_table(identifier)
922+
923+
924+
@pytest.mark.integration
925+
def test_list_views(
926+
session_catalog_hive: HiveCatalog,
927+
spark: SparkSession,
928+
) -> None:
929+
"""
930+
Verify that a view created by Spark through the Iceberg Hive catalog
931+
can be discovered by PyIceberg HiveCatalog.list_views().
932+
933+
The test also verifies that:
934+
- Iceberg tables are not returned as views.
935+
- Multiple views are returned.
936+
- Returned identifiers use the expected (namespace, view_name) format.
937+
"""
938+
suffix = int(time.time())
939+
catalog_name = "hive"
940+
namespace = "default"
941+
table_name = f"table_{suffix}"
942+
first_view_name = f"first_view_{suffix}"
943+
second_view_name = f"second_view_{suffix}"
944+
table_identifier = f"{catalog_name}.{namespace}.{table_name}"
945+
first_view_identifier = f"{catalog_name}.{namespace}.{first_view_name}"
946+
second_view_identifier = f"{catalog_name}.{namespace}.{second_view_name}"
947+
948+
spark.sql(f"""
949+
CREATE TABLE {table_identifier} (
950+
id INTEGER,
951+
name STRING,
952+
dt DATE
953+
)
954+
USING iceberg
955+
""")
956+
957+
spark.sql(f"""
958+
CREATE VIEW {first_view_identifier} AS
959+
SELECT id, name
960+
FROM {table_identifier}
961+
""")
962+
963+
spark.sql(f"""
964+
CREATE VIEW {second_view_identifier} AS
965+
SELECT id, name, dt
966+
FROM {table_identifier}
967+
""")
968+
969+
views = set(session_catalog_hive.list_views(namespace))
970+
971+
assert (namespace, first_view_name) in views
972+
assert (namespace, second_view_name) in views
973+
974+
# A table in the same namespace must not be returned as a view.
975+
assert (namespace, table_name) not in views

tests/integration/test_hive_migration.py

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from pyspark.sql import SparkSession
2222

2323
from pyiceberg.catalog import Catalog
24-
from pyiceberg.catalog.hive import HiveCatalog
2524

2625

2726
@pytest.mark.integration
@@ -82,57 +81,3 @@ def test_migrate_table(
8281
assert tbl.scan(row_filter="dt == '2023-01-01'").to_arrow().column(0).combine_chunks().tolist() == [4, 5, 6]
8382
assert tbl.scan(row_filter="dt == '2022-01-01'").to_arrow().column(0).combine_chunks().tolist() == [1, 2, 3]
8483
assert tbl.scan(row_filter="dt < '2022-02-01'").to_arrow().column(0).combine_chunks().tolist() == [1, 2, 3]
85-
86-
87-
@pytest.mark.integration
88-
def test_list_views(
89-
session_catalog_hive: HiveCatalog,
90-
spark: SparkSession,
91-
) -> None:
92-
"""
93-
Verify that a view created by Spark through the Iceberg Hive catalog
94-
can be discovered by PyIceberg HiveCatalog.list_views().
95-
96-
The test also verifies that:
97-
- Iceberg tables are not returned as views.
98-
- Multiple views are returned.
99-
- Returned identifiers use the expected (namespace, view_name) format.
100-
"""
101-
suffix = int(time.time())
102-
catalog_name = "hive"
103-
namespace = "default"
104-
table_name = f"table_{suffix}"
105-
first_view_name = f"first_view_{suffix}"
106-
second_view_name = f"second_view_{suffix}"
107-
table_identifier = f"{catalog_name}.{namespace}.{table_name}"
108-
first_view_identifier = f"{catalog_name}.{namespace}.{first_view_name}"
109-
second_view_identifier = f"{catalog_name}.{namespace}.{second_view_name}"
110-
111-
spark.sql(f"""
112-
CREATE TABLE {table_identifier} (
113-
id INTEGER,
114-
name STRING,
115-
dt DATE
116-
)
117-
USING iceberg
118-
""")
119-
120-
spark.sql(f"""
121-
CREATE VIEW {first_view_identifier} AS
122-
SELECT id, name
123-
FROM {table_identifier}
124-
""")
125-
126-
spark.sql(f"""
127-
CREATE VIEW {second_view_identifier} AS
128-
SELECT id, name, dt
129-
FROM {table_identifier}
130-
""")
131-
132-
views = set(session_catalog_hive.list_views(namespace))
133-
134-
assert (namespace, first_view_name) in views
135-
assert (namespace, second_view_name) in views
136-
137-
# A table in the same namespace must not be returned as a view.
138-
assert (namespace, table_name) not in views

0 commit comments

Comments
 (0)