Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mkdocs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: in Java (GCSInputStream/GCSOutputStream) gcs.user-project is applied whenever it's set, not only as a fallback, so the doc row reads slightly stricter than the code below it (an explicit gcs.requester-pays=false also skips it here). Happy either way, just flagging the wording:

Suggested change
| 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.user-project | my-billing-project | Configure the user project billed for requester-pays requests, used when `gcs.requester-pays` is not set explicitly. |

| gcs.session-kwargs | {} | Configure a dict of parameters to pass on to aiohttp.ClientSession; can contain, for example, proxy settings. |
| gcs.service.host | <http://0.0.0.0:4443> | 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'. |
Expand Down
1 change: 1 addition & 0 deletions pyiceberg/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion pyiceberg/io/fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
GCS_SESSION_KWARGS,
GCS_TOKEN,
GCS_TOKEN_EXPIRES_AT_MS,
GCS_USER_PROJECT,
GCS_VERSION_AWARE,
HF_ENDPOINT,
HF_TOKEN,
Expand Down Expand Up @@ -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)
Comment on lines +270 to +271

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: property_as_bool treats an explicit empty string as unset (value not in (None, "")), so with gcs.requester-pays="" we'd take this branch and ignore gcs.user-project. Could you match that here? Suggests itself as a small change:

Suggested change
if GCS_REQUESTER_PAYS in properties:
requester_pays = property_as_bool(properties, GCS_REQUESTER_PAYS, False)
if (requester_pays_value := properties.get(GCS_REQUESTER_PAYS)) not in (None, ""):
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

Might also be worth a test case for gcs.requester-pays="" next to gcs.user-project.

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),
Expand Down
20 changes: 20 additions & 0 deletions tests/io/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
Loading