diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-10-19 13:42:32 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-10-19 13:42:32 +0200 |
commit | 8aada7b3ce5f66204d36f1fb88f1d8873d0f292d (patch) | |
tree | 892613954091a2bfc297b85154390a0b1d271253 /config-model | |
parent | 892275bf2b8f3689e44911099602e15d420ed617 (diff) |
More input tests and better error message
Diffstat (limited to 'config-model')
-rw-r--r-- | config-model/src/main/java/com/yahoo/schema/RankProfile.java | 10 | ||||
-rw-r--r-- | config-model/src/test/java/com/yahoo/schema/RankProfileTestCase.java | 70 |
2 files changed, 75 insertions, 5 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/RankProfile.java b/config-model/src/main/java/com/yahoo/schema/RankProfile.java index 31c68d2f2c8..cc1c87e6f47 100644 --- a/config-model/src/main/java/com/yahoo/schema/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/schema/RankProfile.java @@ -783,12 +783,13 @@ public class RankProfile implements Cloneable { // Combine Map<Reference, Input> allInputs = new LinkedHashMap<>(); + for (var inheritedProfile : inherited()) { for (var input : inheritedProfile.inputs().entrySet()) { Input existing = allInputs.get(input.getKey()); if (existing != null && ! existing.equals(input.getValue())) throw new IllegalArgumentException(this + " inherits " + inheritedProfile + " which contains " + - input.getValue() + ", but this input is already defined as " + + input.getValue() + ", but this is already defined as " + existing + " in another profile this inherits"); allInputs.put(input.getKey(), input.getValue()); } @@ -1403,8 +1404,7 @@ public class RankProfile implements Cloneable { @Override public boolean equals(Object o) { if (o == this) return true; - if ( ! (o instanceof Input)) return false; - Input other = (Input)o; + if ( ! (o instanceof Input other)) return false; if ( ! other.name().equals(this.name())) return false; if ( ! other.type().equals(this.type())) return false; if ( ! other.defaultValue().equals(this.defaultValue())) return false; @@ -1418,8 +1418,8 @@ public class RankProfile implements Cloneable { @Override public String toString() { - return "input '" + name + "' " + type + - (defaultValue().isPresent() ? ":" + defaultValue.get().toAbbreviatedString() : ""); + return "input " + name + " " + type + + (defaultValue().isPresent() ? ":" + defaultValue.get().toAbbreviatedString(false, true) : ""); } } diff --git a/config-model/src/test/java/com/yahoo/schema/RankProfileTestCase.java b/config-model/src/test/java/com/yahoo/schema/RankProfileTestCase.java index 51d19283b1e..85225f0d255 100644 --- a/config-model/src/test/java/com/yahoo/schema/RankProfileTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/RankProfileTestCase.java @@ -24,11 +24,13 @@ import ai.vespa.rankingexpression.importer.configmodelview.ImportedMlModels; import static com.yahoo.config.model.test.TestUtil.joinLines; +import com.yahoo.searchlib.rankingexpression.Reference; import org.junit.jupiter.api.Test; import java.util.Iterator; import java.util.List; import java.util.Optional; +import java.util.Set; import static org.junit.jupiter.api.Assertions.*; @@ -168,6 +170,74 @@ public class RankProfileTestCase extends AbstractSchemaTestCase { } @Test + void inputsAreInheritedAndValuesAreOverridable() throws ParseException { + RankProfileRegistry registry = new RankProfileRegistry(); + ApplicationBuilder builder = new ApplicationBuilder(registry, new QueryProfileRegistry()); + builder.addSchema(joinLines( + "schema test {", + " document test { } ", + " rank-profile parent1 {", + " inputs {", + " input1 double: 1", + " input2 double: 2", + " }", + " }", + " rank-profile parent2 {", + " inputs {", + " input4 double: 4", + " }", + " }", + " rank-profile child inherits parent1, parent2 {", + " inputs {", + " input2 double: 2.5", + " input3 double: 3", + " }" + + " }", + "}")); + var application = builder.build(true); + RankProfile child = registry.get(application.schemas().get("test"), "child"); + assertEquals(4, child.inputs().size()); + assertEquals(Set.of(Reference.simple("query", "input1"), + Reference.simple("query", "input2"), + Reference.simple("query", "input3"), + Reference.simple("query", "input4")), + child.inputs().keySet()); + var input2 = child.inputs().get(Reference.simple("query", "input2")); + assertEquals(2.5, input2.defaultValue().get().asDouble(), 0.000000001); + } + + @Test + void inputConflictsAreDetected() throws ParseException { + try { + RankProfileRegistry registry = new RankProfileRegistry(); + ApplicationBuilder builder = new ApplicationBuilder(registry, new QueryProfileRegistry()); + builder.addSchema(joinLines( + "schema test {", + " document test { } ", + " rank-profile parent1 {", + " inputs {", + " input1 double: 1", + " }", + " }", + " rank-profile parent2 {", + " inputs {", + " input1 tensor(x[100])", + " }", + " }", + " rank-profile child inherits parent1, parent2 {", + " }", + "}")); + builder.build(true); + fail("Should have failed"); + } + catch (IllegalArgumentException e) { + assertEquals("rank profile 'child' inherits rank profile 'parent2' which contains input query(input1) tensor(x[100])" + + ", but this is already defined as input query(input1) tensor():{1.0} in another profile this inherits", + e.getCause().getMessage()); + } + } + + @Test void requireThatDefaultInheritingDefaultIsIgnored() throws ParseException { RankProfileRegistry registry = new RankProfileRegistry(); ApplicationBuilder builder = new ApplicationBuilder(registry, setupQueryProfileTypes()); |