|
2 | 2 | from dataclasses import dataclass |
3 | 3 | from datetime import datetime |
4 | 4 | from pathlib import Path |
5 | | -from typing import Any, List, Mapping, Optional, Sequence, Tuple |
| 5 | +from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple |
6 | 6 |
|
7 | 7 | from google.protobuf.struct_pb2 import Struct |
8 | 8 | from grpclib.client import Channel, Stream |
|
23 | 23 | BoundingBoxLabelsByFilterRequest, |
24 | 24 | BoundingBoxLabelsByFilterResponse, |
25 | 25 | CaptureMetadata, |
| 26 | + ConfigureDatabaseUserRequest, |
26 | 27 | DataRequest, |
27 | 28 | DataServiceStub, |
28 | 29 | DeleteBinaryDataByFilterRequest, |
|
43 | 44 | RemoveTagsFromBinaryDataByIDsResponse, |
44 | 45 | TabularDataByFilterRequest, |
45 | 46 | TabularDataByFilterResponse, |
| 47 | + TabularDataByMQLRequest, |
| 48 | + TabularDataByMQLResponse, |
| 49 | + TabularDataBySQLRequest, |
| 50 | + TabularDataBySQLResponse, |
46 | 51 | TagsByFilterRequest, |
47 | 52 | TagsByFilterResponse, |
48 | 53 | ) |
|
73 | 78 | StreamingDataCaptureUploadResponse, |
74 | 79 | UploadMetadata, |
75 | 80 | ) |
76 | | -from viam.utils import create_filter, datetime_to_timestamp, struct_to_dict |
| 81 | +from viam.utils import ValueTypes, create_filter, datetime_to_timestamp, struct_to_dict |
77 | 82 |
|
78 | 83 | LOGGER = logging.getLogger(__name__) |
79 | 84 |
|
@@ -248,6 +253,44 @@ async def tabular_data_by_filter( |
248 | 253 | LOGGER.error(f"Failed to write tabular data to file {dest}", exc_info=e) |
249 | 254 | return data, response.count, response.last |
250 | 255 |
|
| 256 | + async def tabular_data_by_sql(self, organization_id: str, sql_query: str) -> List[Dict[str, ValueTypes]]: |
| 257 | + """Obtain unified tabular data and metadata, queried with SQL. |
| 258 | +
|
| 259 | + :: |
| 260 | +
|
| 261 | + data = await data_client.tabular_data_by_sql(org_id="<your-org-id>", sql_query="<sql-query>") |
| 262 | +
|
| 263 | +
|
| 264 | + Args: |
| 265 | + organization_id (str): The ID of the organization that owns the data. |
| 266 | + sql_query (str): The SQL query to run. |
| 267 | +
|
| 268 | + Returns: |
| 269 | + List[Dict[str, ValueTypes]]: An array of data objects. |
| 270 | + """ |
| 271 | + request = TabularDataBySQLRequest(organization_id=organization_id, sql_query=sql_query) |
| 272 | + response: TabularDataBySQLResponse = await self._data_client.TabularDataBySQL(request, metadata=self._metadata) |
| 273 | + return [struct_to_dict(struct) for struct in response.data] |
| 274 | + |
| 275 | + async def tabular_data_by_mql(self, organization_id: str, mql_binary: List[bytes]) -> List[Dict[str, ValueTypes]]: |
| 276 | + """Obtain unified tabular data and metadata, queried with MQL. |
| 277 | +
|
| 278 | + :: |
| 279 | +
|
| 280 | + data = await data_client.tabular_data_by_mql(org_id="<your-org-id>", mql_binary=[<mql-bytes-1>, <mql-bytes-2>]) |
| 281 | +
|
| 282 | +
|
| 283 | + Args: |
| 284 | + organization_id (str): The ID of the organization that owns the data. |
| 285 | + mql_binary (List[bytes]):The MQL query to run as a list of BSON documents. |
| 286 | +
|
| 287 | + Returns: |
| 288 | + List[Dict[str, ValueTypes]]: An array of data objects. |
| 289 | + """ |
| 290 | + request = TabularDataByMQLRequest(organization_id=organization_id, mql_binary=mql_binary) |
| 291 | + response: TabularDataByMQLResponse = await self._data_client.TabularDataByMQL(request, metadata=self._metadata) |
| 292 | + return [struct_to_dict(struct) for struct in response.data] |
| 293 | + |
251 | 294 | async def binary_data_by_filter( |
252 | 295 | self, |
253 | 296 | filter: Optional[Filter] = None, |
@@ -733,9 +776,16 @@ async def get_database_connection(self, organization_id: str) -> str: |
733 | 776 | response: GetDatabaseConnectionResponse = await self._data_client.GetDatabaseConnection(request, metadata=self._metadata) |
734 | 777 | return response.hostname |
735 | 778 |
|
736 | | - # TODO(RSDK-5569): implement |
737 | 779 | async def configure_database_user(self, organization_id: str, password: str) -> None: |
738 | | - raise NotImplementedError() |
| 780 | + """Configure a database user for the Viam organization's MongoDB Atlas Data Federation instance. It can also be used to reset the |
| 781 | + password of the existing database user. |
| 782 | +
|
| 783 | + Args: |
| 784 | + organization_id (str): The ID of the organization. |
| 785 | + password (str): The password of the user. |
| 786 | + """ |
| 787 | + request = ConfigureDatabaseUserRequest(organization_id=organization_id, password=password) |
| 788 | + await self._data_client.ConfigureDatabaseUser(request, metadata=self._metadata) |
739 | 789 |
|
740 | 790 | async def create_dataset(self, name: str, organization_id: str) -> str: |
741 | 791 | """Create a new dataset. |
|
0 commit comments