Search in sources :

Example 1 with Selection

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");
}
Also used : SelectionSpec(org.hypertrace.core.documentstore.query.SelectionSpec) Query(org.hypertrace.core.documentstore.query.Query) Filter(org.hypertrace.core.documentstore.query.Filter) Selection(org.hypertrace.core.documentstore.query.Selection) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 2 with Selection

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");
}
Also used : Pagination(org.hypertrace.core.documentstore.query.Pagination) SelectionSpec(org.hypertrace.core.documentstore.query.SelectionSpec) Query(org.hypertrace.core.documentstore.query.Query) Filter(org.hypertrace.core.documentstore.query.Filter) Selection(org.hypertrace.core.documentstore.query.Selection) Sort(org.hypertrace.core.documentstore.query.Sort) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 3 with Selection

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");
}
Also used : Pagination(org.hypertrace.core.documentstore.query.Pagination) SelectionSpec(org.hypertrace.core.documentstore.query.SelectionSpec) Query(org.hypertrace.core.documentstore.query.Query) Filter(org.hypertrace.core.documentstore.query.Filter) Selection(org.hypertrace.core.documentstore.query.Selection) Sort(org.hypertrace.core.documentstore.query.Sort) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 4 with Selection

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");
}
Also used : SelectionSpec(org.hypertrace.core.documentstore.query.SelectionSpec) Query(org.hypertrace.core.documentstore.query.Query) Filter(org.hypertrace.core.documentstore.query.Filter) Selection(org.hypertrace.core.documentstore.query.Selection) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 5 with Selection

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();
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) SelectionSpec(org.hypertrace.core.documentstore.query.SelectionSpec) Query(org.hypertrace.core.documentstore.query.Query) Filter(org.hypertrace.core.documentstore.query.Filter) Selection(org.hypertrace.core.documentstore.query.Selection) Test(org.junit.jupiter.api.Test)

Aggregations

Selection (org.hypertrace.core.documentstore.query.Selection)7 Filter (org.hypertrace.core.documentstore.query.Filter)6 Test (org.junit.jupiter.api.Test)6 Document (org.hypertrace.core.documentstore.Document)5 Query (org.hypertrace.core.documentstore.query.Query)5 SelectionSpec (org.hypertrace.core.documentstore.query.SelectionSpec)5 Pagination (org.hypertrace.core.documentstore.query.Pagination)2 Sort (org.hypertrace.core.documentstore.query.Sort)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 BasicDBObject (com.mongodb.BasicDBObject)1 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 Collectors.toUnmodifiableList (java.util.stream.Collectors.toUnmodifiableList)1 JSONDocument (org.hypertrace.core.documentstore.JSONDocument)1 AttributeValueList (org.hypertrace.entity.data.service.v1.AttributeValueList)1