Expose output of SetWindowFieldsOperation correctly to next aggregation stage.
This commit makes sure to expose calculated output fields correctly. Original pull request #4751 Closes #4745
This commit is contained in:
committed by
Mark Paluch
parent
bc590956a9
commit
fffd2ef9b7
@@ -70,7 +70,7 @@ public class SetWindowFieldsOperation
|
||||
|
||||
@Override
|
||||
public ExposedFields getFields() {
|
||||
return ExposedFields.nonSynthetic(Fields.from(output.fields.toArray(new Field[0])));
|
||||
return ExposedFields.synthetic(Fields.from(output.fields.toArray(new Field[0])));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -73,6 +73,29 @@ class SetWindowFieldsOperationTests {
|
||||
238, 378);
|
||||
}
|
||||
|
||||
@Test // GH-4745
|
||||
void exposesFieldsToNextStageCorrectly() {
|
||||
|
||||
initCakeSales();
|
||||
|
||||
SetWindowFieldsOperation setWindowFieldsOperation = SetWindowFieldsOperation.builder() //
|
||||
.partitionByField("state") // resolves to field ref "$state"
|
||||
.sortBy(Sort.by(Direction.ASC, "date")) // resolves to "orderDate"
|
||||
.output(AccumulatorOperators.valueOf("qty").sum()) // resolves to "$quantity"
|
||||
.within(Windows.documents().fromUnbounded().toCurrent().build()) //
|
||||
.as("cumulativeQuantityForState") //
|
||||
.build(); //
|
||||
|
||||
AggregationResults<Document> results = mongoTemplate.aggregateAndReturn(Document.class)
|
||||
.by(Aggregation.newAggregation(CakeSale.class, setWindowFieldsOperation,
|
||||
/* and now project on the field to see it can be referenced */
|
||||
Aggregation.project("cumulativeQuantityForState")))
|
||||
.all();
|
||||
|
||||
assertThat(results.getMappedResults()).map(it -> it.get("cumulativeQuantityForState")).contains(162, 282, 427, 134,
|
||||
238, 378);
|
||||
}
|
||||
|
||||
@Test // GH-3711
|
||||
void executesSetWindowFieldsOperationWithPartitionExpressionCorrectly() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user