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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ if res.task_id:
### Upload

```python
from altertable_lakehouse.models import UploadFormat, UploadMode
from altertable_lakehouse.models import UploadMode

with open("data.csv", "rb") as f:
client.upload(
catalog="my_cat",
schema="my_schema",
table="my_table",
format=UploadFormat.CSV,
mode=UploadMode.APPEND,
content=f.read()
content=f.read(),
content_type="text/csv"
)
```

Expand Down
13 changes: 6 additions & 7 deletions src/altertable_lakehouse/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
ValidateResponse,
AutocompleteRequest,
AutocompleteResponse,
UploadFormat,
UploadMode,
QueryMetadata,
QueryResult,
Expand Down Expand Up @@ -124,26 +123,26 @@ def upload(
catalog: str,
schema: str,
table: str,
format: UploadFormat,
mode: UploadMode,
content: bytes,
mode: Optional[UploadMode] = None,
primary_key: Optional[str] = None,
content_type: str = "application/octet-stream",
) -> 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"},
headers={"Content-Type": content_type},
)
self._check_response(res)
except httpx.RequestError as e:
Expand Down
6 changes: 0 additions & 6 deletions src/altertable_lakehouse/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ class ComputeSize(str, Enum):
XL = "XL"


class UploadFormat(str, Enum):
CSV = "csv"
JSON = "json"
PARQUET = "parquet"


class UploadMode(str, Enum):
CREATE = "create"
APPEND = "append"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_query_all(client):

def test_upload(client):
try:
client.upload(catalog="cat", schema="sch", table="tbl", format=models.UploadFormat.JSON, mode=models.UploadMode.APPEND, content=b'{"a":1}')
client.upload(catalog="cat", schema="sch", table="tbl", mode=models.UploadMode.APPEND, content=b'{"a":1}', content_type="application/json")
except errors.BadRequestError:
pass

Expand Down
Loading