use of org.hypertrace.core.documentstore.query.Selection in project document-store by hypertrace.
the class MongoQueryExecutorIntegrationTest method testFindWithDuplicateSelections.
@Test
public void testFindWithDuplicateSelections() throws IOException {
List<SelectionSpec> selectionSpecs = List.of(SelectionSpec.of(IdentifierExpression.of("item")), SelectionSpec.of(IdentifierExpression.of("item")), SelectionSpec.of(IdentifierExpression.of("price")), SelectionSpec.of(IdentifierExpression.of("quantity")), SelectionSpec.of(IdentifierExpression.of("quantity")), SelectionSpec.of(IdentifierExpression.of("date")));
Selection selection = Selection.builder().selectionSpecs(selectionSpecs).build();
Filter filter = Filter.builder().expression(RelationalExpression.of(IdentifierExpression.of("item"), NOT_IN, ConstantExpression.ofStrings(List.of("Soap", "Bottle")))).build();
Query query = Query.builder().setSelection(selection).setFilter(filter).build();
Iterator<Document> resultDocs = collection.find(query);
assertDocsEqual(resultDocs, "mongo/simple_filter_response.json");
}
use of org.hypertrace.core.documentstore.query.Selection in project document-store by hypertrace.
the class MongoQueryExecutorIntegrationTest method testFindWithDuplicateSortingAndPagination.
@Test
public void testFindWithDuplicateSortingAndPagination() throws IOException {
List<SelectionSpec> selectionSpecs = List.of(SelectionSpec.of(IdentifierExpression.of("item")), SelectionSpec.of(IdentifierExpression.of("price")), SelectionSpec.of(IdentifierExpression.of("quantity")), SelectionSpec.of(IdentifierExpression.of("date")));
Selection selection = Selection.builder().selectionSpecs(selectionSpecs).build();
Filter filter = Filter.builder().expression(RelationalExpression.of(IdentifierExpression.of("item"), IN, ConstantExpression.ofStrings(List.of("Mirror", "Comb", "Shampoo", "Bottle")))).build();
Sort sort = Sort.builder().sortingSpec(SortingSpec.of(IdentifierExpression.of("quantity"), DESC)).sortingSpec(SortingSpec.of(IdentifierExpression.of("item"), ASC)).sortingSpec(SortingSpec.of(IdentifierExpression.of("quantity"), DESC)).sortingSpec(SortingSpec.of(IdentifierExpression.of("item"), ASC)).build();
Pagination pagination = Pagination.builder().offset(1).limit(3).build();
Query query = Query.builder().setSelection(selection).setFilter(filter).setSort(sort).setPagination(pagination).build();
Iterator<Document> resultDocs = collection.find(query);
assertDocsEqual(resultDocs, "mongo/filter_with_sorting_and_pagination_response.json");
}
use of org.hypertrace.core.documentstore.query.Selection in project document-store by hypertrace.
the class MongoQueryExecutorIntegrationTest method testFindWithSortingAndPagination.
@Test
public void testFindWithSortingAndPagination() throws IOException {
List<SelectionSpec> selectionSpecs = List.of(SelectionSpec.of(IdentifierExpression.of("item")), SelectionSpec.of(IdentifierExpression.of("price")), SelectionSpec.of(IdentifierExpression.of("quantity")), SelectionSpec.of(IdentifierExpression.of("date")));
Selection selection = Selection.builder().selectionSpecs(selectionSpecs).build();
Filter filter = Filter.builder().expression(RelationalExpression.of(IdentifierExpression.of("item"), IN, ConstantExpression.ofStrings(List.of("Mirror", "Comb", "Shampoo", "Bottle")))).build();
Sort sort = Sort.builder().sortingSpec(SortingSpec.of(IdentifierExpression.of("quantity"), DESC)).sortingSpec(SortingSpec.of(IdentifierExpression.of("item"), ASC)).build();
Pagination pagination = Pagination.builder().offset(1).limit(3).build();
Query query = Query.builder().setSelection(selection).setFilter(filter).setSort(sort).setPagination(pagination).build();
Iterator<Document> resultDocs = collection.find(query);
assertDocsEqual(resultDocs, "mongo/filter_with_sorting_and_pagination_response.json");
}
use of org.hypertrace.core.documentstore.query.Selection in project document-store by hypertrace.
the class MongoQueryExecutorIntegrationTest method testFindSimple.
@Test
public void testFindSimple() throws IOException {
List<SelectionSpec> selectionSpecs = List.of(SelectionSpec.of(IdentifierExpression.of("item")), SelectionSpec.of(IdentifierExpression.of("price")), SelectionSpec.of(IdentifierExpression.of("quantity")), SelectionSpec.of(IdentifierExpression.of("date")));
Selection selection = Selection.builder().selectionSpecs(selectionSpecs).build();
Filter filter = Filter.builder().expression(RelationalExpression.of(IdentifierExpression.of("item"), NOT_IN, ConstantExpression.ofStrings(List.of("Soap", "Bottle")))).build();
Query query = Query.builder().setSelection(selection).setFilter(filter).build();
Iterator<Document> resultDocs = collection.find(query);
assertDocsEqual(resultDocs, "mongo/simple_filter_response.json");
}
use of org.hypertrace.core.documentstore.query.Selection in project document-store by hypertrace.
the class MongoQueryExecutorTest method testFindAndAggregateWithDuplicateAlias.
@Test
public void testFindAndAggregateWithDuplicateAlias() {
List<SelectionSpec> selectionSpecs = List.of(SelectionSpec.of(IdentifierExpression.of("item")), SelectionSpec.of(IdentifierExpression.of("price"), "value"), SelectionSpec.of(IdentifierExpression.of("quantity"), "value"), SelectionSpec.of(IdentifierExpression.of("date")));
Selection selection = Selection.builder().selectionSpecs(selectionSpecs).build();
Filter filter = Filter.builder().expression(RelationalExpression.of(IdentifierExpression.of("item"), NOT_IN, ConstantExpression.ofStrings(List.of("Soap", "Bottle")))).build();
Query query = Query.builder().setSelection(selection).setFilter(filter).build();
assertThrows(IllegalArgumentException.class, () -> executor.find(query));
verify(collection, NOT_INVOKED).getNamespace();
verify(collection, NOT_INVOKED).find(any(BasicDBObject.class));
verify(iterable, NOT_INVOKED).projection(any(BasicDBObject.class));
verify(iterable, NOT_INVOKED).sort(any(BasicDBObject.class));
verify(iterable, NOT_INVOKED).skip(anyInt());
verify(iterable, NOT_INVOKED).limit(anyInt());
verify(iterable, NOT_INVOKED).cursor();
assertThrows(IllegalArgumentException.class, () -> executor.aggregate(query));
verify(collection, NOT_INVOKED).aggregate(anyList());
verify(aggIterable, NOT_INVOKED).cursor();
}
Aggregations