Skip to content

Commit

Permalink
can override table location
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjqliu committed Jan 22, 2024
1 parent be70212 commit 8a0a6da
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pyiceberg/catalog/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def create_table(
if namespace not in self.__namespaces:
self.__namespaces[namespace] = {}

# if not location:
location = f'{self._warehouse_location}/{"/".join(identifier)}'
if not location:
location = f'{self._warehouse_location}/{"/".join(identifier)}'

# _get_default_warehouse_location
metadata_location = f'{self._warehouse_location}/{"/".join(identifier)}/metadata/metadata.json'
Expand Down
11 changes: 10 additions & 1 deletion tests/catalog/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def given_catalog_has_a_table(catalog: InMemoryCatalog) -> Table:
return catalog.create_table(
identifier=TEST_TABLE_IDENTIFIER,
schema=TEST_TABLE_SCHEMA,
location=TEST_TABLE_LOCATION,
partition_spec=TEST_TABLE_PARTITION_SPEC,
properties=TEST_TABLE_PROPERTIES,
)
Expand Down Expand Up @@ -119,6 +118,16 @@ def test_name_from_str() -> None:


def test_create_table(catalog: InMemoryCatalog) -> None:
table = catalog.create_table(
identifier=TEST_TABLE_IDENTIFIER,
schema=TEST_TABLE_SCHEMA,
partition_spec=TEST_TABLE_PARTITION_SPEC,
properties=TEST_TABLE_PROPERTIES,
)
assert catalog.load_table(TEST_TABLE_IDENTIFIER) == table


def test_create_table_override(catalog: InMemoryCatalog) -> None:
table = catalog.create_table(
identifier=TEST_TABLE_IDENTIFIER,
schema=TEST_TABLE_SCHEMA,
Expand Down
30 changes: 28 additions & 2 deletions tests/cli/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ def test_location(catalog: InMemoryCatalog) -> None:
catalog.create_table(
identifier=TEST_TABLE_IDENTIFIER,
schema=TEST_TABLE_SCHEMA,
location=TEST_TABLE_LOCATION,
partition_spec=TEST_TABLE_PARTITION_SPEC,
)

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


def test_location_override(catalog: InMemoryCatalog) -> None:
catalog.create_table(
identifier=TEST_TABLE_IDENTIFIER,
schema=TEST_TABLE_SCHEMA,
location=TEST_TABLE_LOCATION,
partition_spec=TEST_TABLE_PARTITION_SPEC,
)

runner = CliRunner()
result = runner.invoke(run, ["location", "default.my_table"])
assert result.exit_code == 0
assert result.output == f"""{TEST_TABLE_LOCATION}\n"""


def test_location_does_not_exists(catalog: InMemoryCatalog) -> None:
# pylint: disable=unused-argument

Expand Down Expand Up @@ -674,7 +687,6 @@ def test_json_location(catalog: InMemoryCatalog) -> None:
catalog.create_table(
identifier=TEST_TABLE_IDENTIFIER,
schema=TEST_TABLE_SCHEMA,
location=TEST_TABLE_LOCATION,
partition_spec=TEST_TABLE_PARTITION_SPEC,
)

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


def test_json_location_override(catalog: InMemoryCatalog) -> None:
catalog.create_table(
identifier=TEST_TABLE_IDENTIFIER,
schema=TEST_TABLE_SCHEMA,
location=TEST_TABLE_LOCATION,
partition_spec=TEST_TABLE_PARTITION_SPEC,
)

runner = CliRunner()
result = runner.invoke(run, ["--output=json", "location", "default.my_table"])
assert result.exit_code == 0
assert result.output == f'"{TEST_TABLE_LOCATION}"\n'


def test_json_location_does_not_exists(catalog: InMemoryCatalog) -> None:
# pylint: disable=unused-argument

Expand Down

0 comments on commit 8a0a6da

Please sign in to comment.