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

RSDK-9505: accept bson queries in mql function #318

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
14 changes: 11 additions & 3 deletions lib/src/app/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,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
Loading