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

Fix: Add python client QueryResult model field definitions #2952

Merged
merged 2 commits into from
Jun 24, 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
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,21 @@ def _resource_cls(self) -> Type[QueryResult]:
that the resource class of the resource container is
the return type of the get endpoint.
Therefore, this is only a temporary implementation and will be removed soon.

Returns
-------
[QueryResult][streampipes.model.resource.QueryResult]
"""
return QueryResult

@property
def _container_cls(self) -> Type[ResourceContainer]:
"""Defines the model container class the endpoint refers to."""
"""Defines the model container class the endpoint refers to.

Returns
-------
[DataLakeMeasures][streampipes.model.container.DataLakeMeasures]
"""
return DataLakeMeasures

@property
Expand Down Expand Up @@ -350,7 +359,7 @@ def get(self, identifier: str, **kwargs: Optional[Dict[str, Any]]) -> QueryResul

Returns
-------
measurement: DataLakeMeasures
measurement: QueryResult
The specified data lake measure

Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

from itertools import chain
from typing import Any, Dict, List, Literal, Union
from typing import Any, Dict, List, Literal, Optional, Union

import pandas as pd
from pydantic.v1 import Field, StrictInt, StrictStr
Expand Down Expand Up @@ -73,6 +73,9 @@ def convert_to_pandas_representation(self) -> Dict[str, Union[List[str], List[Li
headers: List[StrictStr]
all_data_series: List[DataSeries]
query_status: Literal["OK", "TOO_MUCH_DATA"] = Field(alias="spQueryStatus")
source_index: StrictInt
for_id: Optional[str]
last_timestamp: StrictInt

def to_pandas(self) -> pd.DataFrame:
"""Returns the data lake series in representation of a Pandas Dataframe.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def test_to_pandas(self, server_version: MagicMock, http_session: MagicMock):
"headers": self.headers,
"spQueryStatus": "OK",
"allDataSeries": [self.data_series],
"sourceIndex": 0,
"forId": None,
"lastTimestamp": 1717936808802,
}

result_pd = self.get_result_as_panda(http_session, query_result)
Expand All @@ -125,6 +128,9 @@ def test_group_by_to_pandas(self, server_version: MagicMock, http_session: Magic
"headers": self.headers,
"spQueryStatus": "OK",
"allDataSeries": [self.data_series, self.data_series],
"sourceIndex": 0,
"forId": None,
"lastTimestamp": 1717936808802,
}

result_pd = self.get_result_as_panda(http_session, query_result)
Expand All @@ -147,6 +153,9 @@ def test_different_headers_exception(self, server_version: MagicMock, http_sessi
"headers": ["one"],
"spQueryStatus": "OK",
"allDataSeries": [self.data_series],
"sourceIndex": 0,
"forId": None,
"lastTimestamp": 1717936808802,
}

with self.assertRaises(StreamPipesUnsupportedDataSeries):
Expand Down
Loading