Search in sources :

Example 6 with Document

use of org.hypertrace.core.documentstore.Document 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 7 with Document

use of org.hypertrace.core.documentstore.Document 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 8 with Document

use of org.hypertrace.core.documentstore.Document 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 9 with Document

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

the class MongoQueryExecutorIntegrationTest method testAggregateSimple.

@Test
public void testAggregateSimple() throws IOException {
    Query query = Query.builder().addSelection(AggregateExpression.of(COUNT, IdentifierExpression.of("item")), "count").build();
    Iterator<Document> resultDocs = collection.aggregate(query);
    assertDocsEqual(resultDocs, "mongo/count_response.json");
}
Also used : Query(org.hypertrace.core.documentstore.query.Query) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 10 with Document

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

the class MongoQueryExecutorIntegrationTest method testFindWithNestedFields.

@Test
public void testFindWithNestedFields() throws IOException {
    List<SelectionSpec> selectionSpecs = List.of(SelectionSpec.of(IdentifierExpression.of("item")), SelectionSpec.of(IdentifierExpression.of("price")), SelectionSpec.of(IdentifierExpression.of("props.seller.name"), "seller"), SelectionSpec.of(IdentifierExpression.of("props.brand")), SelectionSpec.of(IdentifierExpression.of("props.seller.address.city")));
    Query query = Query.builder().addSelections(selectionSpecs).setFilter(LogicalExpression.builder().operand(RelationalExpression.of(IdentifierExpression.of("item"), IN, ConstantExpression.ofStrings(List.of("Mirror", "Comb", "Shampoo")))).operator(OR).operand(RelationalExpression.of(IdentifierExpression.of("props.seller.address.pincode"), EQ, ConstantExpression.of(700007))).build()).addSort(IdentifierExpression.of("props.brand"), ASC).addSort(IdentifierExpression.of("item"), ASC).addSort(IdentifierExpression.of("props.seller.address.city"), ASC).build();
    Iterator<Document> resultDocs = collection.find(query);
    assertDocsEqual(resultDocs, "mongo/filter_on_nested_fields_response.json");
}
Also used : SelectionSpec(org.hypertrace.core.documentstore.query.SelectionSpec) Query(org.hypertrace.core.documentstore.query.Query) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Aggregations

Document (org.hypertrace.core.documentstore.Document)66 JSONDocument (org.hypertrace.core.documentstore.JSONDocument)41 Test (org.junit.jupiter.api.Test)37 SingleValueKey (org.hypertrace.core.documentstore.SingleValueKey)22 Collection (org.hypertrace.core.documentstore.Collection)21 ArrayList (java.util.ArrayList)20 Key (org.hypertrace.core.documentstore.Key)18 Query (org.hypertrace.core.documentstore.query.Query)18 ServiceException (com.google.protobuf.ServiceException)14 HashMap (java.util.HashMap)14 Query (org.hypertrace.core.documentstore.Query)14 MongoCollection (com.mongodb.client.MongoCollection)12 Map (java.util.Map)12 IOException (java.io.IOException)10 BulkUpdateResult (org.hypertrace.core.documentstore.BulkUpdateResult)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 Filter (org.hypertrace.core.documentstore.Filter)8 Entity (org.hypertrace.entity.data.service.v1.Entity)7 BulkArrayValueUpdateRequest (org.hypertrace.core.documentstore.BulkArrayValueUpdateRequest)6 Filter (org.hypertrace.core.documentstore.query.Filter)6