summaryrefslogtreecommitdiffstats
path: root/config-model/src
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2019-12-04 16:21:51 +0100
committerGitHub <noreply@github.com>2019-12-04 16:21:51 +0100
commitd3002ae703705198940203f48ba915d14bb948c4 (patch)
treeee0a9143e255342ac2c565bea9c9f84ffbf637c5 /config-model/src
parentaacefdcdbd22a58fe57011e9cfa18a5d55e5d473 (diff)
parente4bce25aba236f4c0a5929acce15da424ea674c4 (diff)
Merge pull request #11498 from vespa-engine/bratseth/tensor-function-output
Bratseth/tensor function output
Diffstat (limited to 'config-model/src')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java10
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java4
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java4
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/FunctionShadower.java3
-rw-r--r--config-model/src/test/derived/tensor/rank-profiles.cfg33
-rw-r--r--config-model/src/test/derived/tensor/tensor.sd25
6 files changed, 67 insertions, 12 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 a54e21aae68..2be3022ce6e 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java
@@ -108,7 +108,8 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement
if (FeatureNames.isSimpleFeature(reference)) {
// The argument may be a local identifier bound to the actual value
String argument = reference.simpleArgument().get();
- reference = Reference.simple(reference.name(), bindings.getOrDefault(argument, argument));
+ String argumentBinding = getBinding(argument);
+ reference = Reference.simple(reference.name(), argumentBinding != null ? argumentBinding : argument);
return featureTypes.get(reference);
}
@@ -152,7 +153,7 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement
private Optional<String> boundIdentifier(Reference reference) {
if ( ! reference.arguments().isEmpty()) return Optional.empty();
if ( reference.output() != null) return Optional.empty();
- return Optional.ofNullable(bindings.get(reference.name()));
+ return Optional.ofNullable(getBinding(reference.name()));
}
private Optional<ExpressionFunction> functionInvocation(Reference reference) {
@@ -203,8 +204,8 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement
Map<String, String> bindings = new HashMap<>(formalArguments.size());
for (int i = 0; i < formalArguments.size(); i++) {
String identifier = invocationArguments.expressions().get(i).toString();
- identifier = super.bindings.getOrDefault(identifier, identifier);
- bindings.put(formalArguments.get(i), identifier);
+ String identifierBinding = super.getBinding(identifier);
+ bindings.put(formalArguments.get(i), identifierBinding != null ? identifierBinding : identifier);
}
return bindings;
}
@@ -215,7 +216,6 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement
@Override
public MapEvaluationTypeContext withBindings(Map<String, String> bindings) {
- if (bindings.isEmpty() && this.bindings.isEmpty()) return this;
return new MapEvaluationTypeContext(functions(), bindings, featureTypes, currentResolutionCallStack);
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java
index bf585df9005..271442768a8 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java
@@ -53,8 +53,8 @@ public class RankProfileRegistry {
if (existingRangProfileWithSameName == null) return;
if ( ! overridableRankProfileNames.contains(rankProfileName)) {
- throw new IllegalArgumentException("Cannot add rank profile '" + rankProfileName + "' in search definition '"
- + rankProfile.getSearch().getName() + "', since it already exists");
+ throw new IllegalArgumentException("Duplicate rank profile '" + rankProfileName + "' in " +
+ rankProfile.getSearch());
}
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java
index 6192db2654e..1a22b98fd9f 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java
@@ -324,7 +324,7 @@ public class RawRankProfile implements RankProfilesConfig.Producer {
try {
firstPhaseRanking = new RankingExpression(property.getValue());
} catch (ParseException e) {
- throw new IllegalArgumentException("Could not parse second phase expression", e);
+ throw new IllegalArgumentException("Could not parse first phase expression", e);
}
}
else if ("rankingExpression(secondphase).rankingScript".equals(property.getName())) {
@@ -406,7 +406,7 @@ public class RawRankProfile implements RankProfilesConfig.Producer {
return properties;
}
- private List<Pair<String, String>> deriveRankingPhaseRankProperties(RankingExpression expression, String phase) {
+ private List<Pair<String, String>> deriveRankingPhaseRankProperties(RankingExpression expression, String phase) {
List<Pair<String, String>> properties = new ArrayList<>();
if (expression == null) return properties;
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/FunctionShadower.java b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/FunctionShadower.java
index c3ee7d5fc3d..bb2e20a4f05 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/FunctionShadower.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/FunctionShadower.java
@@ -44,9 +44,8 @@ public class FunctionShadower extends ExpressionTransformer<RankProfileTransform
private ExpressionNode transformFunctionNode(FunctionNode function, RankProfileTransformContext context) {
String name = function.getFunction().toString();
RankProfile.RankingExpressionFunction rankingExpressionFunction = context.rankProfile().findFunction(name);
- if (rankingExpressionFunction == null) {
+ if (rankingExpressionFunction == null)
return transformChildren(function, context);
- }
int functionArity = function.getFunction().arity();
if (functionArity != rankingExpressionFunction.function().arguments().size())
diff --git a/config-model/src/test/derived/tensor/rank-profiles.cfg b/config-model/src/test/derived/tensor/rank-profiles.cfg
index cebfa244159..554a36aef86 100644
--- a/config-model/src/test/derived/tensor/rank-profiles.cfg
+++ b/config-model/src/test/derived/tensor/rank-profiles.cfg
@@ -112,7 +112,7 @@ rankprofile[].fef.property[].name "vespa.type.attribute.f5"
rankprofile[].fef.property[].value "tensor<float>(x[10])"
rankprofile[].name "profile7"
rankprofile[].fef.property[].name "rankingExpression(reshaped).rankingScript"
-rankprofile[].fef.property[].value "tensor<float>(d0[1],x[2])({x:1 - x, y:d0})"
+rankprofile[].fef.property[].value "tensor<float>(d0[1],x[2])(attribute(f2){x:1 - x, y:d0})"
rankprofile[].fef.property[].name "rankingExpression(reshaped).type"
rankprofile[].fef.property[].value "tensor<float>(d0[1],x[2])"
rankprofile[].fef.property[].name "vespa.rank.firstphase"
@@ -127,3 +127,34 @@ rankprofile[].fef.property[].name "vespa.type.attribute.f4"
rankprofile[].fef.property[].value "tensor(x[10],y[20])"
rankprofile[].fef.property[].name "vespa.type.attribute.f5"
rankprofile[].fef.property[].value "tensor<float>(x[10])"
+rankprofile[].name "profile8"
+rankprofile[].fef.property[].name "rankingExpression(functionNotLabel).rankingScript"
+rankprofile[].fef.property[].value "3"
+rankprofile[].fef.property[].name "vespa.rank.firstphase"
+rankprofile[].fef.property[].value "rankingExpression(firstphase)"
+rankprofile[].fef.property[].name "rankingExpression(firstphase).rankingScript"
+rankprofile[].fef.property[].value "reduce(tensor(d0[1])(attribute{x:(rankingExpression(functionNotLabel))}), sum)"
+rankprofile[].fef.property[].name "vespa.type.attribute.f2"
+rankprofile[].fef.property[].value "tensor<float>(x[2],y[1])"
+rankprofile[].fef.property[].name "vespa.type.attribute.f3"
+rankprofile[].fef.property[].value "tensor(x{})"
+rankprofile[].fef.property[].name "vespa.type.attribute.f4"
+rankprofile[].fef.property[].value "tensor(x[10],y[20])"
+rankprofile[].fef.property[].name "vespa.type.attribute.f5"
+rankprofile[].fef.property[].value "tensor<float>(x[10])"
+rankprofile[].name "profile9"
+rankprofile[].fef.property[].name "rankingExpression(shadow).rankingScript"
+rankprofile[].fef.property[].value "3"
+rankprofile[].fef.property[].name "vespa.rank.firstphase"
+rankprofile[].fef.property[].value "rankingExpression(firstphase)"
+rankprofile[].fef.property[].name "rankingExpression(firstphase).rankingScript"
+rankprofile[].fef.property[].value "reduce(tensor(shadow[1])(attribute{x:shadow + rankingExpression(shadow)}), sum)"
+rankprofile[].fef.property[].name "vespa.type.attribute.f2"
+rankprofile[].fef.property[].value "tensor<float>(x[2],y[1])"
+rankprofile[].fef.property[].name "vespa.type.attribute.f3"
+rankprofile[].fef.property[].value "tensor(x{})"
+rankprofile[].fef.property[].name "vespa.type.attribute.f4"
+rankprofile[].fef.property[].value "tensor(x[10],y[20])"
+rankprofile[].fef.property[].name "vespa.type.attribute.f5"
+rankprofile[].fef.property[].value "tensor<float>(x[10])"
+
diff --git a/config-model/src/test/derived/tensor/tensor.sd b/config-model/src/test/derived/tensor/tensor.sd
index 15d56517a43..c3380bed19c 100644
--- a/config-model/src/test/derived/tensor/tensor.sd
+++ b/config-model/src/test/derived/tensor/tensor.sd
@@ -90,4 +90,29 @@ search tensor {
}
+ rank-profile profile8 {
+
+ first-phase {
+ expression: sum(tensor(d0[1])(attribute{x:(functionNotLabel)}))
+ }
+
+ function functionNotLabel() {
+ expression: 3
+ }
+
+ }
+
+ rank-profile profile9 {
+
+ # shadow refers to the generate index and shadow() to the function
+ first-phase {
+ expression: sum(tensor(shadow[1])(attribute{x: shadow + shadow() }))
+ }
+
+ function shadow() {
+ expression: 3
+ }
+
+ }
+
}