From 3a643bbd04bd3feae65202c3b1f8dab86438d7dd Mon Sep 17 00:00:00 2001 From: Anurag Singh Date: Wed, 2 Dec 2026 17:16:44 +0530 Subject: [PATCH 1/2] feat(io): accept the Java ADLS shared-key properties Java configs name the ADLS account and key with adls.auth.shared-key.account.name and adls.auth.shared-key.account.key. Read them as fallbacks for adls.account-name and adls.account-key, so one config works for both clients. --- pyiceberg/io/__init__.py | 2 ++ pyiceberg/io/fsspec.py | 6 ++++-- pyiceberg/io/pyarrow.py | 6 ++++-- tests/io/test_fsspec.py | 14 ++++++++++++++ tests/io/test_pyarrow.py | 31 +++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 4 deletions(-) diff --git a/pyiceberg/io/__init__.py b/pyiceberg/io/__init__.py index cc63530195..71f5f81ffd 100644 --- a/pyiceberg/io/__init__.py +++ b/pyiceberg/io/__init__.py @@ -97,6 +97,8 @@ def _is_local_path(path: str) -> bool: ADLS_CREDENTIAL = "adls.credential" ADLS_ACCOUNT_NAME = "adls.account-name" ADLS_ACCOUNT_KEY = "adls.account-key" +ADLS_SHARED_KEY_ACCOUNT_NAME = "adls.auth.shared-key.account.name" +ADLS_SHARED_KEY_ACCOUNT_KEY = "adls.auth.shared-key.account.key" ADLS_SAS_TOKEN = "adls.sas-token" ADLS_TENANT_ID = "adls.tenant-id" ADLS_CLIENT_ID = "adls.client-id" diff --git a/pyiceberg/io/fsspec.py b/pyiceberg/io/fsspec.py index 505b5eebbf..e61df0d552 100644 --- a/pyiceberg/io/fsspec.py +++ b/pyiceberg/io/fsspec.py @@ -50,6 +50,8 @@ ADLS_CONNECTION_STRING, ADLS_CREDENTIAL, ADLS_SAS_TOKEN, + ADLS_SHARED_KEY_ACCOUNT_KEY, + ADLS_SHARED_KEY_ACCOUNT_NAME, ADLS_TENANT_ID, ADLS_TOKEN, AWS_ACCESS_KEY_ID, @@ -287,7 +289,7 @@ def _adls(properties: Properties, hostname: str | None = None) -> AbstractFileSy from azure.core.credentials import AccessToken from azure.core.credentials_async import AsyncTokenCredential - account_name = properties.get(ADLS_ACCOUNT_NAME) + account_name = get_first_property_value(properties, ADLS_ACCOUNT_NAME, ADLS_SHARED_KEY_ACCOUNT_NAME) sas_token = properties.get(ADLS_SAS_TOKEN) for key, per_account_sas_token in { @@ -324,7 +326,7 @@ async def get_token(self, *scopes: str, **kwargs: Any) -> AccessToken: connection_string=properties.get(ADLS_CONNECTION_STRING), credential=credential, account_name=account_name, - account_key=properties.get(ADLS_ACCOUNT_KEY), + account_key=get_first_property_value(properties, ADLS_ACCOUNT_KEY, ADLS_SHARED_KEY_ACCOUNT_KEY), sas_token=sas_token, tenant_id=properties.get(ADLS_TENANT_ID), client_id=properties.get(ADLS_CLIENT_ID), diff --git a/pyiceberg/io/pyarrow.py b/pyiceberg/io/pyarrow.py index 6094093540..29b437d3b8 100644 --- a/pyiceberg/io/pyarrow.py +++ b/pyiceberg/io/pyarrow.py @@ -92,6 +92,8 @@ ADLS_DFS_STORAGE_AUTHORITY, ADLS_DFS_STORAGE_SCHEME, ADLS_SAS_TOKEN, + ADLS_SHARED_KEY_ACCOUNT_KEY, + ADLS_SHARED_KEY_ACCOUNT_NAME, ADLS_TENANT_ID, AWS_ACCESS_KEY_ID, AWS_ASSUME_ROLE_ARN, @@ -601,14 +603,14 @@ def _initialize_azure_fs(self, netloc: str | None = None) -> FileSystem: client_kwargs: dict[str, str] = {} - account_name = self.properties.get(ADLS_ACCOUNT_NAME) + account_name = get_first_property_value(self.properties, ADLS_ACCOUNT_NAME, ADLS_SHARED_KEY_ACCOUNT_NAME) if account_name is None and netloc and "@" in netloc: account_name = netloc.rpartition("@")[2].split(".")[0] or None if account_name: client_kwargs["account_name"] = account_name - if account_key := self.properties.get(ADLS_ACCOUNT_KEY): + if account_key := get_first_property_value(self.properties, ADLS_ACCOUNT_KEY, ADLS_SHARED_KEY_ACCOUNT_KEY): client_kwargs["account_key"] = account_key if blob_storage_authority := self.properties.get(ADLS_BLOB_STORAGE_AUTHORITY): diff --git a/tests/io/test_fsspec.py b/tests/io/test_fsspec.py index 9c76e535fe..1a1e913d8c 100644 --- a/tests/io/test_fsspec.py +++ b/tests/io/test_fsspec.py @@ -676,6 +676,20 @@ def test_adls_account_name_sas_token_extraction() -> None: ) +def test_fsspec_adls_accepts_java_shared_key_properties() -> None: + session_properties: Properties = { + "adls.auth.shared-key.account.name": "testaccount", + "adls.auth.shared-key.account.key": "test-key", + } + + with mock.patch("adlfs.AzureBlobFileSystem") as mock_adlfs: + FsspecFileIO(properties=session_properties).new_input(location="abfss://tests/file.parquet") + + client_kwargs = mock_adlfs.call_args.kwargs + assert client_kwargs["account_name"] == "testaccount" + assert client_kwargs["account_key"] == "test-key" + + def test_adls_account_name_extracted_from_uri_hostname() -> None: """Test that account_name is extracted from the ABFSS URI hostname when not in properties.""" session_properties: Properties = { diff --git a/tests/io/test_pyarrow.py b/tests/io/test_pyarrow.py index 658f10bb10..f7e13734a3 100644 --- a/tests/io/test_pyarrow.py +++ b/tests/io/test_pyarrow.py @@ -4713,6 +4713,37 @@ def test_adls_account_name_property_wins_over_location() -> None: assert mock_azure_fs.call_args.kwargs["account_name"] == "configured" +@skip_if_pyarrow_too_old +def test_adls_java_shared_key_properties() -> None: + """Java configs name the shared key with adls.auth.shared-key.*.""" + with patch("pyarrow.fs.AzureFileSystem") as mock_azure_fs: + PyArrowFileIO( + { + "adls.auth.shared-key.account.name": "configured", + "adls.auth.shared-key.account.key": "secret", + } + ).fs_by_scheme("abfss", "warehouse") + + assert mock_azure_fs.call_args.kwargs["account_name"] == "configured" + assert mock_azure_fs.call_args.kwargs["account_key"] == "secret" + + +@skip_if_pyarrow_too_old +def test_adls_native_shared_key_properties_take_precedence() -> None: + with patch("pyarrow.fs.AzureFileSystem") as mock_azure_fs: + PyArrowFileIO( + { + "adls.account-name": "native", + "adls.account-key": "native-secret", + "adls.auth.shared-key.account.name": "java", + "adls.auth.shared-key.account.key": "java-secret", + } + ).fs_by_scheme("abfss", "warehouse") + + assert mock_azure_fs.call_args.kwargs["account_name"] == "native" + assert mock_azure_fs.call_args.kwargs["account_key"] == "native-secret" + + @skip_if_pyarrow_too_old def test_adls_no_account_name_from_container_only_location() -> None: """A container only netloc carries no account, so nothing should be inferred from it.""" From b214d932990cd989774ac33757eaee190be5877b Mon Sep 17 00:00:00 2001 From: Anurag Singh Date: Wed, 2 Dec 2026 22:03:12 +0530 Subject: [PATCH 2/2] feat(io): accept per-account ADLS connection strings adls.connection-string. selects a connection string for the account in the location. The single adls.connection-string key still takes precedence when both are set. --- pyiceberg/io/fsspec.py | 6 +++++- tests/io/test_fsspec.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pyiceberg/io/fsspec.py b/pyiceberg/io/fsspec.py index e61df0d552..dc38e311f4 100644 --- a/pyiceberg/io/fsspec.py +++ b/pyiceberg/io/fsspec.py @@ -304,6 +304,10 @@ def _adls(properties: Properties, hostname: str | None = None) -> AbstractFileSy if hostname and account_name is None: account_name = hostname.split(".")[0] + connection_string = properties.get(ADLS_CONNECTION_STRING) + if connection_string is None and account_name is not None: + connection_string = properties.get(f"{ADLS_CONNECTION_STRING}.{account_name}") + class StaticTokenCredential(AsyncTokenCredential): _DEFAULT_EXPIRY_SECONDS = 3600 @@ -323,7 +327,7 @@ async def get_token(self, *scopes: str, **kwargs: Any) -> AccessToken: credential = properties.get(ADLS_CREDENTIAL) # type: ignore return AzureBlobFileSystem( - connection_string=properties.get(ADLS_CONNECTION_STRING), + connection_string=connection_string, credential=credential, account_name=account_name, account_key=get_first_property_value(properties, ADLS_ACCOUNT_KEY, ADLS_SHARED_KEY_ACCOUNT_KEY), diff --git a/tests/io/test_fsspec.py b/tests/io/test_fsspec.py index 1a1e913d8c..378790e066 100644 --- a/tests/io/test_fsspec.py +++ b/tests/io/test_fsspec.py @@ -690,6 +690,35 @@ def test_fsspec_adls_accepts_java_shared_key_properties() -> None: assert client_kwargs["account_key"] == "test-key" +def test_fsspec_adls_accepts_per_account_connection_string() -> None: + session_properties: Properties = { + "adls.connection-string.connectionaccount": "DefaultEndpointsProtocol=https;AccountName=connectionaccount", + } + + with mock.patch("adlfs.AzureBlobFileSystem") as mock_adlfs: + FsspecFileIO(properties=session_properties).new_input( + location="abfss://container@connectionaccount.dfs.core.windows.net/file.parquet" + ) + + assert mock_adlfs.call_args.kwargs["connection_string"] == ( + "DefaultEndpointsProtocol=https;AccountName=connectionaccount" + ) + + +def test_fsspec_adls_single_connection_string_takes_precedence() -> None: + session_properties: Properties = { + "adls.connection-string": "single", + "adls.connection-string.connectionaccount": "per-account", + } + + with mock.patch("adlfs.AzureBlobFileSystem") as mock_adlfs: + FsspecFileIO(properties=session_properties).new_input( + location="abfss://container@connectionaccount.dfs.core.windows.net/file.parquet" + ) + + assert mock_adlfs.call_args.kwargs["connection_string"] == "single" + + def test_adls_account_name_extracted_from_uri_hostname() -> None: """Test that account_name is extracted from the ABFSS URI hostname when not in properties.""" session_properties: Properties = {