summaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/searchdefinition
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-05-12 21:24:29 +0200
committerGitHub <noreply@github.com>2022-05-12 21:24:29 +0200
commit78e8952ad0ed18c026aaeb7c471dfc886ccde7cb (patch)
tree9634ca34296bf5cebd52bbdc38450e1e39a77383 /config-model/src/test/java/com/yahoo/searchdefinition
parent9128b9c93fd58be98409c59892470263f249ec0b (diff)
Revert "Create distributable constants on deriving"
Diffstat (limited to 'config-model/src/test/java/com/yahoo/searchdefinition')
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java4
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java2
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java58
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java26
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/LiteralBoostTestCase.java4
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java9
6 files changed, 54 insertions, 49 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java
index cbbb53d8ec8..d07f4513c3c 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java
@@ -36,7 +36,7 @@ public class RankProfileRegistryTest {
public void testRankProfileDuplicateNameIsIllegal() {
Schema schema = new Schema("foo", MockApplicationPackage.createEmpty());
RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(schema);
- RankProfile barRankProfile = new RankProfile("bar", schema, rankProfileRegistry);
+ RankProfile barRankProfile = new RankProfile("bar", schema, rankProfileRegistry, schema.rankingConstants());
rankProfileRegistry.add(barRankProfile);
rankProfileRegistry.add(barRankProfile);
}
@@ -48,7 +48,7 @@ public class RankProfileRegistryTest {
for (String rankProfileName : RankProfileRegistry.overridableRankProfileNames) {
assertNull(rankProfileRegistry.get(schema, rankProfileName).getFunctions().get("foo"));
- RankProfile rankProfileWithAddedFunction = new RankProfile(rankProfileName, schema, rankProfileRegistry);
+ RankProfile rankProfileWithAddedFunction = new RankProfile(rankProfileName, schema, rankProfileRegistry, schema.rankingConstants());
rankProfileWithAddedFunction.addFunction(new ExpressionFunction("foo", RankingExpression.from("1+2")), true);
rankProfileRegistry.add(rankProfileWithAddedFunction);
assertNotNull(rankProfileRegistry.get(schema, rankProfileName).getFunctions().get("foo"));
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java
index 50f930dde86..03b504bb821 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java
@@ -52,7 +52,7 @@ public class RankProfileTestCase extends AbstractSchemaTestCase {
a.setRankType(RankType.IDENTITY);
document.addField("b", DataType.STRING);
schema.addDocument(document);
- RankProfile child = new RankProfile("child", schema, rankProfileRegistry);
+ RankProfile child = new RankProfile("child", schema, rankProfileRegistry, schema.rankingConstants());
child.inherit("default");
rankProfileRegistry.add(child);
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java
index 3aab1a7bbe6..6eb74dede62 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java
@@ -30,7 +30,7 @@ public class RankingConstantTest {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry);
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" rank-profile my_rank_profile {",
" first-phase {",
@@ -46,12 +46,12 @@ public class RankingConstantTest {
schemaBuilder.build(true);
Schema schema = schemaBuilder.getSchema();
- Iterator<RankProfile.Constant> constantIterator = schema.constants().values().iterator();
- RankProfile.Constant constant = constantIterator.next();
- assertEquals(TENSOR_NAME, constant.name().simpleArgument().get());
- assertEquals(TENSOR_FILE, constant.valuePath().get());
- assertEquals(TENSOR_TYPE, constant.type().toString());
- assertEquals(DistributableResource.PathType.FILE, constant.pathType().get());
+ Iterator<RankingConstant> constantIterator = schema.rankingConstants().asMap().values().iterator();
+ RankingConstant constant = constantIterator.next();
+ assertEquals(TENSOR_NAME, constant.getName());
+ assertEquals(TENSOR_FILE, constant.getFileName());
+ assertEquals(TENSOR_TYPE, constant.getType());
+ assertEquals(RankingConstant.PathType.FILE, constant.getPathType());
assertFalse(constantIterator.hasNext());
}
@@ -63,7 +63,7 @@ public class RankingConstantTest {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("must have a type");
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" file: bar.baz",
@@ -79,7 +79,7 @@ public class RankingConstantTest {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("must have a file");
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x[])",
@@ -93,7 +93,7 @@ public class RankingConstantTest {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry);
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x{})",
@@ -103,8 +103,8 @@ public class RankingConstantTest {
));
schemaBuilder.build(true);
Schema schema = schemaBuilder.getSchema();
- RankProfile.Constant constant = schema.constants().values().iterator().next();
- assertEquals("simplename", constant.valuePath().get());
+ RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next();
+ assertEquals("simplename", constant.getFileName());
}
@Test
@@ -112,7 +112,7 @@ public class RankingConstantTest {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry);
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x{})",
@@ -122,9 +122,9 @@ public class RankingConstantTest {
));
schemaBuilder.build(true);
Schema schema = schemaBuilder.getSchema();
- RankProfile.Constant constant = schema.constants().values().iterator().next();
- assertEquals(DistributableResource.PathType.URI, constant.pathType().get());
- assertEquals("http://somewhere.far.away/in/another-galaxy", constant.valuePath().get());
+ RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next();
+ assertEquals(RankingConstant.PathType.URI, constant.getPathType());
+ assertEquals("http://somewhere.far.away/in/another-galaxy", constant.getUri());
}
@Test
@@ -132,7 +132,7 @@ public class RankingConstantTest {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry);
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x{})",
@@ -142,9 +142,9 @@ public class RankingConstantTest {
));
schemaBuilder.build(true);
Schema schema = schemaBuilder.getSchema();
- RankProfile.Constant constant = schema.constants().values().iterator().next();
- assertEquals(DistributableResource.PathType.URI, constant.pathType().get());
- assertEquals("https://somewhere.far.away:4443/in/another-galaxy", constant.valuePath().get());
+ RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next();
+ assertEquals(RankingConstant.PathType.URI, constant.getPathType());
+ assertEquals("https://somewhere.far.away:4443/in/another-galaxy", constant.getUri());
}
@Test
@@ -152,7 +152,7 @@ public class RankingConstantTest {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry);
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x{})",
@@ -162,9 +162,9 @@ public class RankingConstantTest {
));
schemaBuilder.build(true);
Schema schema = schemaBuilder.getSchema();
- RankProfile.Constant constant = schema.constants().values().iterator().next();
- assertEquals(DistributableResource.PathType.URI, constant.pathType().get());
- assertEquals("http://somewhere.far.away:4080/in/another-galaxy", constant.valuePath().get());
+ RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next();
+ assertEquals(RankingConstant.PathType.URI, constant.getPathType());
+ assertEquals("http://somewhere.far.away:4080/in/another-galaxy", constant.getUri());
}
@Test
@@ -172,7 +172,7 @@ public class RankingConstantTest {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry);
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x{})",
@@ -182,9 +182,9 @@ public class RankingConstantTest {
));
schemaBuilder.build(true);
Schema schema = schemaBuilder.getSchema();
- RankProfile.Constant constant = schema.constants().values().iterator().next();
- assertEquals(DistributableResource.PathType.URI, constant.pathType().get());
- assertEquals("http:somewhere.far.away/in/another-galaxy", constant.valuePath().get());
+ RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next();
+ assertEquals(RankingConstant.PathType.URI, constant.getPathType());
+ assertEquals("http:somewhere.far.away/in/another-galaxy", constant.getUri());
}
@Test
@@ -196,7 +196,7 @@ public class RankingConstantTest {
"<URI_PATH> ...";
try {
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x{})",
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java
index eb9b6e3a733..4b40da9e289 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java
@@ -189,10 +189,10 @@ public class SchemaTestCase {
assertNotNull(builder.getRankProfileRegistry().get(child1, "parent_profile"));
assertNotNull(builder.getRankProfileRegistry().get(child1, "child1_profile"));
assertEquals("parent_profile", builder.getRankProfileRegistry().get(child1, "child1_profile").inheritedNames().get(0));
- assertNotNull(child1.constants().get(FeatureNames.asConstantFeature("parent_constant")));
- assertNotNull(child1.constants().get(FeatureNames.asConstantFeature("child1_constant")));
- assertTrue(child1.constants().containsKey(FeatureNames.asConstantFeature("parent_constant")));
- assertTrue(child1.constants().containsKey(FeatureNames.asConstantFeature("child1_constant")));
+ assertNotNull(child1.rankingConstants().get("parent_constant"));
+ assertNotNull(child1.rankingConstants().get("child1_constant"));
+ assertTrue(child1.rankingConstants().asMap().containsKey("parent_constant"));
+ assertTrue(child1.rankingConstants().asMap().containsKey("child1_constant"));
assertNotNull(child1.onnxModels().get("parent_model"));
assertNotNull(child1.onnxModels().get("child1_model"));
assertTrue(child1.onnxModels().asMap().containsKey("parent_model"));
@@ -224,10 +224,10 @@ public class SchemaTestCase {
assertNotNull(builder.getRankProfileRegistry().get(child2, "parent_profile"));
assertNotNull(builder.getRankProfileRegistry().get(child2, "child2_profile"));
assertEquals("parent_profile", builder.getRankProfileRegistry().get(child2, "child2_profile").inheritedNames().get(0));
- assertNotNull(child2.constants().get(FeatureNames.asConstantFeature("parent_constant")));
- assertNotNull(child2.constants().get(FeatureNames.asConstantFeature("child2_constant")));
- assertTrue(child2.constants().containsKey(FeatureNames.asConstantFeature("parent_constant")));
- assertTrue(child2.constants().containsKey(FeatureNames.asConstantFeature("child2_constant")));
+ assertNotNull(child2.rankingConstants().get("parent_constant"));
+ assertNotNull(child2.rankingConstants().get("child2_constant"));
+ assertTrue(child2.rankingConstants().asMap().containsKey("parent_constant"));
+ assertTrue(child2.rankingConstants().asMap().containsKey("child2_constant"));
assertNotNull(child2.onnxModels().get("parent_model"));
assertNotNull(child2.onnxModels().get("child2_model"));
assertTrue(child2.onnxModels().asMap().containsKey("parent_model"));
@@ -317,8 +317,8 @@ public class SchemaTestCase {
builder.build(true);
var application = builder.application();
- assertInheritedFromParent(application.schemas().get("child"), builder.getRankProfileRegistry());
- assertInheritedFromParent(application.schemas().get("grandchild"), builder.getRankProfileRegistry());
+ assertInheritedFromParent(application.schemas().get("child"), application, builder.getRankProfileRegistry());
+ assertInheritedFromParent(application.schemas().get("grandchild"), application, builder.getRankProfileRegistry());
}
@Test
@@ -419,15 +419,15 @@ public class SchemaTestCase {
}
}
- private void assertInheritedFromParent(Schema schema, RankProfileRegistry rankProfileRegistry) {
+ private void assertInheritedFromParent(Schema schema, Application application, RankProfileRegistry rankProfileRegistry) {
assertEquals("pf1", schema.fieldSets().userFieldSets().get("parent_set").getFieldNames().stream().findFirst().get());
assertEquals(Stemming.NONE, schema.getStemming());
assertEquals(Stemming.BEST, schema.getIndex("parent_index").getStemming());
assertNotNull(schema.getField("parent_field"));
assertNotNull(schema.getExtraField("parent_field"));
assertNotNull(rankProfileRegistry.get(schema, "parent_profile"));
- assertNotNull(schema.constants().get(FeatureNames.asConstantFeature("parent_constant")));
- assertTrue(schema.constants().containsKey(FeatureNames.asConstantFeature("parent_constant")));
+ assertNotNull(schema.rankingConstants().get("parent_constant"));
+ assertTrue(schema.rankingConstants().asMap().containsKey("parent_constant"));
assertNotNull(schema.onnxModels().get("parent_model"));
assertTrue(schema.onnxModels().asMap().containsKey("parent_model"));
assertNotNull(schema.getSummary("parent_summary"));
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/LiteralBoostTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/LiteralBoostTestCase.java
index 70545c15ca0..1e7dd3a2405 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/LiteralBoostTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/LiteralBoostTestCase.java
@@ -38,7 +38,7 @@ public class LiteralBoostTestCase extends AbstractExportingTestCase {
SDField field1 = document.addField("a", DataType.STRING);
field1.parseIndexingScript("{ index }");
field1.setLiteralBoost(20);
- RankProfile other = new RankProfile("other", schema, rankProfileRegistry);
+ RankProfile other = new RankProfile("other", schema, rankProfileRegistry, schema.rankingConstants());
rankProfileRegistry.add(other);
other.addRankSetting(new RankProfile.RankSetting("a", RankProfile.RankSetting.Type.LITERALBOOST, 333));
@@ -70,7 +70,7 @@ public class LiteralBoostTestCase extends AbstractExportingTestCase {
schema.addDocument(document);
SDField field1 = document.addField("a", DataType.STRING);
field1.parseIndexingScript("{ index }");
- RankProfile other = new RankProfile("other", schema, rankProfileRegistry);
+ RankProfile other = new RankProfile("other", schema, rankProfileRegistry, schema.rankingConstants());
rankProfileRegistry.add(other);
other.addRankSetting(new RankProfile.RankSetting("a", RankProfile.RankSetting.Type.LITERALBOOST, 333));
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java
index 44857835ccf..0929e54a360 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java
@@ -10,7 +10,10 @@ import com.yahoo.path.Path;
import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.searchdefinition.FeatureNames;
import com.yahoo.searchdefinition.parser.ParseException;
+import com.yahoo.searchlib.rankingexpression.evaluation.Value;
import com.yahoo.tensor.TensorType;
+import com.yahoo.vespa.model.VespaModel;
+import com.yahoo.vespa.model.ml.ImportedModelTester;
import com.yahoo.yolean.Exceptions;
import org.junit.After;
import org.junit.Test;
@@ -20,8 +23,10 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -231,7 +236,7 @@ public class RankingExpressionWithOnnxTestCase {
search.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile_child");
assertNull("Constant overridden by function is not added",
- search.search().constants().get(name + "_Variable"));
+ search.search().rankingConstants().get( name + "_Variable"));
// At this point the expression is stored - copy application to another location which do not have a models dir
Path storedApplicationDirectory = applicationDir.getParentPath().append("copy");
@@ -246,7 +251,7 @@ public class RankingExpressionWithOnnxTestCase {
searchFromStored.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile");
searchFromStored.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile_child");
assertNull("Constant overridden by function is not added",
- searchFromStored.search().constants().get(name + "_Variable"));
+ searchFromStored.search().rankingConstants().get( name + "_Variable"));
} finally {
IOUtils.recursiveDeleteDir(storedApplicationDirectory.toFile());
}