Skip to content

Commit

Permalink
RSDK-9505: accept bson queries in mql function (#318)
Browse files Browse the repository at this point in the history
* change query to be dynamic

* add comment

* change test to use list of maps
  • Loading branch information
purplenicole730 authored Dec 20, 2024
1 parent 8fc978f commit 3749a17
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 11 additions & 3 deletions lib/src/app/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,21 @@ class DataClient {
return response.rawData.map((e) => BsonCodec.deserialize(BsonBinary.from(e))).toList();
}

/// Obtain unified tabular data and metadata, queried with MQL.
/// Obtain unified tabular data and metadata, queried with MQL. The query should be of type List<Map<String, dynamic>>.
///
/// For more information, see [Data Client API](https://docs.viam.com/appendix/apis/data-client/).
Future<List<Map<String, dynamic>>> tabularDataByMql(String organizationId, List<Uint8List> query) async {
Future<List<Map<String, dynamic>>> tabularDataByMql(String organizationId, dynamic query) async {
List<Uint8List> binary;
if (query is List<Map<String, dynamic>>) {
binary = query.map((q) => BsonCodec.serialize(q).byteList).toList();
} else if (query is List<Uint8List>) {
binary = query;
} else {
throw TypeError();
}
final request = TabularDataByMQLRequest()
..organizationId = organizationId
..mqlBinary.addAll(query);
..mqlBinary.addAll(binary);
final response = await _dataClient.tabularDataByMQL(request);
return response.rawData.map((e) => BsonCodec.deserialize(BsonBinary.from(e))).toList();
}
Expand Down
5 changes: 4 additions & 1 deletion test/unit_test/app/data_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ void main() {
});

test('tabularDataByMql', () async {
final List<Map<String, dynamic>> query = [
{'key': 'value'}
];
final startDate = DateTime.utc(2020, 12, 31);
final List<Map<String, dynamic>> data = [
{
Expand All @@ -175,7 +178,7 @@ void main() {
when(serviceClient.tabularDataByMQL(any)).thenAnswer(
(_) => MockResponseFuture.value(TabularDataByMQLResponse()..rawData.addAll(data.map((e) => BsonCodec.serialize(e).byteList))));

final response = await dataClient.tabularDataByMql('some_org_id', [Uint8List.fromList('some_query'.codeUnits)]);
final response = await dataClient.tabularDataByMql('some_org_id', query);
expect(response[0]['key1'], equals(data[0]['key1']));
expect(response, equals(data));
});
Expand Down

0 comments on commit 3749a17

Please sign in to comment.