Add expression support for median aggregation.
Original Pull Request: #4515
This commit is contained in:
@@ -231,6 +231,8 @@ public class MethodReferenceNode extends ExpressionNode {
|
||||
.mappingParametersTo("n", "input"));
|
||||
map.put("percentile", mapArgRef().forOperator("$percentile") //
|
||||
.mappingParametersTo("input", "p", "method"));
|
||||
map.put("median", mapArgRef().forOperator("$median") //
|
||||
.mappingParametersTo("input", "method"));
|
||||
|
||||
// TYPE OPERATORS
|
||||
map.put("type", singleArgRef().forOperator("$type"));
|
||||
|
||||
@@ -1269,6 +1269,16 @@ public class SpelExpressionTransformerUnitTests {
|
||||
.isEqualTo("{ $percentile : { input : \"$score\", p : [0.4, 0.85], method : \"approximate\" }}");
|
||||
}
|
||||
|
||||
@Test // GH-4472
|
||||
void shouldRenderMedian() {
|
||||
|
||||
assertThat(transform("median(new String[]{\"$scoreOne\", \"$scoreTwo\" }, \"approximate\")"))
|
||||
.isEqualTo("{ $median : { input : [\"$scoreOne\", \"$scoreTwo\"], method : \"approximate\" }}");
|
||||
|
||||
assertThat(transform("median(score, \"approximate\")"))
|
||||
.isEqualTo("{ $median : { input : \"$score\", method : \"approximate\" }}");
|
||||
}
|
||||
|
||||
private Document transform(String expression, Object... params) {
|
||||
return (Document) transformer.transform(expression, Aggregation.DEFAULT_CONTEXT, params);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user