diff --git a/CHANGELOG.md b/CHANGELOG.md index 99ce0f3..cdbebde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,5 +19,5 @@ All notable changes to this project will be documented in this file. ## [0.1.0] - 2026-03-09 ### Added - Initial release of the Python SDK for the Altertable Lakehouse API. -- Implemented `append`, `upload`, `query`, `query_all`, `validate`, `get_query`, and `cancel_query` methods. +- Implemented `append`, `upsert`, `query`, `query_all`, `validate`, `get_query`, and `cancel_query` methods. - Full typing support with `pydantic` models. diff --git a/README.md b/README.md index e4c329a..bd085a9 100644 --- a/README.md +++ b/README.md @@ -58,18 +58,17 @@ if res.task_id: print(task.status) ``` -### Upload +### Upsert ```python -from altertable_lakehouse.models import UploadFormat, UploadMode +from altertable_lakehouse.models import UpsertMode with open("data.csv", "rb") as f: - client.upload( + client.upsert( catalog="my_cat", schema="my_schema", table="my_table", - format=UploadFormat.CSV, - mode=UploadMode.APPEND, + mode=UpsertMode.APPEND, content=f.read() ) ``` diff --git a/src/altertable_lakehouse/client.py b/src/altertable_lakehouse/client.py index 1a5aed4..8f17153 100644 --- a/src/altertable_lakehouse/client.py +++ b/src/altertable_lakehouse/client.py @@ -16,8 +16,7 @@ ValidateResponse, AutocompleteRequest, AutocompleteResponse, - UploadFormat, - UploadMode, + UpsertMode, QueryMetadata, QueryResult, ) @@ -119,31 +118,29 @@ def get_task(self, task_id: str) -> TaskResponse: except httpx.RequestError as e: self._handle_error(e) - def upload( + def upsert( self, catalog: str, schema: str, table: str, - format: UploadFormat, - mode: UploadMode, content: bytes, + mode: Optional[UpsertMode] = None, primary_key: Optional[str] = None, ) -> None: params = { "catalog": catalog, "schema": schema, "table": table, - "format": format.value, - "mode": mode.value, } + if mode is not None: + params["mode"] = mode.value if primary_key: params["primary_key"] = primary_key try: res = self._client.post( - "/upload", + "/upsert", params=params, content=content, - headers={"Content-Type": "application/octet-stream"}, ) self._check_response(res) except httpx.RequestError as e: diff --git a/src/altertable_lakehouse/models.py b/src/altertable_lakehouse/models.py index d69725e..2c4c950 100644 --- a/src/altertable_lakehouse/models.py +++ b/src/altertable_lakehouse/models.py @@ -11,13 +11,7 @@ class ComputeSize(str, Enum): XL = "XL" -class UploadFormat(str, Enum): - CSV = "csv" - JSON = "json" - PARQUET = "parquet" - - -class UploadMode(str, Enum): +class UpsertMode(str, Enum): CREATE = "create" APPEND = "append" UPSERT = "upsert" diff --git a/tests/test_client.py b/tests/test_client.py index f59c404..6c38d74 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -45,9 +45,9 @@ def test_query_all(client): assert isinstance(res.columns, list) assert isinstance(res.rows, list) -def test_upload(client): +def test_upsert(client): try: - client.upload(catalog="cat", schema="sch", table="tbl", format=models.UploadFormat.JSON, mode=models.UploadMode.APPEND, content=b'{"a":1}') + client.upsert(catalog="cat", schema="sch", table="tbl", mode=models.UpsertMode.APPEND, content=b'{"a":1}') except errors.BadRequestError: pass