Skip to content
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

Add support for 'None' on response data #443

Merged
merged 1 commit into from
Jan 31, 2024
Merged
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
23 changes: 23 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,29 @@ def sample_get_response_data():
}


@pytest.fixture(scope="session")
def sample_get_response_data_none():
"""
This is the response to the second HTTP request (a GET) from an actual
Trino session. It is deliberately not truncated to document such response
and allow to use it for other tests. After doing the steps above, do:

::
>>> cur.fetchall()

"""
yield {
"id": "20210817_140827_00000_arvdv",
"nextUri": "coordinator:8080/v1/statement/20210817_140827_00000_arvdv/2",
"data": None,
"columns": [],
"taskDownloadUris": [],
"partialCancelUri": "http://localhost:8080/v1/stage/20210817_140827_00000_arvdv.0", # NOQA: E501
"stats": {},
"infoUri": "http://coordinator:8080/query.html?20210817_140827_00000_arvdv", # NOQA: E501
}


@pytest.fixture(scope="session")
def sample_get_error_response_data():
yield {
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,32 @@ def test_trino_fetch_request(mock_requests, sample_get_response_data):
assert status.rows == sample_get_response_data["data"]


@mock.patch("trino.client.TrinoRequest.http")
def test_trino_fetch_request_data_none(mock_requests, sample_get_response_data_none):
mock_requests.Response.return_value.json.return_value = sample_get_response_data_none

req = TrinoRequest(
host="coordinator",
port=8080,
client_session=ClientSession(
user="test",
source="test",
catalog="test",
schema="test",
properties={},
),
http_scheme="http",
)

http_resp = TrinoRequest.http.Response()
http_resp.status_code = 200
status = req.process(http_resp)

assert status.next_uri == sample_get_response_data_none["nextUri"]
assert status.id == sample_get_response_data_none["id"]
assert status.rows == []


@mock.patch("trino.client.TrinoRequest.http")
def test_trino_fetch_error(mock_requests, sample_get_error_response_data):
mock_requests.Response.return_value.json.return_value = sample_get_error_response_data
Expand Down
4 changes: 3 additions & 1 deletion trino/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ def process(self, http_response) -> TrinoStatus:

self._next_uri = response.get("nextUri")

data = response.get("data") if response.get("data") else []

return TrinoStatus(
id=response["id"],
stats=response["stats"],
Expand All @@ -641,7 +643,7 @@ def process(self, http_response) -> TrinoStatus:
next_uri=self._next_uri,
update_type=response.get("updateType"),
update_count=response.get("updateCount"),
rows=response.get("data", []),
rows=data,
columns=response.get("columns"),
)

Expand Down
Loading