|
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | 17 | import pytest |
| 18 | +from sqlalchemy import Connection, inspect |
18 | 19 |
|
19 | 20 | from pyiceberg.catalog import Catalog |
20 | 21 | from pyiceberg.exceptions import NoSuchTableError, TableAlreadyExistsError |
21 | 22 | from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionSpec |
22 | 23 | from pyiceberg.schema import Schema |
23 | 24 | from pyiceberg.table import Table |
24 | | -from pyiceberg.types import ( |
25 | | - BooleanType, |
26 | | - DateType, |
27 | | - IntegerType, |
28 | | - NestedField, |
29 | | - StringType, |
30 | | -) |
| 25 | +from pyiceberg.types import BooleanType, DateType, IntegerType, NestedField, StringType |
31 | 26 |
|
32 | 27 | TABLE_SCHEMA = Schema( |
33 | 28 | NestedField(field_id=1, name="foo", field_type=BooleanType(), required=False), |
@@ -86,3 +81,35 @@ def test_register_table_existing( |
86 | 81 | # Assert that registering the table again raises TableAlreadyExistsError |
87 | 82 | with pytest.raises(TableAlreadyExistsError): |
88 | 83 | catalog.register_table(("default", "register_table_existing"), metadata_location=tbl.metadata_location) |
| 84 | + |
| 85 | + |
| 86 | +@pytest.mark.integration_trino |
| 87 | +@pytest.mark.integration |
| 88 | +@pytest.mark.parametrize( |
| 89 | + "catalog, trino_conn", |
| 90 | + [ |
| 91 | + (pytest.lazy_fixture("session_catalog_hive"), pytest.lazy_fixture("trino_hive_conn")), |
| 92 | + (pytest.lazy_fixture("session_catalog"), pytest.lazy_fixture("trino_rest_conn")), |
| 93 | + ], |
| 94 | +) |
| 95 | +def test_register_table_existing_in_trino( |
| 96 | + catalog: Catalog, |
| 97 | + trino_conn: Connection, |
| 98 | +) -> None: |
| 99 | + """Test the registration of a table in the catalog that already exists in Trino. |
| 100 | + This test verifies that a table can be registered in the catalog with an existing |
| 101 | + metadata location and properly reflected in Trino. |
| 102 | + """ |
| 103 | + namespace = "default" |
| 104 | + table_name = "register_table_trino" |
| 105 | + identifier = f"{namespace}.{table_name}" |
| 106 | + location = f"s3a://warehouse/{namespace}/{table_name}" |
| 107 | + tbl = _create_table(catalog, identifier, 2, location) |
| 108 | + assert catalog.table_exists(identifier=identifier) |
| 109 | + assert table_name in inspect(trino_conn).get_table_names(schema=namespace) |
| 110 | + catalog.drop_table(identifier=identifier) |
| 111 | + assert not catalog.table_exists(identifier=identifier) |
| 112 | + assert table_name not in inspect(trino_conn).get_table_names(schema=namespace) |
| 113 | + catalog.register_table((namespace, table_name), metadata_location=tbl.metadata_location) |
| 114 | + assert catalog.table_exists(identifier=identifier) |
| 115 | + assert table_name in inspect(trino_conn).get_table_names(schema=namespace) |
0 commit comments