Skip to content

Commit 8a0a6da

Browse files
committed
can override table location
1 parent be70212 commit 8a0a6da

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

pyiceberg/catalog/memory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def create_table(
6767
if namespace not in self.__namespaces:
6868
self.__namespaces[namespace] = {}
6969

70-
# if not location:
71-
location = f'{self._warehouse_location}/{"/".join(identifier)}'
70+
if not location:
71+
location = f'{self._warehouse_location}/{"/".join(identifier)}'
7272

7373
# _get_default_warehouse_location
7474
metadata_location = f'{self._warehouse_location}/{"/".join(identifier)}/metadata/metadata.json'

tests/catalog/test_base.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def given_catalog_has_a_table(catalog: InMemoryCatalog) -> Table:
7676
return catalog.create_table(
7777
identifier=TEST_TABLE_IDENTIFIER,
7878
schema=TEST_TABLE_SCHEMA,
79-
location=TEST_TABLE_LOCATION,
8079
partition_spec=TEST_TABLE_PARTITION_SPEC,
8180
properties=TEST_TABLE_PROPERTIES,
8281
)
@@ -119,6 +118,16 @@ def test_name_from_str() -> None:
119118

120119

121120
def test_create_table(catalog: InMemoryCatalog) -> None:
121+
table = catalog.create_table(
122+
identifier=TEST_TABLE_IDENTIFIER,
123+
schema=TEST_TABLE_SCHEMA,
124+
partition_spec=TEST_TABLE_PARTITION_SPEC,
125+
properties=TEST_TABLE_PROPERTIES,
126+
)
127+
assert catalog.load_table(TEST_TABLE_IDENTIFIER) == table
128+
129+
130+
def test_create_table_override(catalog: InMemoryCatalog) -> None:
122131
table = catalog.create_table(
123132
identifier=TEST_TABLE_IDENTIFIER,
124133
schema=TEST_TABLE_SCHEMA,

tests/cli/test_console.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ def test_location(catalog: InMemoryCatalog) -> None:
264264
catalog.create_table(
265265
identifier=TEST_TABLE_IDENTIFIER,
266266
schema=TEST_TABLE_SCHEMA,
267-
location=TEST_TABLE_LOCATION,
268267
partition_spec=TEST_TABLE_PARTITION_SPEC,
269268
)
270269

@@ -274,6 +273,20 @@ def test_location(catalog: InMemoryCatalog) -> None:
274273
assert result.output == f"""{DEFAULT_WAREHOUSE_LOCATION}/default/my_table\n"""
275274

276275

276+
def test_location_override(catalog: InMemoryCatalog) -> None:
277+
catalog.create_table(
278+
identifier=TEST_TABLE_IDENTIFIER,
279+
schema=TEST_TABLE_SCHEMA,
280+
location=TEST_TABLE_LOCATION,
281+
partition_spec=TEST_TABLE_PARTITION_SPEC,
282+
)
283+
284+
runner = CliRunner()
285+
result = runner.invoke(run, ["location", "default.my_table"])
286+
assert result.exit_code == 0
287+
assert result.output == f"""{TEST_TABLE_LOCATION}\n"""
288+
289+
277290
def test_location_does_not_exists(catalog: InMemoryCatalog) -> None:
278291
# pylint: disable=unused-argument
279292

@@ -674,7 +687,6 @@ def test_json_location(catalog: InMemoryCatalog) -> None:
674687
catalog.create_table(
675688
identifier=TEST_TABLE_IDENTIFIER,
676689
schema=TEST_TABLE_SCHEMA,
677-
location=TEST_TABLE_LOCATION,
678690
partition_spec=TEST_TABLE_PARTITION_SPEC,
679691
)
680692

@@ -684,6 +696,20 @@ def test_json_location(catalog: InMemoryCatalog) -> None:
684696
assert result.output == f'"{DEFAULT_WAREHOUSE_LOCATION}/default/my_table"\n'
685697

686698

699+
def test_json_location_override(catalog: InMemoryCatalog) -> None:
700+
catalog.create_table(
701+
identifier=TEST_TABLE_IDENTIFIER,
702+
schema=TEST_TABLE_SCHEMA,
703+
location=TEST_TABLE_LOCATION,
704+
partition_spec=TEST_TABLE_PARTITION_SPEC,
705+
)
706+
707+
runner = CliRunner()
708+
result = runner.invoke(run, ["--output=json", "location", "default.my_table"])
709+
assert result.exit_code == 0
710+
assert result.output == f'"{TEST_TABLE_LOCATION}"\n'
711+
712+
687713
def test_json_location_does_not_exists(catalog: InMemoryCatalog) -> None:
688714
# pylint: disable=unused-argument
689715

0 commit comments

Comments
 (0)