diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-02-14 10:34:00 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-02-14 10:34:00 +0100 |
commit | 8916ae3d409523f61825bc9927ae408f8ae44237 (patch) | |
tree | 6c763ba92197e04a5caa947f7bf5abfebc05a993 | |
parent | fa0bc59e2313aa6b6249ad88f7c1892a3a29553d (diff) |
Handle nested bindings
3 files changed, 43 insertions, 2 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 bf6a95f10c1..84c99969325 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java @@ -132,8 +132,11 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement Arguments invocationArguments) { // TODO: What is our position on argument overloading/argument count differences? Map<String, String> bindings = new HashMap<>(formalArguments.size()); - for (int i = 0; i < formalArguments.size(); i++) - bindings.put(formalArguments.get(i), invocationArguments.expressions().get(i).toString()); // TODO: toString does not work generally + for (int i = 0; i < formalArguments.size(); i++) { + String identifier = invocationArguments.expressions().get(i).toString(); // TODO: ... + identifier = super.bindings.getOrDefault(identifier, identifier); + bindings.put(formalArguments.get(i), identifier); + } return bindings; } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java index b8117178c74..551e5a59aba 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java @@ -146,6 +146,43 @@ public class RankingExpressionTypeValidatorTestCase { summaryFeatures(profile).get("macro1(b)").type(profile.typeContext(builder.getQueryProfileRegistry()))); } + @Test + public void testMacroInvocationTypes_Nested() throws Exception { + RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); + SearchBuilder builder = new SearchBuilder(rankProfileRegistry); + builder.importString(joinLines( + "search test {", + " document test { ", + " field a type tensor(x[],y[]) {", + " indexing: attribute", + " }", + " field b type tensor(z[10]) {", + " indexing: attribute", + " }", + " }", + " rank-profile my_rank_profile {", + " macro use_first(attribute1, attribute2) {", + " expression: attribute(attribute1)", + " }", + " macro use_second(attribute1, attribute2) {", + " expression: use_first(attribute2, attribute1)", + " }", + " summary-features {", + " use_first(a, b)", + " use_second(a, b)", + " }", + " }", + "}" + )); + builder.build(); + RankProfile profile = + builder.getRankProfileRegistry().getRankProfile(builder.getSearch(), "my_rank_profile"); + assertEquals(TensorType.fromSpec("tensor(x[],y[])"), + summaryFeatures(profile).get("use_first(a,b)").type(profile.typeContext(builder.getQueryProfileRegistry()))); + assertEquals(TensorType.fromSpec("tensor(z[10])"), + summaryFeatures(profile).get("use_second(a,b)").type(profile.typeContext(builder.getQueryProfileRegistry()))); + } + private Map<String, ReferenceNode> summaryFeatures(RankProfile profile) { return profile.getSummaryFeatures().stream().collect(Collectors.toMap(f -> f.toString(), f -> f)); } diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/FunctionReferenceContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/FunctionReferenceContext.java index 289495f6ce9..96815d2cbae 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/FunctionReferenceContext.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/FunctionReferenceContext.java @@ -20,6 +20,7 @@ public class FunctionReferenceContext { private final ImmutableMap<String, ExpressionFunction> functions; /** Mapping from argument names to the expressions they resolve to */ + // TODO: Make private public final Map<String, String> bindings = new HashMap<>(); /** Create a context for a single serialization task */ |