Skip to content

Commit e05c5f3

Browse files
jayceslesaramitgilad3
authored andcommitted
maint: use URI constant instead of 'uri' strings (apache#2094)
1 parent 10ed707 commit e05c5f3

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

pyiceberg/catalog/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def infer_catalog_type(name: str, catalog_properties: RecursiveDict) -> Optional
195195
Raises:
196196
ValueError: Raises a ValueError in case properties are missing, or the wrong type.
197197
"""
198-
if uri := catalog_properties.get("uri"):
198+
if uri := catalog_properties.get(URI):
199199
if isinstance(uri, str):
200200
if uri.startswith("http"):
201201
return CatalogType.REST

pyiceberg/catalog/hive.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
LOCATION,
6464
METADATA_LOCATION,
6565
TABLE_TYPE,
66+
URI,
6667
MetastoreCatalog,
6768
PropertiesUpdateSummary,
6869
)
@@ -307,7 +308,7 @@ def __init__(self, name: str, **properties: str):
307308
@staticmethod
308309
def _create_hive_client(properties: Dict[str, str]) -> _HiveClient:
309310
last_exception = None
310-
for uri in properties["uri"].split(","):
311+
for uri in properties[URI].split(","):
311312
try:
312313
return _HiveClient(
313314
uri,
@@ -319,7 +320,7 @@ def _create_hive_client(properties: Dict[str, str]) -> _HiveClient:
319320
if last_exception is not None:
320321
raise last_exception
321322
else:
322-
raise ValueError(f"Unable to connect to hive using uri: {properties['uri']}")
323+
raise ValueError(f"Unable to connect to hive using uri: {properties[URI]}")
323324

324325
def _convert_hive_into_iceberg(self, table: HiveTable) -> Table:
325326
properties: Dict[str, str] = table.parameters

pyiceberg/catalog/memory.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from pyiceberg.catalog import URI
1819
from pyiceberg.catalog.sql import SqlCatalog
1920

2021

@@ -27,6 +28,6 @@ class InMemoryCatalog(SqlCatalog):
2728

2829
def __init__(self, name: str, warehouse: str = "file:///tmp/iceberg/warehouse", **kwargs: str) -> None:
2930
self._warehouse_location = warehouse
30-
if "uri" not in kwargs:
31-
kwargs["uri"] = "sqlite:///:memory:"
31+
if URI not in kwargs:
32+
kwargs[URI] = "sqlite:///:memory:"
3233
super().__init__(name=name, warehouse=warehouse, **kwargs)

pyiceberg/catalog/sql.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
from pyiceberg.catalog import (
4646
METADATA_LOCATION,
47+
URI,
4748
Catalog,
4849
MetastoreCatalog,
4950
PropertiesUpdateSummary,
@@ -119,7 +120,7 @@ class SqlCatalog(MetastoreCatalog):
119120
def __init__(self, name: str, **properties: str):
120121
super().__init__(name, **properties)
121122

122-
if not (uri_prop := self.properties.get("uri")):
123+
if not (uri_prop := self.properties.get(URI)):
123124
raise NoSuchPropertyException("SQL connection URI is required")
124125

125126
echo_str = str(self.properties.get("echo", DEFAULT_ECHO_VALUE)).lower()

pyiceberg/cli/console.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from click import Context
3030

3131
from pyiceberg import __version__
32-
from pyiceberg.catalog import Catalog, load_catalog
32+
from pyiceberg.catalog import URI, Catalog, load_catalog
3333
from pyiceberg.cli.output import ConsoleOutput, JsonOutput, Output
3434
from pyiceberg.exceptions import NoSuchNamespaceError, NoSuchPropertyException, NoSuchTableError
3535
from pyiceberg.table import TableProperties
@@ -75,7 +75,7 @@ def run(
7575
if ugi:
7676
properties["ugi"] = ugi
7777
if uri:
78-
properties["uri"] = uri
78+
properties[URI] = uri
7979
if credential:
8080
properties["credential"] = credential
8181

pyiceberg/io/fsspec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from fsspec.implementations.local import LocalFileSystem
3737
from requests import HTTPError
3838

39-
from pyiceberg.catalog import TOKEN
39+
from pyiceberg.catalog import TOKEN, URI
4040
from pyiceberg.exceptions import SignError
4141
from pyiceberg.io import (
4242
ADLS_ACCOUNT_HOST,
@@ -91,7 +91,7 @@
9191

9292

9393
def s3v4_rest_signer(properties: Properties, request: "AWSRequest", **_: Any) -> "AWSRequest":
94-
signer_url = properties.get(S3_SIGNER_URI, properties["uri"]).rstrip("/") # type: ignore
94+
signer_url = properties.get(S3_SIGNER_URI, properties[URI]).rstrip("/") # type: ignore
9595
signer_endpoint = properties.get(S3_SIGNER_ENDPOINT, S3_SIGNER_ENDPOINT_DEFAULT)
9696

9797
signer_headers = {}

0 commit comments

Comments
 (0)