summaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-07-14 12:09:09 +0200
committerJon Bratseth <bratseth@gmail.com>2022-07-14 12:09:09 +0200
commitf77b2641cea9d51ceb2f4cfa13eb3dd8571b2161 (patch)
tree2aaddbdfd614f158121b88e4c9396abca9c3365b /container-search/src/test/java/com
parentb60757392ea4d007412581adcd5d7d6be94a1540 (diff)
Carry over parameters when grouping from YQL
Diffstat (limited to 'container-search/src/test/java/com')
-rw-r--r--container-search/src/test/java/com/yahoo/search/grouping/vespa/RequestBuilderTestCase.java23
-rw-r--r--container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java32
2 files changed, 52 insertions, 3 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/grouping/vespa/RequestBuilderTestCase.java b/container-search/src/test/java/com/yahoo/search/grouping/vespa/RequestBuilderTestCase.java
index cfcbc435ba5..5882c56c688 100644
--- a/container-search/src/test/java/com/yahoo/search/grouping/vespa/RequestBuilderTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/grouping/vespa/RequestBuilderTestCase.java
@@ -784,6 +784,16 @@ public class RequestBuilderTestCase {
}
@Test
+ public void require_that_total_groups_restriction_can_be_disabled() {
+ assertTotalGroupsAndSummaries(3+3*5+3*5*7+3*5*7*100,
+ -1, // disable
+ "all( group(a) max(3) each(output(count())" +
+ " all(group(b) max(5) each(output(count())" +
+ " all(group(c) max(7) each(max(100) output(count())" +
+ " each(output(summary()))))))))");
+ }
+
+ @Test
public void require_that_unbounded_queries_fails_when_global_max_is_enabled() {
assertQueryFailsOnGlobalMax(4, "all(group(a) max(5) each(output(count())))", "5 > 4");
assertQueryFailsOnGlobalMax(Long.MAX_VALUE, "all(group(a) each(output(count())))", "unbounded number of groups");
@@ -810,10 +820,15 @@ public class RequestBuilderTestCase {
}
private static void assertTotalGroupsAndSummaries(long expected, String query) {
+ assertTotalGroupsAndSummaries(expected, Long.MAX_VALUE, query);
+ }
+
+ private static void assertTotalGroupsAndSummaries(long expected, long globalMaxGroups, String query) {
RequestBuilder builder = new RequestBuilder(0)
- .setRootOperation(GroupingOperation.fromString(query)).setGlobalMaxGroups(Long.MAX_VALUE);
+ .setRootOperation(GroupingOperation.fromString(query)).setGlobalMaxGroups(globalMaxGroups);
builder.build();
- assertEquals(expected, builder.totalGroupsAndSummaries().orElseThrow());
+ if (globalMaxGroups >= 0) // otherwise, totalGroupsAndSummaries is not computed
+ assertEquals(expected, builder.totalGroupsAndSummaries().orElseThrow());
}
private static void assertQueryFailsOnGlobalMax(long globalMax, String query, String errorSubstring) {
@@ -938,11 +953,13 @@ public class RequestBuilderTestCase {
String expectedOutput;
OutputWriter outputWriter;
Continuation continuation;
+
}
- private static interface OutputWriter {
+ private interface OutputWriter {
String write(List<Grouping> groupingList, GroupingTransform transform);
+
}
private static class OffsetWriter implements OutputWriter {
diff --git a/container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java b/container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java
index 890f847ebfe..1ef9fe5832f 100644
--- a/container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java
@@ -5,6 +5,7 @@ import com.google.common.base.Charsets;
import com.yahoo.component.chain.Chain;
import com.yahoo.language.Language;
import com.yahoo.language.simple.SimpleLinguistics;
+import com.yahoo.processing.IllegalInputException;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
import com.yahoo.search.Searcher;
@@ -29,6 +30,7 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Smoke test for first generation YQL+ integration.
@@ -350,6 +352,36 @@ public class MinimalQueryInserterTestCase {
}
@Test
+ public void globalMaxGroupsIsCarriedOver() {
+ URIBuilder builder = new URIBuilder();
+ builder.setPath("search/");
+ builder.setParameter("yql", "select foo from bar where baz contains 'cox' " +
+ "| all(group(a) each(output(count())))");
+ Query query = new Query(builder.toString());
+ query.properties().set("grouping.globalMaxGroups", -1);
+ execution.search(query);
+ assertEquals(1, query.getSelect().getGrouping().size());
+ assertEquals(-1L, query.getSelect().getGrouping().get(0).globalMaxGroups().getAsLong());
+ }
+
+ @Test
+ public void globalMaxGroupsCannotBeSetInRequest() {
+ try {
+ URIBuilder builder = new URIBuilder();
+ builder.setPath("search/");
+ builder.setParameter("yql", "select foo from bar where baz contains 'cox' " +
+ "| all(group(a) each(output(count())))");
+ builder.setParameter("grouping.globalMaxGroups", "-1");
+ Query query = new Query(builder.toString());
+ execution.search(query);
+ fail();
+ }
+ catch (IllegalInputException e) {
+ assertEquals("grouping.globalMaxGroups must be specified in a query profile.", e.getCause().getMessage());
+ }
+ }
+
+ @Test
public void verifyThatWarmupIsSane() {
assertTrue(MinimalQueryInserter.warmup());
}