Skip to content

Commit 0723c9d

Browse files
EN-51893 | CHORE : Adding Last aggregation operator (#215)
* Adding ast aggregation operator * added integration tests * resolved comments * minor fix
1 parent 1af3457 commit 0723c9d

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

document-store/src/integrationTest/java/org/hypertrace/core/documentstore/DocStoreQueryV1Test.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.COUNT;
1212
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.DISTINCT_ARRAY;
1313
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.DISTINCT_COUNT;
14+
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.LAST;
1415
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.MAX;
1516
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.MIN;
1617
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.SUM;
@@ -1334,6 +1335,24 @@ public void testQueryV1AggregationFilterWithWhereClause(String dataStoreName) th
13341335
dataStoreName, resultDocs, "query/test_aggr_filter_and_where_filter_result.json", 2);
13351336
}
13361337

1338+
@ParameterizedTest
1339+
@ArgumentsSource(MongoProvider.class)
1340+
public void testQueryV1LastAggregationOperator(String dataStoreName) throws IOException {
1341+
Collection collection = getCollection(dataStoreName);
1342+
1343+
org.hypertrace.core.documentstore.query.Query query =
1344+
org.hypertrace.core.documentstore.query.Query.builder()
1345+
.addSelection(IdentifierExpression.of("item"))
1346+
.addAggregation(IdentifierExpression.of("item"))
1347+
.addSelection(
1348+
AggregateExpression.of(LAST, IdentifierExpression.of("price")), "last_price")
1349+
.build();
1350+
1351+
Iterator<Document> resultDocs = collection.aggregate(query);
1352+
assertDocsAndSizeEqualWithoutOrder(
1353+
dataStoreName, resultDocs, "query/test_last_aggregation_operator.json", 4);
1354+
}
1355+
13371356
@Nested
13381357
class StartsWithOperatorTest {
13391358

document-store/src/integrationTest/resources/query/collection_data.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"quantity": 2,
77
"date": "2014-03-01T08:00:00Z",
88
"props": {
9-
"colors": ["Blue", "Green"],
9+
"colors": [
10+
"Blue",
11+
"Green"
12+
],
1013
"brand": "Dettol",
1114
"size": "M",
1215
"seller": {
@@ -70,7 +73,9 @@
7073
"quantity": 10,
7174
"date": "2014-03-15T09:00:00Z",
7275
"props": {
73-
"colors": ["Black"],
76+
"colors": [
77+
"Black"
78+
],
7479
"brand": "Sunsilk",
7580
"size": "L",
7681
"seller": {
@@ -133,7 +138,10 @@
133138
"quantity": 5,
134139
"date": "2014-04-04T21:23:13.331Z",
135140
"props": {
136-
"colors": ["Orange", "Blue"],
141+
"colors": [
142+
"Orange",
143+
"Blue"
144+
],
137145
"brand": "Lifebuoy",
138146
"size": "S",
139147
"seller": {
@@ -176,4 +184,4 @@
176184
"quantity": 5,
177185
"date": "2016-02-06T20:20:13Z"
178186
}
179-
]
187+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"item":"Shampoo",
4+
"last_price":5
5+
},
6+
{
7+
"item":"Comb",
8+
"last_price":7.5
9+
},
10+
{
11+
"item":"Mirror",
12+
"last_price":20
13+
},
14+
{
15+
"item":"Soap",
16+
"last_price":20
17+
}
18+
]

document-store/src/main/java/org/hypertrace/core/documentstore/expression/operators/AggregationOperator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ public enum AggregationOperator {
1111
SUM,
1212
MIN,
1313
MAX,
14+
LAST,
1415
}

document-store/src/main/java/org/hypertrace/core/documentstore/mongo/query/parser/MongoAggregateExpressionParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.COUNT;
66
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.DISTINCT;
77
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.DISTINCT_ARRAY;
8+
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.LAST;
89
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.MAX;
910
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.MIN;
1011
import static org.hypertrace.core.documentstore.expression.operators.AggregationOperator.SUM;
@@ -30,6 +31,7 @@ final class MongoAggregateExpressionParser extends MongoSelectTypeExpressionPars
3031
put(MIN, "$min");
3132
put(MAX, "$max");
3233
put(COUNT, "$push");
34+
put(LAST, "$last");
3335
}
3436
});
3537

0 commit comments

Comments
 (0)