aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-02-17 16:09:15 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2023-02-17 16:09:15 +0100
commit9989efa858ed434c8d1a2bf102fd8ba232010df7 (patch)
tree29a2540a408f9511cfd74c4817ecca0a965c506c
parentd01cbe25a8e0d7fa4b7c9783ff5518d277519342 (diff)
Enforce backend limitations when building the query.
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/aggregation/Group.java9
1 files changed, 8 insertions, 1 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/aggregation/Group.java b/searchlib/src/main/java/com/yahoo/searchlib/aggregation/Group.java
index 3054f53e7b3..0b629d43446 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/aggregation/Group.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/aggregation/Group.java
@@ -15,12 +15,13 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
-import java.util.stream.Collectors;
public class Group extends Identifiable {
public static final int classId = registerClass(0x4000 + 90, Group.class);
private static final ObjectPredicate REF_LOCATOR = new RefLocator();
+ private static final int MAX_AGGREGATIONS = 0x10000; // Backend limitation
+ private static final int MAX_ORDERBY_EXPRESSIONS = 8; // Backend limitation
private List<Integer> orderByIdx = List.of();
private List<ExpressionNode> orderByExp = List.of();
private List<AggregationResult> aggregationResults = List.of();
@@ -274,6 +275,9 @@ public class Group extends Identifiable {
* @return this, to allow chaining
*/
public Group addAggregationResult(AggregationResult result) {
+ if (aggregationResults.size() >= MAX_AGGREGATIONS) {
+ throw new IllegalArgumentException("You have reached the limit for number of aggregations of " + MAX_AGGREGATIONS);
+ }
aggregationResults = add(aggregationResults, result);
return this;
}
@@ -288,6 +292,9 @@ public class Group extends Identifiable {
* @return this, to allow chaining
*/
public Group addOrderBy(ExpressionNode exp, boolean asc) {
+ if (orderByExp.size() >= MAX_ORDERBY_EXPRESSIONS) {
+ throw new IllegalArgumentException("You have reached the limit for number of orderby expressions of " + MAX_ORDERBY_EXPRESSIONS);
+ }
if (exp instanceof AggregationResult) {
exp = new AggregationRefNode((AggregationResult)exp);
}