This is an automated email from the ASF dual-hosted git repository.
fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
The following commit(s) were added to refs/heads/main by this push:
new 5313df80 Pass table-token to commit endpoint (#1278)
5313df80 is described below
commit 5313df80ffd9720bf0b86492f35903c5b5ebbdb5
Author: Fokko Driesprong <[email protected]>
AuthorDate: Tue Nov 5 09:17:47 2024 +0100
Pass table-token to commit endpoint (#1278)
* Pass table-token to subsequent requests
See open-api spec:
https://github.com/apache/iceberg/blob/ea61ee46db17d94f22a5ef11fd913146557bdce7/open-api/rest-catalog-open-api.yaml#L927-L929
Resolves #1113
* Replace with constant
---
pyiceberg/catalog/rest.py | 7 +++++++
pyiceberg/table/__init__.py | 10 +++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/pyiceberg/catalog/rest.py b/pyiceberg/catalog/rest.py
index 20a04d9c..7c5d774c 100644
--- a/pyiceberg/catalog/rest.py
+++ b/pyiceberg/catalog/rest.py
@@ -525,6 +525,7 @@ class RestCatalog(Catalog):
{**table_response.metadata.properties,
**table_response.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:
@@ -777,9 +778,15 @@ class RestCatalog(Catalog):
identifier =
self._identifier_to_tuple_without_catalog(table.identifier)
table_identifier = TableIdentifier(namespace=identifier[:-1],
name=identifier[-1])
table_request = CommitTableRequest(identifier=table_identifier,
requirements=requirements, updates=updates)
+
+ headers = self._session.headers
+ if table_token := table.config.get(TOKEN):
+ headers[AUTHORIZATION_HEADER] = f"{BEARER_PREFIX} {table_token}"
+
response = self._session.post(
self.url(Endpoints.update_table, prefixed=True,
**self._split_identifier_for_path(table_request.identifier)),
data=table_request.model_dump_json().encode(UTF8),
+ headers=headers,
)
try:
response.raise_for_status()
diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py
index e431101b..80550825 100644
--- a/pyiceberg/table/__init__.py
+++ b/pyiceberg/table/__init__.py
@@ -734,15 +734,23 @@ class Table:
metadata_location: str = Field()
io: FileIO
catalog: Catalog
+ config: Dict[str, str]
def __init__(
- self, identifier: Identifier, metadata: TableMetadata,
metadata_location: str, io: FileIO, catalog: Catalog
+ self,
+ identifier: Identifier,
+ metadata: TableMetadata,
+ metadata_location: str,
+ io: FileIO,
+ catalog: Catalog,
+ config: Dict[str, str] = EMPTY_DICT,
) -> None:
self._identifier = identifier
self.metadata = metadata
self.metadata_location = metadata_location
self.io = io
self.catalog = catalog
+ self.config = config
def transaction(self) -> Transaction:
"""Create a new transaction object to first stage the changes, and
then commit them to the catalog.