Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.COUNT;
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.DISTINCT_ARRAY;
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.DISTINCT_COUNT;
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.LAST;
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.MAX;
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.MIN;
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.SUM;
Expand Down Expand Up @@ -1334,6 +1335,24 @@ public void testQueryV1AggregationFilterWithWhereClause(String dataStoreName) th
dataStoreName, resultDocs, "query/test_aggr_filter_and_where_filter_result.json", 2);
}

@ParameterizedTest
@ArgumentsSource(MongoProvider.class)
public void testQueryV1LastAggregationOperator(String dataStoreName) throws IOException {
Collection collection = getCollection(dataStoreName);

org.hypertrace.core.documentstore.query.Query query =
org.hypertrace.core.documentstore.query.Query.builder()
.addSelection(IdentifierExpression.of("item"))
.addAggregation(IdentifierExpression.of("item"))
.addSelection(
AggregateExpression.of(LAST, IdentifierExpression.of("price")), "last_price")
.build();

Iterator<Document> resultDocs = collection.aggregate(query);
assertDocsAndSizeEqualWithoutOrder(
dataStoreName, resultDocs, "query/test_last_aggregation_operator.json", 4);
}

@Nested
class StartsWithOperatorTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"quantity": 2,
"date": "2014-03-01T08:00:00Z",
"props": {
"colors": ["Blue", "Green"],
"colors": [
"Blue",
"Green"
],
"brand": "Dettol",
"size": "M",
"seller": {
Expand Down Expand Up @@ -70,7 +73,9 @@
"quantity": 10,
"date": "2014-03-15T09:00:00Z",
"props": {
"colors": ["Black"],
"colors": [
"Black"
],
"brand": "Sunsilk",
"size": "L",
"seller": {
Expand Down Expand Up @@ -133,7 +138,10 @@
"quantity": 5,
"date": "2014-04-04T21:23:13.331Z",
"props": {
"colors": ["Orange", "Blue"],
"colors": [
"Orange",
"Blue"
],
"brand": "Lifebuoy",
"size": "S",
"seller": {
Expand Down Expand Up @@ -176,4 +184,4 @@
"quantity": 5,
"date": "2016-02-06T20:20:13Z"
}
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"item":"Shampoo",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could you please prettify the JSON (specifically spaces before the values)?

Suggested change
"item":"Shampoo",
"item": "Shampoo",

"last_price":5
},
{
"item":"Comb",
"last_price":7.5
},
{
"item":"Mirror",
"last_price":20
},
{
"item":"Soap",
"last_price":20
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public enum AggregationOperator {
SUM,
MIN,
MAX,
LAST,
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.COUNT;
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.DISTINCT;
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.DISTINCT_ARRAY;
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.LAST;
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.MAX;
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.MIN;
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.SUM;
Expand All @@ -30,6 +31,7 @@ final class MongoAggregateExpressionParser extends MongoSelectTypeExpressionPars
put(MIN, "$min");
put(MAX, "$max");
put(COUNT, "$push");
put(LAST, "$last");
}
});

Expand Down
Loading