From f99b7deb078e49f9219453a6d8d8af2b30c38667 Mon Sep 17 00:00:00 2001 From: jayceslesar Date: Sun, 15 Jun 2025 11:27:27 -0400 Subject: [PATCH] maint: use `URI` constant instead of 'uri' strings --- pyiceberg/catalog/__init__.py | 2 +- pyiceberg/catalog/hive.py | 5 +++-- pyiceberg/catalog/memory.py | 5 +++-- pyiceberg/catalog/sql.py | 3 ++- pyiceberg/cli/console.py | 4 ++-- pyiceberg/io/fsspec.py | 4 ++-- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pyiceberg/catalog/__init__.py b/pyiceberg/catalog/__init__.py index 81d3a34eaa..4da116434e 100644 --- a/pyiceberg/catalog/__init__.py +++ b/pyiceberg/catalog/__init__.py @@ -195,7 +195,7 @@ def infer_catalog_type(name: str, catalog_properties: RecursiveDict) -> Optional Raises: ValueError: Raises a ValueError in case properties are missing, or the wrong type. """ - if uri := catalog_properties.get("uri"): + if uri := catalog_properties.get(URI): if isinstance(uri, str): if uri.startswith("http"): return CatalogType.REST diff --git a/pyiceberg/catalog/hive.py b/pyiceberg/catalog/hive.py index 54e5100e95..05dd408fc2 100644 --- a/pyiceberg/catalog/hive.py +++ b/pyiceberg/catalog/hive.py @@ -63,6 +63,7 @@ LOCATION, METADATA_LOCATION, TABLE_TYPE, + URI, MetastoreCatalog, PropertiesUpdateSummary, ) @@ -307,7 +308,7 @@ def __init__(self, name: str, **properties: str): @staticmethod def _create_hive_client(properties: Dict[str, str]) -> _HiveClient: last_exception = None - for uri in properties["uri"].split(","): + for uri in properties[URI].split(","): try: return _HiveClient( uri, @@ -319,7 +320,7 @@ def _create_hive_client(properties: Dict[str, str]) -> _HiveClient: if last_exception is not None: raise last_exception else: - raise ValueError(f"Unable to connect to hive using uri: {properties['uri']}") + raise ValueError(f"Unable to connect to hive using uri: {properties[URI]}") def _convert_hive_into_iceberg(self, table: HiveTable) -> Table: properties: Dict[str, str] = table.parameters diff --git a/pyiceberg/catalog/memory.py b/pyiceberg/catalog/memory.py index 7d6053baaf..024d14fba6 100644 --- a/pyiceberg/catalog/memory.py +++ b/pyiceberg/catalog/memory.py @@ -15,6 +15,7 @@ # specific language governing permissions and limitations # under the License. +from pyiceberg.catalog import URI from pyiceberg.catalog.sql import SqlCatalog @@ -27,6 +28,6 @@ class InMemoryCatalog(SqlCatalog): def __init__(self, name: str, warehouse: str = "file:///tmp/iceberg/warehouse", **kwargs: str) -> None: self._warehouse_location = warehouse - if "uri" not in kwargs: - kwargs["uri"] = "sqlite:///:memory:" + if URI not in kwargs: + kwargs[URI] = "sqlite:///:memory:" super().__init__(name=name, warehouse=warehouse, **kwargs) diff --git a/pyiceberg/catalog/sql.py b/pyiceberg/catalog/sql.py index b4b06e3a46..880a4db481 100644 --- a/pyiceberg/catalog/sql.py +++ b/pyiceberg/catalog/sql.py @@ -44,6 +44,7 @@ from pyiceberg.catalog import ( METADATA_LOCATION, + URI, Catalog, MetastoreCatalog, PropertiesUpdateSummary, @@ -119,7 +120,7 @@ class SqlCatalog(MetastoreCatalog): def __init__(self, name: str, **properties: str): super().__init__(name, **properties) - if not (uri_prop := self.properties.get("uri")): + if not (uri_prop := self.properties.get(URI)): raise NoSuchPropertyException("SQL connection URI is required") echo_str = str(self.properties.get("echo", DEFAULT_ECHO_VALUE)).lower() diff --git a/pyiceberg/cli/console.py b/pyiceberg/cli/console.py index 25a536d2a6..6be4df12cc 100644 --- a/pyiceberg/cli/console.py +++ b/pyiceberg/cli/console.py @@ -29,7 +29,7 @@ from click import Context from pyiceberg import __version__ -from pyiceberg.catalog import Catalog, load_catalog +from pyiceberg.catalog import URI, Catalog, load_catalog from pyiceberg.cli.output import ConsoleOutput, JsonOutput, Output from pyiceberg.exceptions import NoSuchNamespaceError, NoSuchPropertyException, NoSuchTableError from pyiceberg.table import TableProperties @@ -75,7 +75,7 @@ def run( if ugi: properties["ugi"] = ugi if uri: - properties["uri"] = uri + properties[URI] = uri if credential: properties["credential"] = credential diff --git a/pyiceberg/io/fsspec.py b/pyiceberg/io/fsspec.py index cc80725d14..6febff0ae6 100644 --- a/pyiceberg/io/fsspec.py +++ b/pyiceberg/io/fsspec.py @@ -36,7 +36,7 @@ from fsspec.implementations.local import LocalFileSystem from requests import HTTPError -from pyiceberg.catalog import TOKEN +from pyiceberg.catalog import TOKEN, URI from pyiceberg.exceptions import SignError from pyiceberg.io import ( ADLS_ACCOUNT_HOST, @@ -91,7 +91,7 @@ def s3v4_rest_signer(properties: Properties, request: "AWSRequest", **_: Any) -> "AWSRequest": - signer_url = properties.get(S3_SIGNER_URI, properties["uri"]).rstrip("/") # type: ignore + signer_url = properties.get(S3_SIGNER_URI, properties[URI]).rstrip("/") # type: ignore signer_endpoint = properties.get(S3_SIGNER_ENDPOINT, S3_SIGNER_ENDPOINT_DEFAULT) signer_headers = {}