DATAMONGO-1756 - Fix nested field name resolution for arithmetic aggregation ops.
Original pull request: #491.
This commit is contained in:
committed by
Mark Paluch
parent
f2e72fe931
commit
e8ae928e74
@@ -1407,7 +1407,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
protected List<Object> getOperationArguments(AggregationOperationContext context) {
|
||||
|
||||
List<Object> result = new ArrayList<Object>(values.size());
|
||||
result.add(context.getReference(getField().getName()).toString());
|
||||
result.add(context.getReference(getField()).toString());
|
||||
|
||||
for (Object element : values) {
|
||||
|
||||
|
||||
@@ -559,6 +559,16 @@ public class AggregationUnitTests {
|
||||
assertThat(getAsDocument(fields, "foosum"), isBsonObject().containing("$first.$cond.else", "no-answer"));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1756
|
||||
public void projectOperationShouldRenderNestedFieldNamesCorrectly() {
|
||||
|
||||
Document agg = newAggregation(project().and("value1.value").plus("value2.value").as("val")).toDocument("collection",
|
||||
Aggregation.DEFAULT_CONTEXT);
|
||||
|
||||
assertThat(extractPipelineElement(agg, 0, "$project"),
|
||||
is(equalTo(new Document("val", new Document("$add", Arrays.asList("$value1.value", "$value2.value"))))));
|
||||
}
|
||||
|
||||
private Document extractPipelineElement(Document agg, int index, String operation) {
|
||||
|
||||
List<Document> pipeline = (List<Document>) agg.get("pipeline");
|
||||
|
||||
@@ -338,6 +338,18 @@ public class TypeBasedAggregationOperationContextUnitTests {
|
||||
assertThat(age, isBsonObject().containing("$ifNull.[1]._class", Age.class.getName()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1756
|
||||
public void projectOperationShouldRenderNestedFieldNamesCorrectlyForTypedAggregation() {
|
||||
|
||||
AggregationOperationContext context = getContext(Wrapper.class);
|
||||
|
||||
Document agg = newAggregation(Wrapper.class, project().and("nested1.value1").plus("nested2.value2").as("val"))
|
||||
.toDocument("collection", context);
|
||||
|
||||
assertThat(getPipelineElementFromAggregationAt(agg, 0).get("$project"), is(
|
||||
equalTo(new Document("val", new Document("$add", Arrays.asList("$nested1.value1", "$field2.nestedValue2"))))));
|
||||
}
|
||||
|
||||
@org.springframework.data.mongodb.core.mapping.Document(collection = "person")
|
||||
public static class FooPerson {
|
||||
|
||||
@@ -408,4 +420,15 @@ public class TypeBasedAggregationOperationContextUnitTests {
|
||||
|
||||
String name;
|
||||
}
|
||||
|
||||
static class Wrapper {
|
||||
|
||||
Nested nested1;
|
||||
@org.springframework.data.mongodb.core.mapping.Field("field2") Nested nested2;
|
||||
}
|
||||
|
||||
static class Nested {
|
||||
String value1;
|
||||
@org.springframework.data.mongodb.core.mapping.Field("nestedValue2") String value2;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user