diff options
author | Jon Bratseth <bratseth@oath.com> | 2020-11-04 10:12:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 10:12:53 +0100 |
commit | bc6d4f82be7c1a34416aa7e07109196b571847f9 (patch) | |
tree | 3d28a96cd4c14743364064cf826ad9a356ee32fb /searchlib | |
parent | 7174c66847a43d6f4aab7d611f47283bf665df28 (diff) | |
parent | 432d35c0d4cc761c6739e63de5dbb6197a369a3d (diff) |
Merge pull request #15135 from vespa-engine/bratseth/median-aggregator
Add median aggregator
Diffstat (limited to 'searchlib')
3 files changed, 15 insertions, 9 deletions
diff --git a/searchlib/abi-spec.json b/searchlib/abi-spec.json index aca88ff864e..88eccb4559f 100644 --- a/searchlib/abi-spec.json +++ b/searchlib/abi-spec.json @@ -1049,10 +1049,11 @@ "public static final int ARGMIN", "public static final int AVG", "public static final int COUNT", - "public static final int PROD", - "public static final int SUM", "public static final int MAX", + "public static final int MEDIAN", "public static final int MIN", + "public static final int PROD", + "public static final int SUM", "public static final int IDENTIFIER", "public static final int SINGLE_LINE_COMMENT", "public static final int DEFAULT", diff --git a/searchlib/src/main/javacc/RankingExpressionParser.jj b/searchlib/src/main/javacc/RankingExpressionParser.jj index 5f27bbcbeee..09880b8dfc3 100755 --- a/searchlib/src/main/javacc/RankingExpressionParser.jj +++ b/searchlib/src/main/javacc/RankingExpressionParser.jj @@ -144,10 +144,11 @@ TOKEN : <AVG: "avg" > | <COUNT: "count"> | - <PROD: "prod"> | - <SUM: "sum"> | <MAX: "max"> | + <MEDIAN: "median"> | <MIN: "min"> | + <PROD: "prod"> | + <SUM: "sum"> | <IDENTIFIER: (["A"-"Z","a"-"z","0"-"9","_","@"](["A"-"Z","a"-"z","0"-"9","_","@","$"])*)> } @@ -630,7 +631,7 @@ Reduce.Aggregator tensorReduceAggregator() : { } { - ( <AVG> | <COUNT> | <PROD> | <SUM> | <MAX> | <MIN> ) + ( <AVG> | <COUNT> | <MAX> | <MEDIAN> | <MIN> | <PROD> | <SUM> ) { return Reduce.Aggregator.valueOf(token.image); } } diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/EvaluationTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/EvaluationTestCase.java index f1c421f6c22..1bf4dc5698d 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/EvaluationTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/EvaluationTestCase.java @@ -194,14 +194,16 @@ public class EvaluationTestCase { "reduce(tensor0, avg, x, y)", "{ {x:0,y:0}:1.0, {x:1,y:0}:3.0, {x:0,y:1}:5.0, {x:1,y:1}:7.0 }"); tester.assertEvaluates("{ {}:4 }", "reduce(tensor0, count, x, y)", "{ {x:0,y:0}:1.0, {x:1,y:0}:3.0, {x:0,y:1}:5.0, {x:1,y:1}:7.0 }"); - tester.assertEvaluates("{ {}:105 }", - "reduce(tensor0, prod, x, y)", "{ {x:0,y:0}:1.0, {x:1,y:0}:3.0, {x:0,y:1}:5.0, {x:1,y:1}:7.0 }"); - tester.assertEvaluates("{ {}:16 }", - "reduce(tensor0, sum, x, y)", "{ {x:0,y:0}:1.0, {x:1,y:0}:3.0, {x:0,y:1}:5.0, {x:1,y:1}:7.0 }"); tester.assertEvaluates("{ {}:7 }", "reduce(tensor0, max, x, y)", "{ {x:0,y:0}:1.0, {x:1,y:0}:3.0, {x:0,y:1}:5.0, {x:1,y:1}:7.0 }"); + tester.assertEvaluates("{ {}:4 }", + "reduce(tensor0, median, x, y)", "{ {x:0,y:0}:1.0, {x:1,y:0}:3.0, {x:0,y:1}:5.0, {x:1,y:1}:7.0 }"); tester.assertEvaluates("{ {}:1 }", "reduce(tensor0, min, x, y)", "{ {x:0,y:0}:1.0, {x:1,y:0}:3.0, {x:0,y:1}:5.0, {x:1,y:1}:7.0 }"); + tester.assertEvaluates("{ {}:105 }", + "reduce(tensor0, prod, x, y)", "{ {x:0,y:0}:1.0, {x:1,y:0}:3.0, {x:0,y:1}:5.0, {x:1,y:1}:7.0 }"); + tester.assertEvaluates("{ {}:16 }", + "reduce(tensor0, sum, x, y)", "{ {x:0,y:0}:1.0, {x:1,y:0}:3.0, {x:0,y:1}:5.0, {x:1,y:1}:7.0 }"); // -- reduce 2 by specifying no arguments tester.assertEvaluates("{ {}:4 }", "reduce(tensor0, avg)", "{ {x:0,y:0}:1.0, {x:1,y:0}:3.0, {x:0,y:1}:5.0, {x:1,y:1}:7.0 }"); @@ -223,6 +225,8 @@ public class EvaluationTestCase { tester.assertEvaluates("{ {}:-5 }", "sum(tensor0)", "-5.0"); tester.assertEvaluates("{ {}:12.5 }", "sum(tensor0)", "{ {d1:0}:5.5, {d1:1}:7.0 }"); tester.assertEvaluates("{ {}: 0 }", "sum(tensor0)", "{ {d1:0}:5.0, {d1:1}:7.0, {d1:2}:-12.0}"); + tester.assertEvaluates("{ {}: 8.0 }", "avg(tensor0)", "{ {d1:0}:5.0, {d1:1}:7.0, {d1:2}:12.0}"); + tester.assertEvaluates("{ {}: 5.0 }", "median(tensor0)", "{ {d1:0}:5.0, {d1:1}:7.0, {d1:2}:-12.0}"); tester.assertEvaluates("{ {y:0}:4, {y:1}:12.0 }", "sum(tensor0, x)", "{ {x:0,y:0}:1.0, {x:1,y:0}:3.0, {x:0,y:1}:5.0, {x:1,y:1}:7.0 }"); tester.assertEvaluates("{ {x:0}:6, {x:1}:10.0 }", |