From d0a554abbb3beb40db60f54f6c7be895ff49a640 Mon Sep 17 00:00:00 2001 From: Arunav Ghosh <120900200+AllyNav@users.noreply.github.com> Date: Sat, 5 Dec 2026 12:53:29 +0530 Subject: [PATCH] feat(io): accept the Java gcs.user-project property --- mkdocs/docs/configuration.md | 1 + pyiceberg/io/__init__.py | 1 + pyiceberg/io/fsspec.py | 11 ++++++++++- tests/io/test_fsspec.py | 20 ++++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/mkdocs/docs/configuration.md b/mkdocs/docs/configuration.md index d72a4ead27..314ea66669 100644 --- a/mkdocs/docs/configuration.md +++ b/mkdocs/docs/configuration.md @@ -242,6 +242,7 @@ export AWS_RESPONSE_CHECKSUM_VALIDATION=when_required | gcs.consistency | md5 | Configure the check method when writing files. Must be one of 'none', 'size', or 'md5' | | gcs.cache-timeout | 60 | Configure the cache expiration time in seconds for object metadata cache | | gcs.requester-pays | False | Configure whether to use requester-pays requests | +| gcs.user-project | my-billing-project | Configure the user project billed for requester-pays requests (Java Iceberg fallback when `gcs.requester-pays` is not set). | | gcs.session-kwargs | {} | Configure a dict of parameters to pass on to aiohttp.ClientSession; can contain, for example, proxy settings. | | gcs.service.host | | Configure an alternative endpoint for the GCS FileIO to access (format protocol://host:port) If not given, defaults to the value of environment variable "STORAGE_EMULATOR_HOST"; if that is not set either, will use the standard Google endpoint. | | gcs.default-bucket-location | US | Configure the default location where buckets are created, like 'US' or 'EUROPE-WEST3'. | diff --git a/pyiceberg/io/__init__.py b/pyiceberg/io/__init__.py index c5c1ca932a..3ce6d8989e 100644 --- a/pyiceberg/io/__init__.py +++ b/pyiceberg/io/__init__.py @@ -120,6 +120,7 @@ def _is_local_path(path: str) -> bool: GCS_CONSISTENCY = "gcs.consistency" GCS_CACHE_TIMEOUT = "gcs.cache-timeout" GCS_REQUESTER_PAYS = "gcs.requester-pays" +GCS_USER_PROJECT = "gcs.user-project" GCS_SESSION_KWARGS = "gcs.session-kwargs" GCS_SERVICE_HOST = "gcs.service.host" GCS_DEFAULT_LOCATION = "gcs.default-bucket-location" diff --git a/pyiceberg/io/fsspec.py b/pyiceberg/io/fsspec.py index 87607d377b..a4b0a4f088 100644 --- a/pyiceberg/io/fsspec.py +++ b/pyiceberg/io/fsspec.py @@ -67,6 +67,7 @@ GCS_SESSION_KWARGS, GCS_TOKEN, GCS_TOKEN_EXPIRES_AT_MS, + GCS_USER_PROJECT, GCS_VERSION_AWARE, HF_ENDPOINT, HF_TOKEN, @@ -265,13 +266,21 @@ def _gs(properties: Properties) -> AbstractFileSystem: if token and (expires_at := properties.get(GCS_TOKEN_EXPIRES_AT_MS)): token = Credentials(token, expiry=millis_to_datetime(int(expires_at))) + requester_pays: bool | str + if GCS_REQUESTER_PAYS in properties: + requester_pays = property_as_bool(properties, GCS_REQUESTER_PAYS, False) + elif user_project := properties.get(GCS_USER_PROJECT): + requester_pays = user_project + else: + requester_pays = False + return GCSFileSystem( project=properties.get(GCS_PROJECT_ID), access=properties.get(GCS_ACCESS, "full_control"), token=token, consistency=properties.get(GCS_CONSISTENCY, "none"), cache_timeout=properties.get(GCS_CACHE_TIMEOUT), - requester_pays=property_as_bool(properties, GCS_REQUESTER_PAYS, False), + requester_pays=requester_pays, session_kwargs=json.loads(properties.get(GCS_SESSION_KWARGS, "{}")), endpoint_url=properties.get(GCS_SERVICE_HOST), default_location=properties.get(GCS_DEFAULT_LOCATION), diff --git a/tests/io/test_fsspec.py b/tests/io/test_fsspec.py index 9c76e535fe..6930ea8800 100644 --- a/tests/io/test_fsspec.py +++ b/tests/io/test_fsspec.py @@ -788,6 +788,26 @@ def test_fsspec_gcs_token_without_expiry() -> None: assert mock_gcsfs.call_args.kwargs["token"] == "token" +@pytest.mark.parametrize( + ("properties", "expected_requester_pays"), + [ + ({}, False), + ({"gcs.requester-pays": "true"}, True), + ({"gcs.requester-pays": "false"}, False), + ({"gcs.user-project": "my-billing-project"}, "my-billing-project"), + ({"gcs.user-project": ""}, False), + ({"gcs.requester-pays": "false", "gcs.user-project": "my-billing-project"}, False), + ({"gcs.requester-pays": "true", "gcs.user-project": "my-billing-project"}, True), + ], +) +def test_fsspec_gcs_user_project_property(properties: Properties, expected_requester_pays: bool | str) -> None: + """Test that gcs.user-project falls back to gcsfs requester_pays with native-key precedence.""" + with mock.patch("gcsfs.GCSFileSystem") as mock_gcsfs: + FsspecFileIO(properties=properties).new_input(location="gs://bucket/path/file.parquet") + + assert mock_gcsfs.call_args.kwargs["requester_pays"] == expected_requester_pays + + @pytest.mark.gcs def test_fsspec_new_input_file_gcs(fsspec_fileio_gcs: FsspecFileIO) -> None: """Test creating a new input file from a fsspec file-io"""