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");
}
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");
}
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");
}
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());
}
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;
}
Aggregations