Skip to content
Draft
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
53 changes: 53 additions & 0 deletions tests/integration/test_rest_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,56 @@ def test_create_namespace_if_already_existing(catalog: RestCatalog) -> None:
catalog.create_namespace_if_not_exists(TEST_NAMESPACE_IDENTIFIER)

assert catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER)


@pytest.mark.integration
@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog")])
def test_create_table_invalid_sort_order(catalog: RestCatalog) -> None:
from pyiceberg.catalog.rest import Endpoints
from pyiceberg.schema import Schema
from pyiceberg.types import LongType, NestedField

namespace = "default"
table_name = "test_invalid_sort_order"

# Ensure namespace exists
catalog.create_namespace_if_not_exists(namespace)

# Define a simple schema
schema = Schema(NestedField(1, "x", LongType()))

# Create the payload manually to bypass client-side validation
# We want a sort order that references a non-existent field ID (e.g., 9999)
payload = {
"name": table_name,
"schema": schema.model_dump(by_alias=True),
"write-order": {
"order-id": 1,
"fields": [
{
"transform": "identity",
"source-id": 9999, # Non-existent field
"direction": "asc",
"null-order": "nulls-first",
}
],
},
"stage-create": False,
}

# Send the request using the underlying session
# Endpoints.create_table is "namespaces/{namespace}/tables"
url = catalog.url(Endpoints.create_table, namespace=namespace)

response = catalog._session.post(url, json=payload)

assert response.status_code == 400
response_json = response.json()
response_json["error"].pop("stack", None)
assert response_json == {
"error": {
"message": "Cannot find source column for sort field: identity(9999) ASC NULLS FIRST",
"type": "ValidationException",
"code": 400,
}
}