aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne H Juul <arnej27959@users.noreply.github.com>2022-02-15 18:10:46 +0100
committerGitHub <noreply@github.com>2022-02-15 18:10:46 +0100
commit2ebbc783aa190ea40aac166638f01cfc58a00c91 (patch)
tree5502b210ff0d11c94fb40910b5985d15ed8e286d
parentf21d76a13a8c569897643293a984374ae08e3a3e (diff)
parentd030467ed4b417c910bfb063a5e77e4a49553d82 (diff)
Merge pull request #21195 from vespa-engine/bratseth/allow-quoted-string-slice-labels
Allow quoted string slice labels
-rw-r--r--config-model/src/test/derived/slice/query-profiles/default.xml3
-rw-r--r--config-model/src/test/derived/slice/query-profiles/types/DefaultQueryProfileType.xml4
-rw-r--r--config-model/src/test/derived/slice/test.sd21
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/SliceTestCase.java27
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/expression/ConstantNode.java4
-rwxr-xr-xsearchlib/src/main/javacc/RankingExpressionParser.jj12
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/TypeResolver.java4
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/functions/Slice.java5
8 files changed, 66 insertions, 14 deletions
diff --git a/config-model/src/test/derived/slice/query-profiles/default.xml b/config-model/src/test/derived/slice/query-profiles/default.xml
new file mode 100644
index 00000000000..2535ca895ed
--- /dev/null
+++ b/config-model/src/test/derived/slice/query-profiles/default.xml
@@ -0,0 +1,3 @@
+<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<query-profile id="default" type="DefaultQueryProfileType">
+</query-profile>
diff --git a/config-model/src/test/derived/slice/query-profiles/types/DefaultQueryProfileType.xml b/config-model/src/test/derived/slice/query-profiles/types/DefaultQueryProfileType.xml
new file mode 100644
index 00000000000..50970d8743f
--- /dev/null
+++ b/config-model/src/test/derived/slice/query-profiles/types/DefaultQueryProfileType.xml
@@ -0,0 +1,4 @@
+<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<query-profile-type id="DefaultQueryProfileType" inherits="native">
+ <field name="ranking.features.query(myTensor)" type="tensor&lt;float&gt;(key{})" />
+</query-profile-type>
diff --git a/config-model/src/test/derived/slice/test.sd b/config-model/src/test/derived/slice/test.sd
new file mode 100644
index 00000000000..fbb581d1b1d
--- /dev/null
+++ b/config-model/src/test/derived/slice/test.sd
@@ -0,0 +1,21 @@
+search test {
+
+ document test {
+ }
+
+ rank-profile parent {
+
+ function inline cpmScore() {
+ expression: myValue * mySlice(query(myTensor))
+ }
+
+ function inline myValue() {
+ expression: 4
+ }
+
+ function inline mySlice(myTensor) {
+ expression: myTensor{"NULL"}
+ }
+ }
+
+} \ No newline at end of file
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/SliceTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/SliceTestCase.java
new file mode 100644
index 00000000000..e6c7efd7052
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/SliceTestCase.java
@@ -0,0 +1,27 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.searchdefinition.derived;
+
+import com.yahoo.component.ComponentId;
+import com.yahoo.search.Query;
+import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
+import com.yahoo.search.query.profile.config.QueryProfileConfigurer;
+import com.yahoo.searchdefinition.parser.ParseException;
+import com.yahoo.vespa.model.container.search.QueryProfiles;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author bratseth
+ */
+public class SliceTestCase extends AbstractExportingTestCase {
+
+ @Test
+ public void testSlice() throws IOException, ParseException {
+ ComponentId.resetGlobalCountersForTests();
+ DerivedConfiguration c = assertCorrectDeriving("slice");
+ }
+
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/expression/ConstantNode.java b/searchlib/src/main/java/com/yahoo/searchlib/expression/ConstantNode.java
index 2bab10d1830..e26900ac77e 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/expression/ConstantNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/expression/ConstantNode.java
@@ -16,9 +16,7 @@ public class ConstantNode extends ExpressionNode {
public static final int classId = registerClass(0x4000 + 49, ConstantNode.class);
private ResultNode value = null;
- public ConstantNode() {
-
- }
+ public ConstantNode() {}
public ConstantNode(ResultNode value) {
this.value = value;
diff --git a/searchlib/src/main/javacc/RankingExpressionParser.jj b/searchlib/src/main/javacc/RankingExpressionParser.jj
index 0d46ab4ddb6..865820320d8 100755
--- a/searchlib/src/main/javacc/RankingExpressionParser.jj
+++ b/searchlib/src/main/javacc/RankingExpressionParser.jj
@@ -1032,11 +1032,13 @@ Slice.DimensionValue dimensionValue(Optional dimensionName) :
{
value = expression()
{
- if (value instanceof ReferenceNode && ((ReferenceNode)value).reference().isIdentifier())
- return new Slice.DimensionValue(dimensionName, ((ReferenceNode)value).reference().name());
- else
- return new Slice.DimensionValue(dimensionName, TensorFunctionNode.wrapScalar(value));
-}
+ if (value instanceof ReferenceNode && ((ReferenceNode)value).reference().isIdentifier()) // A label
+ return new Slice.DimensionValue(dimensionName, ((ReferenceNode)value).reference().name());
+ else if (value instanceof ConstantNode && ((ConstantNode)value).getValue() instanceof StringValue) // A quoted label
+ return new Slice.DimensionValue(dimensionName, ((StringValue)((ConstantNode)value).getValue()).asString());
+ else
+ return new Slice.DimensionValue(dimensionName, TensorFunctionNode.wrapScalar(value));
+ }
}
String label() :
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TypeResolver.java b/vespajlib/src/main/java/com/yahoo/tensor/TypeResolver.java
index dad93734b22..457cfcbfa5f 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/TypeResolver.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/TypeResolver.java
@@ -2,13 +2,9 @@
package com.yahoo.tensor;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.yahoo.tensor.TensorType.Dimension;
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Slice.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Slice.java
index a6f71dacf30..09bfb8b996b 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Slice.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Slice.java
@@ -121,14 +121,13 @@ public class Slice<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETY
private TensorType resultType(TensorType argumentType) {
List<String> peekDimensions;
-
// Special case where a single indexed or mapped dimension is sliced
if (subspaceAddress.size() == 1 && subspaceAddress.get(0).dimension().isEmpty()) {
if (subspaceAddress.get(0).index().isPresent()) {
peekDimensions = findDimensions(argumentType.dimensions(), TensorType.Dimension::isIndexed);
if (peekDimensions.size() > 1) {
throw new IllegalArgumentException(this + " slices a single indexed dimension, cannot be applied " +
- "to " + argumentType + ", which has multiple");
+ "to " + argumentType + ", which has multiple");
}
}
else {
@@ -141,6 +140,8 @@ public class Slice<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETY
else { // general slicing
peekDimensions = subspaceAddress.stream().map(d -> d.dimension().get()).collect(Collectors.toList());
}
+ if (peekDimensions.isEmpty())
+ throw new IllegalArgumentException(this + " cannot slice " + argumentType + ": No dimensions to slice");
return TypeResolver.peek(argumentType, peekDimensions);
}