|
20 | 20 |
|
21 | 21 | import pytest |
22 | 22 |
|
23 | | -from pyiceberg.catalog import Catalog |
| 23 | +from pyiceberg.catalog import Catalog, MetastoreCatalog |
24 | 24 | from pyiceberg.catalog.dynamodb import DynamoDbCatalog |
25 | 25 | from pyiceberg.catalog.glue import GLUE_CATALOG_ENDPOINT, GlueCatalog |
26 | 26 | from pyiceberg.catalog.hive import HiveCatalog |
27 | 27 | from pyiceberg.catalog.memory import InMemoryCatalog |
28 | 28 | from pyiceberg.catalog.rest import RestCatalog |
29 | 29 | from pyiceberg.catalog.sql import SqlCatalog |
30 | 30 | from pyiceberg.io import WAREHOUSE |
| 31 | +from pyiceberg.schema import Schema |
31 | 32 | from tests.conftest import clean_up, get_bucket_name, get_glue_endpoint, get_s3_path |
32 | 33 |
|
33 | | -# The number of tables/databases used in list_table/namespace test |
34 | | -LIST_TEST_NUMBER = 2 |
35 | | - |
36 | 34 |
|
37 | 35 | @pytest.fixture(scope="function") |
38 | 36 | def dynamodb() -> Generator[Catalog, None, None]: |
@@ -117,3 +115,49 @@ def test_create_namespace( |
117 | 115 | test_catalog.create_namespace(database_name) |
118 | 116 | # note the use of `in` because some catalogs have a "default" namespace |
119 | 117 | assert (database_name,) in test_catalog.list_namespaces() |
| 118 | + |
| 119 | + |
| 120 | +@pytest.mark.integration |
| 121 | +@pytest.mark.parametrize( |
| 122 | + "test_catalog", |
| 123 | + [ |
| 124 | + pytest.lazy_fixture("glue"), |
| 125 | + pytest.lazy_fixture("dynamodb"), |
| 126 | + pytest.lazy_fixture("memory_catalog"), |
| 127 | + pytest.lazy_fixture("sqlite_catalog_memory"), |
| 128 | + pytest.lazy_fixture("sqlite_catalog_file"), |
| 129 | + pytest.lazy_fixture("rest_catalog"), |
| 130 | + pytest.lazy_fixture("hive_catalog"), |
| 131 | + ], |
| 132 | +) |
| 133 | +def test_create_table_with_default_location( |
| 134 | + test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str |
| 135 | +) -> None: |
| 136 | + identifier = (database_name, table_name) |
| 137 | + test_catalog.create_namespace(database_name) |
| 138 | + test_catalog.create_table(identifier, table_schema_nested) |
| 139 | + table = test_catalog.load_table(identifier) |
| 140 | + assert table.name() == identifier |
| 141 | + assert MetastoreCatalog._parse_metadata_version(table.metadata_location) == 0 |
| 142 | + |
| 143 | + |
| 144 | +@pytest.mark.integration |
| 145 | +@pytest.mark.parametrize( |
| 146 | + "test_catalog", |
| 147 | + [ |
| 148 | + pytest.lazy_fixture("glue"), |
| 149 | + pytest.lazy_fixture("dynamodb"), |
| 150 | + pytest.lazy_fixture("memory_catalog"), |
| 151 | + pytest.lazy_fixture("sqlite_catalog_memory"), |
| 152 | + pytest.lazy_fixture("sqlite_catalog_file"), |
| 153 | + pytest.lazy_fixture("rest_catalog"), |
| 154 | + pytest.lazy_fixture("hive_catalog"), |
| 155 | + ], |
| 156 | +) |
| 157 | +def test_create_table_with_invalid_location( |
| 158 | + test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str |
| 159 | +) -> None: |
| 160 | + identifier = (database_name, table_name) |
| 161 | + test_catalog.create_namespace(database_name) |
| 162 | + with pytest.raises(ValueError): |
| 163 | + test_catalog.create_table(identifier, table_schema_nested) |
0 commit comments