Skip to content

Commit 9f28fe4

Browse files
committed
dry
1 parent f393c38 commit 9f28fe4

4 files changed

Lines changed: 20 additions & 37 deletions

File tree

pyiceberg/catalog/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ def _resolve_table_location(self, location: Optional[str], database_name: str, t
923923
return location.rstrip("/")
924924

925925
def _get_default_warehouse_location(self, database_name: str, table_name: str) -> str:
926+
"""Return the default warehouse location using the convention of `warehousePath/databaseName/tableName`."""
926927
database_properties = self.load_namespace_properties(database_name)
927928
if database_location := database_properties.get(LOCATION):
928929
database_location = database_location.rstrip("/")
@@ -934,6 +935,19 @@ def _get_default_warehouse_location(self, database_name: str, table_name: str) -
934935

935936
raise ValueError("No default path is set, please specify a location when creating a table")
936937

938+
def _get_hive_style_warehouse_location(self, database_name: str, table_name: str) -> str:
939+
"""Return the default warehouse location following the Hive convention of `warehousePath/databaseName.db/tableName`."""
940+
database_properties = self.load_namespace_properties(database_name)
941+
if database_location := database_properties.get(LOCATION):
942+
database_location = database_location.rstrip("/")
943+
return f"{database_location}/{table_name}"
944+
945+
if warehouse_path := self.properties.get(WAREHOUSE_LOCATION):
946+
warehouse_path = warehouse_path.rstrip("/")
947+
return f"{warehouse_path}/{database_name}.db/{table_name}"
948+
949+
raise ValueError("No default path is set, please specify a location when creating a table")
950+
937951
@staticmethod
938952
def _write_metadata(metadata: TableMetadata, io: FileIO, metadata_path: str) -> None:
939953
ToOutputFile.table_metadata(metadata, io.new_output(metadata_path))

pyiceberg/catalog/dynamodb.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@
3232
from pyiceberg.catalog import (
3333
BOTOCORE_SESSION,
3434
ICEBERG,
35-
LOCATION,
3635
METADATA_LOCATION,
3736
PREVIOUS_METADATA_LOCATION,
3837
TABLE_TYPE,
39-
WAREHOUSE_LOCATION,
4038
MetastoreCatalog,
4139
PropertiesUpdateSummary,
4240
)
@@ -655,17 +653,8 @@ def _convert_dynamo_table_item_to_iceberg_table(self, dynamo_table_item: Dict[st
655653
)
656654

657655
def _get_default_warehouse_location(self, database_name: str, table_name: str) -> str:
658-
"""Return the default warehouse location following the Hive convention of `warehousePath/databaseName.db/tableName`."""
659-
database_properties = self.load_namespace_properties(database_name)
660-
if database_location := database_properties.get(LOCATION):
661-
database_location = database_location.rstrip("/")
662-
return f"{database_location}/{table_name}"
663-
664-
if warehouse_path := self.properties.get(WAREHOUSE_LOCATION):
665-
warehouse_path = warehouse_path.rstrip("/")
666-
return f"{warehouse_path}/{database_name}.db/{table_name}"
667-
668-
raise ValueError("No default path is set, please specify a location when creating a table")
656+
"""Override the default warehouse location to follow Hive-style conventions."""
657+
return self._get_hive_style_warehouse_location(database_name, table_name)
669658

670659

671660
def _get_create_table_item(database_name: str, table_name: str, properties: Properties, metadata_location: str) -> Dict[str, Any]:

pyiceberg/catalog/glue.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
METADATA_LOCATION,
4949
PREVIOUS_METADATA_LOCATION,
5050
TABLE_TYPE,
51-
WAREHOUSE_LOCATION,
5251
MetastoreCatalog,
5352
PropertiesUpdateSummary,
5453
)
@@ -811,14 +810,5 @@ def __is_iceberg_table(table: TableTypeDef) -> bool:
811810
return table.get("Parameters", {}).get(TABLE_TYPE, "").lower() == ICEBERG
812811

813812
def _get_default_warehouse_location(self, database_name: str, table_name: str) -> str:
814-
"""Return the default warehouse location following the Hive convention of `warehousePath/databaseName.db/tableName`."""
815-
database_properties = self.load_namespace_properties(database_name)
816-
if database_location := database_properties.get(LOCATION):
817-
database_location = database_location.rstrip("/")
818-
return f"{database_location}/{table_name}"
819-
820-
if warehouse_path := self.properties.get(WAREHOUSE_LOCATION):
821-
warehouse_path = warehouse_path.rstrip("/")
822-
return f"{warehouse_path}/{database_name}.db/{table_name}"
823-
824-
raise ValueError("No default path is set, please specify a location when creating a table")
813+
"""Override the default warehouse location to follow Hive-style conventions."""
814+
return self._get_hive_style_warehouse_location(database_name, table_name)

pyiceberg/catalog/hive.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
LOCATION,
6464
METADATA_LOCATION,
6565
TABLE_TYPE,
66-
WAREHOUSE_LOCATION,
6766
MetastoreCatalog,
6867
PropertiesUpdateSummary,
6968
)
@@ -793,14 +792,5 @@ def drop_view(self, identifier: Union[str, Identifier]) -> None:
793792
raise NotImplementedError
794793

795794
def _get_default_warehouse_location(self, database_name: str, table_name: str) -> str:
796-
"""Return the default warehouse location following the Hive convention of `warehousePath/databaseName.db/tableName`."""
797-
database_properties = self.load_namespace_properties(database_name)
798-
if database_location := database_properties.get(LOCATION):
799-
database_location = database_location.rstrip("/")
800-
return f"{database_location}/{table_name}"
801-
802-
if warehouse_path := self.properties.get(WAREHOUSE_LOCATION):
803-
warehouse_path = warehouse_path.rstrip("/")
804-
return f"{warehouse_path}/{database_name}.db/{table_name}"
805-
806-
raise ValueError("No default path is set, please specify a location when creating a table")
795+
"""Override the default warehouse location to follow Hive-style conventions."""
796+
return self._get_hive_style_warehouse_location(database_name, table_name)

0 commit comments

Comments
 (0)