summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@vespa.ai>2024-06-12 12:10:08 +0200
committerJon Bratseth <bratseth@vespa.ai>2024-06-12 12:10:08 +0200
commit39be0cc157341ee119ae7aea4b3c28d51cf4e270 (patch)
treec9901e20d08d84e26cee3564d34fbb4cb2c4675d
parent011b3aa45a2a92714d88c80dcb1b87b63f6d078a (diff)
Support setting 'select' in a query profile
-rw-r--r--container-search/abi-spec.json1
-rw-r--r--container-search/src/main/java/com/yahoo/search/Query.java9
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/Select.java4
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/hitfield/test/JSONStringTestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/query/ItemHelperTestCase.java1
-rw-r--r--container-search/src/test/java/com/yahoo/search/dispatch/TopKEstimatorTest.java2
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java1
-rw-r--r--container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java18
-rw-r--r--vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java26
9 files changed, 54 insertions, 15 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json
index 8fbf12b16b4..afaf449a432 100644
--- a/container-search/abi-spec.json
+++ b/container-search/abi-spec.json
@@ -2119,6 +2119,7 @@
"public com.yahoo.search.Query clone()",
"public com.yahoo.search.query.Presentation getPresentation()",
"public com.yahoo.search.query.Select getSelect()",
+ "public void setSelect(java.lang.String)",
"public com.yahoo.search.query.Ranking getRanking()",
"public com.yahoo.search.query.Model getModel()",
"public com.yahoo.search.query.Trace getTrace()",
diff --git a/container-search/src/main/java/com/yahoo/search/Query.java b/container-search/src/main/java/com/yahoo/search/Query.java
index e01d03e96a7..8e0897b866f 100644
--- a/container-search/src/main/java/com/yahoo/search/Query.java
+++ b/container-search/src/main/java/com/yahoo/search/Query.java
@@ -384,9 +384,11 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
// We need special handling for "select" because it can be both the prefix of the nested JSON select
// parameters, and a plain select expression. The latter will be disallowed by query profile types
// since they contain the former.
- String select = requestMap.get(Select.SELECT);
+ Object select = requestMap.get(Select.SELECT);
+ if (select == null)
+ select = queryProfile.get(Select.SELECT, requestMap);
if (select != null)
- properties().set(Select.SELECT, select);
+ properties().set(Select.SELECT, select.toString());
}
else { // bypass these complications if there is no query profile to get values from and validate against
properties().
@@ -906,6 +908,9 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
/** Returns the select to be used for this query, never null */
public Select getSelect() { return select; }
+ /** Sets the select (grouping) parameter from a string. */
+ public void setSelect(String groupingString) { select.setGroupingExpressionString(groupingString); }
+
/** Returns the ranking to be used for this query, never null */
public Ranking getRanking() { return ranking; }
diff --git a/container-search/src/main/java/com/yahoo/search/query/Select.java b/container-search/src/main/java/com/yahoo/search/query/Select.java
index 6735a6bd050..38ef7b8f190 100644
--- a/container-search/src/main/java/com/yahoo/search/query/Select.java
+++ b/container-search/src/main/java/com/yahoo/search/query/Select.java
@@ -115,9 +115,7 @@ public class Select implements Cloneable {
public String getGroupingExpressionString() { return groupingExpressionString; }
/** Returns the grouping in the query */
- public String getGroupingString(){
- return grouping;
- }
+ public String getGroupingString() { return grouping; }
/**
* Returns the query's {@link GroupingRequest} as a mutable list. Changing this directly changes the grouping
diff --git a/container-search/src/test/java/com/yahoo/prelude/hitfield/test/JSONStringTestCase.java b/container-search/src/test/java/com/yahoo/prelude/hitfield/test/JSONStringTestCase.java
index cafb79d8542..ca7d5bf6999 100644
--- a/container-search/src/test/java/com/yahoo/prelude/hitfield/test/JSONStringTestCase.java
+++ b/container-search/src/test/java/com/yahoo/prelude/hitfield/test/JSONStringTestCase.java
@@ -740,13 +740,6 @@ public class JSONStringTestCase {
Inspector value5 = new JSONString("{\"foo\":1}").inspect();
Inspector value6 = new JSONString("[1,2,3]").inspect();
- System.out.println("1: " + value1);
- System.out.println("2: " + value2);
- System.out.println("3: " + value3);
- System.out.println("4: " + value4);
- System.out.println("5: " + value5);
- System.out.println("6: " + value6);
-
assertEquals(Type.STRING, value1.type());
assertEquals("", value1.asString());
diff --git a/container-search/src/test/java/com/yahoo/prelude/query/ItemHelperTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/ItemHelperTestCase.java
index 5b20eda4344..5e0da17c186 100644
--- a/container-search/src/test/java/com/yahoo/prelude/query/ItemHelperTestCase.java
+++ b/container-search/src/test/java/com/yahoo/prelude/query/ItemHelperTestCase.java
@@ -34,7 +34,6 @@ public class ItemHelperTestCase {
ItemHelper helper = new ItemHelper();
Query q = new Query("/?query=" + enc("a b c \"d e\" -f"));
List<IndexedItem> l = new ArrayList<>();
- System.out.println(q.getModel());
helper.getPositiveTerms(q.getModel().getQueryTree().getRoot(), l);
assertEquals(4, l.size());
boolean a = false;
diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/TopKEstimatorTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/TopKEstimatorTest.java
index 4cd453746bb..2f36d174ad4 100644
--- a/container-search/src/test/java/com/yahoo/search/dispatch/TopKEstimatorTest.java
+++ b/container-search/src/test/java/com/yahoo/search/dispatch/TopKEstimatorTest.java
@@ -88,7 +88,7 @@ public class TopKEstimatorTest {
@Test
void requireThatLargeKAreSane() {
- System.out.println(dumpProbability(10, 0.05));
+ // System.out.println(dumpProbability(10, 0.05));
TopKEstimator idealEstimator = new TopKEstimator(30, 0.9999);
TopKEstimator skewedEstimator = new TopKEstimator(30, 0.9999, 0.05);
int [] K = {10, 20, 40, 80, 100, 200, 400, 800, 1000, 2000, 4000, 8000, 10000, 20000, 40000, 80000, 100000};
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java
index 357bba0c7b1..7cbd5747d2d 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java
@@ -25,7 +25,6 @@ public class DumpToolTestCase {
@Test
void testNoDimensionValues() {
- System.out.println(new DumpTool().resolveAndDump("multiprofile1", profileDir));
assertTrue(new DumpTool().resolveAndDump("multiprofile1", profileDir).contains("a=general-a\n"));
}
diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
index 6a310180eab..259a79b095b 100644
--- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
@@ -306,6 +306,24 @@ public class QueryTestCase {
assertEquals("Profile: myProfile", q.properties().get("myField"));
}
+ /** Select is special handled due to the strange idea to also use it to contain subproperties with JSON. */
+ @Test
+ void testQueryProfileWithSelect() {
+ String grouping = "all(group(customerid) each(output(count())))";
+
+ { // select in the request
+ QueryProfile profile = new QueryProfile("myProfile");
+ Query q = new Query(QueryTestCase.httpEncode("/search?query=macbook&queryProfile=myProfile&select=" + grouping), profile.compile(null));
+ assertEquals(grouping, q.getSelect().getGroupingExpressionString());
+ }
+ { // select in the query profile
+ QueryProfile profile = new QueryProfile("myProfile");
+ profile.set("select", grouping, null);
+ Query q = new Query(QueryTestCase.httpEncode("/search?query=macbook&queryProfile=myProfile"), profile.compile(null));
+ assertEquals(grouping, q.getSelect().getGroupingExpressionString());
+ }
+ }
+
@Test
void testQueryProfileSourceAccess() {
QueryProfile profile = new QueryProfile("myProfile");
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java
index 3ed8a7237ec..4ab60ecb9b9 100644
--- a/vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java
@@ -2,9 +2,14 @@
package com.yahoo.tensor;
+import com.yahoo.tensor.functions.Reduce;
import org.junit.Test;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -159,4 +164,25 @@ public class MixedTensorTestCase {
tensor.toString());
}
+ @Test
+ public void testSplitIntoDense() {
+ TensorType type = new TensorType.Builder().mapped("key").indexed("x", 3).build();
+ Tensor tensor = MixedTensor.Builder.of(type).
+ cell().label("key", "key1").label("x", 0).value(1).
+ cell().label("key", "key1").label("x", 1).value(2).
+ cell().label("key", "key1").label("x", 2).value(3).
+ cell().label("key", "key2").label("x", 0).value(4).
+ cell().label("key", "key2").label("x", 1).value(5).
+ cell().label("key", "key2").label("x", 2).value(6).
+ build();
+
+ Map<String, Tensor> indexedTensors = new HashMap<>();
+ tensor.sum("x").cellIterator()
+ .forEachRemaining(cell -> indexedTensors.put(cell.getKey().label(0),
+ tensor.multiply(Tensor.Builder.of(type.mappedSubtype()).cell(cell.getKey(), 1.0).build()).sum("key")));
+
+ assertEquals("tensor(x[3]):[1.0, 2.0, 3.0]", indexedTensors.get("key1").toString());
+ assertEquals("tensor(x[3]):[4.0, 5.0, 6.0]", indexedTensors.get("key2").toString());
+ }
+
}