summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2021-05-11 15:53:57 +0200
committerGitHub <noreply@github.com>2021-05-11 15:53:57 +0200
commit6308b75159d8c45ec77e48d431412d2aea9646be (patch)
treed258dd0287c53ac1536fd92e01cae6460d0c7398
parent1742c8156364087d9891149e7817b1b48c8f0417 (diff)
parentd9f21343081ecce184313ed732768896becf26df (diff)
Merge pull request #17822 from vespa-engine/arnej/wire-constant-types
Arnej/wire constant types
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java8
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConstantTensorTransformer.java13
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java50
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java20
4 files changed, 87 insertions, 4 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java b/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java
index e8ee5e9ed57..41cb40da4d6 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java
@@ -206,6 +206,14 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement
return featureTypes.get(reference);
}
+ // the name of a constant feature?
+ if (reference.isIdentifier()) {
+ Reference asConst = FeatureNames.asConstantFeature(reference.name());
+ if (featureTypes.containsKey(asConst)) {
+ return featureTypes.get(asConst);
+ }
+ }
+
// We do not know what this is - since we do not have complete knowledge about the match features
// in Java we must assume this is a match feature and return the double type - which is the type of
// all match features
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConstantTensorTransformer.java b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConstantTensorTransformer.java
index 6991e2b978b..31025b0511d 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConstantTensorTransformer.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConstantTensorTransformer.java
@@ -49,11 +49,16 @@ public class ConstantTensorTransformer extends ExpressionTransformer<RankProfile
}
private ExpressionNode transformConstantReference(ReferenceNode node, RankProfileTransformContext context) {
+ String constantName = node.getName();
Reference constantReference = node.reference();
- if ( ! FeatureNames.isConstantFeature(constantReference) && constantReference.isIdentifier())
- constantReference = FeatureNames.asConstantFeature(node.getName());
-
- Value value = context.constants().get(node.getName());
+ if (FeatureNames.isConstantFeature(constantReference)) {
+ constantName = constantReference.simpleArgument().orElse(null);
+ } else if (constantReference.isIdentifier()) {
+ constantReference = FeatureNames.asConstantFeature(constantName);
+ } else {
+ return node;
+ }
+ Value value = context.constants().get(constantName);
if (value == null || value.type().rank() == 0) return node;
TensorValue tensorValue = (TensorValue)value;
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java
index b149dafab95..12fe7e151c0 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java
@@ -57,6 +57,56 @@ public class RankingExpressionTypeResolverTestCase {
}
}
+
+ @Test
+ public void tensorFirstPhaseFromConstantMustProduceDouble() throws Exception {
+ try {
+ SearchBuilder builder = new SearchBuilder();
+ builder.importString(joinLines(
+ "search test {",
+ " document test { ",
+ " field a type tensor(d0[3]) {",
+ " indexing: attribute",
+ " }",
+ " }",
+ " rank-profile my_rank_profile {",
+ " function my_func() {",
+ " expression: x_tensor*2.0",
+ " }",
+ " function inline other_func() {",
+ " expression: z_tensor+3.0",
+ " }",
+ " first-phase {",
+ " expression: reduce(attribute(a),sum,d0)+y_tensor+my_func+other_func",
+ " }",
+ " constants {",
+ " x_tensor {",
+ " type: tensor(x{})",
+ " value: { {x:bar}:17 }",
+ " }",
+ " y_tensor {",
+ " type: tensor(y{})",
+ " value: { {y:foo}:42 }",
+ " }",
+ " z_tensor {",
+ " type: tensor(z{})",
+ " value: { {z:qux}:666 }",
+ " }",
+ " }",
+ " }",
+ "}"
+ ));
+ builder.build();
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals("In search definition 'test', rank profile 'my_rank_profile': The first-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x{},y{},z{})",
+ Exceptions.toMessageString(expected));
+ }
+ }
+
+
+
@Test
public void tensorSecondPhaseMustProduceDouble() throws Exception {
try {
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java
index a1231a1418b..10ba6eff169 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java
@@ -33,6 +33,26 @@ public class RankingExpressionWithTensorTestCase {
}
@Test
+ public void requireConstantTensorCanBeReferredViaConstantFeature() throws ParseException {
+ RankProfileSearchFixture f = new RankProfileSearchFixture(
+ " rank-profile my_profile {\n" +
+ " first-phase {\n" +
+ " expression: sum(constant(my_tensor))\n" +
+ " }\n" +
+ " constants {\n" +
+ " my_tensor {\n" +
+ " value: { {x:1,y:2}:1, {x:2,y:1}:2 }\n" +
+ " type: tensor(x{},y{})\n" +
+ " }\n" +
+ " }\n" +
+ " }");
+ f.compileRankProfile("my_profile");
+ f.assertFirstPhaseExpression("reduce(constant(my_tensor), sum)", "my_profile");
+ f.assertRankProperty("tensor(x{},y{}):{{x:1,y:2}:1.0,{x:2,y:1}:2.0}", "constant(my_tensor).value", "my_profile");
+ f.assertRankProperty("tensor(x{},y{})", "constant(my_tensor).type", "my_profile");
+ }
+
+ @Test
public void requireThatMultiLineConstantTensorAndTypeCanBeParsed() throws ParseException {
RankProfileSearchFixture f = new RankProfileSearchFixture(
" rank-profile my_profile {\n" +