-
Notifications
You must be signed in to change notification settings - Fork 451
Support storage-credentials in REST catalog LoadTableResult #3042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kevinjqliu
merged 3 commits into
apache:main
from
rcjverhoef:rcjverhoef/storage-creds-support
Mar 6, 2026
+116
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ | |
| PlanSubmitted, | ||
| PlanTableScanRequest, | ||
| ScanTasks, | ||
| StorageCredential, | ||
| ) | ||
| from pyiceberg.exceptions import ( | ||
| AuthorizationExpiredError, | ||
|
|
@@ -261,6 +262,7 @@ class TableResponse(IcebergBaseModel): | |
| metadata_location: str | None = Field(alias="metadata-location", default=None) | ||
| metadata: TableMetadata | ||
| config: Properties = Field(default_factory=dict) | ||
| storage_credentials: list[StorageCredential] = Field(alias="storage-credentials", default_factory=list) | ||
|
|
||
|
|
||
| class CreateTableRequest(IcebergBaseModel): | ||
|
|
@@ -396,6 +398,26 @@ def _create_session(self) -> Session: | |
|
|
||
| return session | ||
|
|
||
| @staticmethod | ||
| def _resolve_storage_credentials(storage_credentials: list[StorageCredential], location: str | None) -> Properties: | ||
| """Resolve the best-matching storage credential by longest prefix match. | ||
|
|
||
| Mirrors the Java implementation in S3FileIO.clientForStoragePath() which iterates | ||
| over storage credential prefixes and selects the one with the longest match. | ||
|
|
||
| See: https://github.com/apache/iceberg/blob/main/aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java | ||
| """ | ||
| if not storage_credentials or not location: | ||
| return {} | ||
|
|
||
| best_match: StorageCredential | None = None | ||
| for cred in storage_credentials: | ||
| if location.startswith(cred.prefix): | ||
| if best_match is None or len(cred.prefix) > len(best_match.prefix): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| best_match = cred | ||
|
|
||
| return best_match.config if best_match else {} | ||
|
|
||
| def _load_file_io(self, properties: Properties = EMPTY_DICT, location: str | None = None) -> FileIO: | ||
| merged_properties = {**self.properties, **properties} | ||
| if self._auth_manager: | ||
|
|
@@ -734,24 +756,34 @@ def add_headers(self, request: PreparedRequest, **kwargs: Any) -> None: # pylin | |
| session.mount(self.uri, SigV4Adapter(**self.properties)) | ||
|
|
||
| def _response_to_table(self, identifier_tuple: tuple[str, ...], table_response: TableResponse) -> Table: | ||
| # Per Iceberg spec: storage-credentials take precedence over config | ||
| credential_config = self._resolve_storage_credentials( | ||
| table_response.storage_credentials, table_response.metadata_location | ||
| ) | ||
| return Table( | ||
| identifier=identifier_tuple, | ||
| metadata_location=table_response.metadata_location, # type: ignore | ||
| metadata=table_response.metadata, | ||
| io=self._load_file_io( | ||
| {**table_response.metadata.properties, **table_response.config}, table_response.metadata_location | ||
| {**table_response.metadata.properties, **table_response.config, **credential_config}, | ||
| table_response.metadata_location, | ||
| ), | ||
| catalog=self, | ||
| config=table_response.config, | ||
| ) | ||
|
|
||
| def _response_to_staged_table(self, identifier_tuple: tuple[str, ...], table_response: TableResponse) -> StagedTable: | ||
| # Per Iceberg spec: storage-credentials take precedence over config | ||
| credential_config = self._resolve_storage_credentials( | ||
| table_response.storage_credentials, table_response.metadata_location | ||
| ) | ||
| return StagedTable( | ||
| identifier=identifier_tuple, | ||
| metadata_location=table_response.metadata_location, # type: ignore | ||
| metadata=table_response.metadata, | ||
| io=self._load_file_io( | ||
| {**table_response.metadata.properties, **table_response.config}, table_response.metadata_location | ||
| {**table_response.metadata.properties, **table_response.config, **credential_config}, | ||
| table_response.metadata_location, | ||
| ), | ||
| catalog=self, | ||
| ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me: https://github.com/apache/iceberg/blob/6299a289732dfeda7b5ab6d11d4438015505910e/open-api/rest-catalog-open-api.yaml#L3500-L3503
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @Fokko, would you be able to merge this one as well?