Search in sources :

Example 11 with Document

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

the class MongoQueryExecutorIntegrationTest method testAggregateWithDuplicateSelections.

@Test
public void testAggregateWithDuplicateSelections() throws IOException {
    Query query = Query.builder().addSelection(AggregateExpression.of(COUNT, IdentifierExpression.of("item")), "count").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 12 with Document

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

the class MongoQueryExecutorIntegrationTest method testAggregateWithNestedFields.

@Test
public void testAggregateWithNestedFields() throws IOException {
    Query query = Query.builder().addSelection(IdentifierExpression.of("props.seller.address.pincode"), "pincode.value").addSelection(AggregateExpression.of(SUM, ConstantExpression.of(1)), "num_items.value").addAggregation(IdentifierExpression.of("props.seller.address.pincode")).addSort(IdentifierExpression.of("num_items.value"), DESC).addSort(IdentifierExpression.of("pincode.value"), DESC).setAggregationFilter(RelationalExpression.of(IdentifierExpression.of("num_items.value"), GT, ConstantExpression.of(1))).build();
    Iterator<Document> resultDocs = collection.aggregate(query);
    assertDocsEqual(resultDocs, "mongo/aggregate_on_nested_fields_response.json");
}
Also used : Query(org.hypertrace.core.documentstore.query.Query) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 13 with Document

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

the class MongoQueryExecutorIntegrationTest method testAggregateWithMultipleGroupingLevels.

@Test
public void testAggregateWithMultipleGroupingLevels() throws IOException {
    Query query = Query.builder().addAggregation(IdentifierExpression.of("item")).addAggregation(IdentifierExpression.of("price")).addSelection(IdentifierExpression.of("item")).addSelection(IdentifierExpression.of("price")).addSelection(FunctionExpression.builder().operator(LENGTH).operand(IdentifierExpression.of("quantities")).build(), "num_quantities").addSelection(AggregateExpression.of(DISTINCT, IdentifierExpression.of("quantity")), "quantities").setAggregationFilter(RelationalExpression.of(IdentifierExpression.of("num_quantities"), EQ, ConstantExpression.of(1))).addSort(IdentifierExpression.of("item"), DESC).build();
    Iterator<Document> resultDocs = collection.aggregate(query);
    assertDocsEqual(resultDocs, "mongo/multi_level_grouping_response.json");
}
Also used : Query(org.hypertrace.core.documentstore.query.Query) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 14 with Document

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

the class PostgresDocStoreTest method testUpsertAndReturn.

@Test
public void testUpsertAndReturn() throws IOException {
    Collection collection = datastore.getCollection(COLLECTION_NAME);
    Document document = Utils.createDocument("foo1", "bar1");
    Document resultDocument = collection.upsertAndReturn(new SingleValueKey("default", "testKey"), document);
    Assertions.assertEquals(document.toJson(), resultDocument.toJson());
}
Also used : SingleValueKey(org.hypertrace.core.documentstore.SingleValueKey) Collection(org.hypertrace.core.documentstore.Collection) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 15 with Document

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

the class Utils method createDocumentsFromResource.

public static Map<Key, Document> createDocumentsFromResource(String resourcePath) throws IOException {
    Optional<String> contentOptional = readFileFromResource(resourcePath);
    String json = contentOptional.orElseThrow();
    List<Map<String, Object>> maps = OBJECT_MAPPER.readValue(json, new TypeReference<>() {
    });
    Map<Key, Document> documentMap = new HashMap<>();
    for (Map<String, Object> map : maps) {
        Key key = new SingleValueKey("default", map.get(MongoCollection.ID_KEY).toString());
        Document value = new JSONDocument(map);
        documentMap.put(key, value);
    }
    return documentMap;
}
Also used : HashMap(java.util.HashMap) Document(org.hypertrace.core.documentstore.Document) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) SingleValueKey(org.hypertrace.core.documentstore.SingleValueKey) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) HashMap(java.util.HashMap) Map(java.util.Map) Key(org.hypertrace.core.documentstore.Key) SingleValueKey(org.hypertrace.core.documentstore.SingleValueKey)

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