Search in sources :

Example 1 with Query

use of org.hypertrace.core.documentstore.query.Query 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 Query

use of org.hypertrace.core.documentstore.query.Query in project document-store by hypertrace.

the class MongoQueryExecutorIntegrationTest method testFindAll.

@Test
public void testFindAll() throws IOException {
    Query query = Query.builder().build();
    Iterator<Document> resultDocs = collection.find(query);
    assertSizeEqual(resultDocs, "mongo/collection_data.json");
}
Also used : Query(org.hypertrace.core.documentstore.query.Query) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 3 with Query

use of org.hypertrace.core.documentstore.query.Query in project document-store by hypertrace.

the class MongoQueryExecutorIntegrationTest method testAggregateWithUnsupportedExpressionNesting.

@Test
public void testAggregateWithUnsupportedExpressionNesting() {
    Query query = Query.builder().addAggregation(IdentifierExpression.of("item")).addAggregation(IdentifierExpression.of("price")).addSelection(IdentifierExpression.of("item")).addSelection(IdentifierExpression.of("price")).addSelection(AggregateExpression.of(DISTINCT, IdentifierExpression.of("quantity")), "quantities").setAggregationFilter(RelationalExpression.of(ConstantExpression.of(1), GT, FunctionExpression.builder().operator(LENGTH).operand(IdentifierExpression.of("quantities")).build())).addSort(IdentifierExpression.of("item"), DESC).build();
    assertThrows(UnsupportedOperationException.class, () -> collection.aggregate(query));
}
Also used : Query(org.hypertrace.core.documentstore.query.Query) Test(org.junit.jupiter.api.Test)

Example 4 with Query

use of org.hypertrace.core.documentstore.query.Query in project document-store by hypertrace.

the class MongoQueryExecutorIntegrationTest method testUnnestAndAggregate.

@Test
public void testUnnestAndAggregate() throws IOException {
    org.hypertrace.core.documentstore.query.Query query = org.hypertrace.core.documentstore.query.Query.builder().addSelection(IdentifierExpression.of("sales.medium.type")).addAggregation(IdentifierExpression.of("sales.medium.type")).addSelection(AggregateExpression.of(SUM, IdentifierExpression.of("sales.medium.volume")), "totalSales").addFromClause(UnnestExpression.of(IdentifierExpression.of("sales"), false)).addFromClause(UnnestExpression.of(IdentifierExpression.of("sales.medium"), false)).addSort(IdentifierExpression.of("totalSales"), DESC).build();
    Iterator<Document> iterator = collection.aggregate(query);
    assertDocsEqual(iterator, "mongo/aggregate_on_nested_array_reponse.json");
}
Also used : Query(org.hypertrace.core.documentstore.query.Query) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 5 with Query

use of org.hypertrace.core.documentstore.query.Query 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)

Aggregations

Query (org.hypertrace.core.documentstore.query.Query)39 Test (org.junit.jupiter.api.Test)36 BasicDBObject (com.mongodb.BasicDBObject)18 Document (org.hypertrace.core.documentstore.Document)18 SelectionSpec (org.hypertrace.core.documentstore.query.SelectionSpec)6 Filter (org.hypertrace.core.documentstore.query.Filter)5 Selection (org.hypertrace.core.documentstore.query.Selection)5 Sort (org.hypertrace.core.documentstore.query.Sort)3 Pagination (org.hypertrace.core.documentstore.query.Pagination)2 TypeLiteral (com.google.inject.TypeLiteral)1 List (java.util.List)1 ConstantExpression (org.hypertrace.core.documentstore.expression.impl.ConstantExpression)1 AccessorModule (org.hypertrace.entity.query.service.converter.accessor.AccessorModule)1 AggregationModule (org.hypertrace.entity.query.service.converter.aggregation.AggregationModule)1 FilterModule (org.hypertrace.entity.query.service.converter.filter.FilterModule)1 IdentifierModule (org.hypertrace.entity.query.service.converter.identifier.IdentifierModule)1 ResponseModule (org.hypertrace.entity.query.service.converter.response.ResponseModule)1 SelectionConverterModule (org.hypertrace.entity.query.service.converter.selection.SelectionConverterModule)1 EntityQueryRequest (org.hypertrace.entity.query.service.v1.EntityQueryRequest)1 LiteralConstant (org.hypertrace.entity.query.service.v1.LiteralConstant)1