Skip to content

Commit 44b6880

Browse files
accept dictionary in mql function
1 parent 14c9c82 commit 44b6880

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/viam/app/data_client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ async def tabular_data_by_sql(self, organization_id: str, sql_query: str) -> Lis
269269
response: TabularDataBySQLResponse = await self._data_client.TabularDataBySQL(request, metadata=self._metadata)
270270
return [bson.decode(bson_bytes) for bson_bytes in response.raw_data]
271271

272-
async def tabular_data_by_mql(self, organization_id: str, mql_binary: List[bytes]) -> List[Dict[str, Union[ValueTypes, datetime]]]:
272+
async def tabular_data_by_mql(
273+
self,
274+
organization_id: str,
275+
mql_query: Union[List[bytes], Dict[str, Union[ValueTypes, datetime]]]
276+
) -> List[Dict[str, Union[ValueTypes, datetime]]]:
273277
"""Obtain unified tabular data and metadata, queried with MQL.
274278
275279
::
@@ -288,14 +292,15 @@ async def tabular_data_by_mql(self, organization_id: str, mql_binary: List[bytes
288292
Args:
289293
organization_id (str): The ID of the organization that owns the data.
290294
You can obtain your organization ID from the Viam app's organization settings page.
291-
mql_binary (List[bytes]): The MQL query to run as a list of BSON queries. You can encode your bson queries using a library like
292-
`pymongo`.
295+
mql_query (Union[List[bytes], Dict[str, Union[ValueTypes, datetime]]]): The MQL query to run as a list of BSON queries.
296+
Note: Use a dictionary for `mql_query` as support for bytes will be removed in the future.
293297
294298
Returns:
295299
List[Dict[str, Union[ValueTypes, datetime]]]: An array of decoded BSON data objects.
296300
297301
For more information, see `Data Client API <https://docs.viam.com/appendix/apis/data-client/>`_.
298302
"""
303+
mql_binary = bson.encode(mql_query) if isinstance(mql_query, dict) else mql_query
299304
request = TabularDataByMQLRequest(organization_id=organization_id, mql_binary=mql_binary)
300305
response: TabularDataByMQLResponse = await self._data_client.TabularDataByMQL(request, metadata=self._metadata)
301306
return [bson.decode(bson_bytes) for bson_bytes in response.raw_data]

tests/test_data_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
)
7474
BBOXES = [BBOX]
7575
SQL_QUERY = "sql_query"
76-
MQL_BINARY = [b"mql_binary"]
76+
MQL_BINARY = {"binary": "mql_binary"}
7777
TABULAR_DATA = {"key": "value"}
7878
TABULAR_METADATA = CaptureMetadata(
7979
organization_id=ORG_ID,

0 commit comments

Comments
 (0)