Skip to content

Commit

Permalink
EN-51893 | CHORE : Adding Last aggregation operator (#215)
Browse files Browse the repository at this point in the history
* Adding ast aggregation operator

* added integration tests

* resolved comments

* minor fix
  • Loading branch information
singh-viikram authored Oct 18, 2024
1 parent 1af3457 commit 0723c9d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
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",
"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

0 comments on commit 0723c9d

Please sign in to comment.