diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-05-12 21:26:17 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-05-12 21:26:17 +0200 |
commit | fa7c1ee9d68b01d4501f08b9ea937f066fb3e45e (patch) | |
tree | 23637dc005deb2410a773f9561d23b59d8b5461e /config-model/src/test/java/com | |
parent | c6c407d234fe5b5e926f35bceb8e26d4298d3c4f (diff) |
Revert "Revert "Create distributable constants on deriving""
This reverts commit 78e8952ad0ed18c026aaeb7c471dfc886ccde7cb.
Diffstat (limited to 'config-model/src/test/java/com')
8 files changed, 64 insertions, 67 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 d07f4513c3c..cbbb53d8ec8 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, schema.rankingConstants()); + RankProfile barRankProfile = new RankProfile("bar", schema, rankProfileRegistry); 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, schema.rankingConstants()); + RankProfile rankProfileWithAddedFunction = new RankProfile(rankProfileName, schema, rankProfileRegistry); 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 03b504bb821..50f930dde86 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, schema.rankingConstants()); + RankProfile child = new RankProfile("child", schema, rankProfileRegistry); 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 6eb74dede62..3aab1a7bbe6 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( - "search test {", + "schema 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<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()); + 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()); assertFalse(constantIterator.hasNext()); } @@ -63,7 +63,7 @@ public class RankingConstantTest { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("must have a type"); schemaBuilder.addSchema(joinLines( - "search test {", + "schema 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( - "search test {", + "schema 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( - "search test {", + "schema test {", " document test { }", " constant foo {", " type: tensor(x{})", @@ -103,8 +103,8 @@ public class RankingConstantTest { )); schemaBuilder.build(true); Schema schema = schemaBuilder.getSchema(); - RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next(); - assertEquals("simplename", constant.getFileName()); + RankProfile.Constant constant = schema.constants().values().iterator().next(); + assertEquals("simplename", constant.valuePath().get()); } @Test @@ -112,7 +112,7 @@ public class RankingConstantTest { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry); schemaBuilder.addSchema(joinLines( - "search test {", + "schema test {", " document test { }", " constant foo {", " type: tensor(x{})", @@ -122,9 +122,9 @@ public class RankingConstantTest { )); schemaBuilder.build(true); Schema schema = schemaBuilder.getSchema(); - RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next(); - assertEquals(RankingConstant.PathType.URI, constant.getPathType()); - assertEquals("http://somewhere.far.away/in/another-galaxy", constant.getUri()); + 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()); } @Test @@ -132,7 +132,7 @@ public class RankingConstantTest { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry); schemaBuilder.addSchema(joinLines( - "search test {", + "schema test {", " document test { }", " constant foo {", " type: tensor(x{})", @@ -142,9 +142,9 @@ public class RankingConstantTest { )); schemaBuilder.build(true); Schema schema = schemaBuilder.getSchema(); - 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()); + 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()); } @Test @@ -152,7 +152,7 @@ public class RankingConstantTest { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry); schemaBuilder.addSchema(joinLines( - "search test {", + "schema test {", " document test { }", " constant foo {", " type: tensor(x{})", @@ -162,9 +162,9 @@ public class RankingConstantTest { )); schemaBuilder.build(true); Schema schema = schemaBuilder.getSchema(); - 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()); + 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()); } @Test @@ -172,7 +172,7 @@ public class RankingConstantTest { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry); schemaBuilder.addSchema(joinLines( - "search test {", + "schema test {", " document test { }", " constant foo {", " type: tensor(x{})", @@ -182,9 +182,9 @@ public class RankingConstantTest { )); schemaBuilder.build(true); Schema schema = schemaBuilder.getSchema(); - RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next(); - assertEquals(RankingConstant.PathType.URI, constant.getPathType()); - assertEquals("http:somewhere.far.away/in/another-galaxy", constant.getUri()); + 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()); } @Test @@ -196,7 +196,7 @@ public class RankingConstantTest { "<URI_PATH> ..."; try { schemaBuilder.addSchema(joinLines( - "search test {", + "schema 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 4b40da9e289..eb9b6e3a733 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.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.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.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.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.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.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"), application, builder.getRankProfileRegistry()); - assertInheritedFromParent(application.schemas().get("grandchild"), application, builder.getRankProfileRegistry()); + assertInheritedFromParent(application.schemas().get("child"), builder.getRankProfileRegistry()); + assertInheritedFromParent(application.schemas().get("grandchild"), builder.getRankProfileRegistry()); } @Test @@ -419,15 +419,15 @@ public class SchemaTestCase { } } - private void assertInheritedFromParent(Schema schema, Application application, RankProfileRegistry rankProfileRegistry) { + private void assertInheritedFromParent(Schema schema, 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.rankingConstants().get("parent_constant")); - assertTrue(schema.rankingConstants().asMap().containsKey("parent_constant")); + assertNotNull(schema.constants().get(FeatureNames.asConstantFeature("parent_constant"))); + assertTrue(schema.constants().containsKey(FeatureNames.asConstantFeature("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 1e7dd3a2405..70545c15ca0 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, schema.rankingConstants()); + RankProfile other = new RankProfile("other", schema, rankProfileRegistry); 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, schema.rankingConstants()); + RankProfile other = new RankProfile("other", schema, rankProfileRegistry); 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 0929e54a360..44857835ccf 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,10 +10,7 @@ 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; @@ -23,10 +20,8 @@ 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; @@ -236,7 +231,7 @@ public class RankingExpressionWithOnnxTestCase { search.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile_child"); assertNull("Constant overridden by function is not added", - search.search().rankingConstants().get( name + "_Variable")); + search.search().constants().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"); @@ -251,7 +246,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().rankingConstants().get( name + "_Variable")); + searchFromStored.search().constants().get(name + "_Variable")); } finally { IOUtils.recursiveDeleteDir(storedApplicationDirectory.toFile()); } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidatorTest.java index f6fa73dce74..efb6969d6c7 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidatorTest.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.model.application.validation; import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg; +import com.yahoo.yolean.Exceptions; import org.junit.Test; import static com.yahoo.vespa.model.application.validation.RankingConstantsValidator.TensorValidationException; @@ -21,9 +22,9 @@ public class RankingConstantsValidatorTest { new VespaModelCreatorWithFilePkg("src/test/cfg/application/validation/ranking_constants_fail/").create(); fail(); } catch (TensorValidationException e) { - assertTrue(e.getMessage().contains("Ranking constant 'constant_tensor_2' (tensors/constant_tensor_2.json): Tensor label is not a string (VALUE_NUMBER_INT)")); - assertTrue(e.getMessage().contains("Ranking constant 'constant_tensor_3' (tensors/constant_tensor_3.json): Tensor dimension 'cd' does not exist")); - assertTrue(e.getMessage().contains("Ranking constant 'constant_tensor_4' (tensors/constant_tensor_4.json): Tensor dimension 'z' does not exist")); + assertTrue(e.getMessage().contains("Ranking constant 'constant(constant_tensor_2)' (tensors/constant_tensor_2.json): Tensor label is not a string (VALUE_NUMBER_INT)")); + assertTrue(e.getMessage().contains("Ranking constant 'constant(constant_tensor_3)' (tensors/constant_tensor_3.json): Tensor dimension 'cd' does not exist")); + assertTrue(e.getMessage().contains("Ranking constant 'constant(constant_tensor_4)' (tensors/constant_tensor_4.json): Tensor dimension 'z' does not exist")); } } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java b/config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java index a1fc13adf5c..556d91acb70 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java @@ -1,14 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.ml; -import com.google.common.collect.ImmutableList; import com.yahoo.config.model.ApplicationPackageTester; import ai.vespa.rankingexpression.importer.configmodelview.MlModelImporter; import com.yahoo.config.model.deploy.DeployState; import com.yahoo.io.GrowableByteBuffer; import com.yahoo.io.IOUtils; import com.yahoo.path.Path; -import com.yahoo.searchdefinition.RankingConstant; import ai.vespa.rankingexpression.importer.lightgbm.LightGBMImporter; import ai.vespa.rankingexpression.importer.onnx.OnnxImporter; import ai.vespa.rankingexpression.importer.tensorflow.TensorFlowImporter; @@ -21,10 +19,12 @@ import org.xml.sax.SAXException; import java.io.IOException; import java.io.UncheckedIOException; +import java.util.List; import java.util.Optional; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; /** * Helper for testing of imported models. @@ -34,11 +34,11 @@ import static org.junit.Assert.assertEquals; */ public class ImportedModelTester { - private final ImmutableList<MlModelImporter> importers = ImmutableList.of(new TensorFlowImporter(), - new OnnxImporter(), - new LightGBMImporter(), - new XGBoostImporter(), - new VespaImporter()); + private final List<MlModelImporter> importers = List.of(new TensorFlowImporter(), + new OnnxImporter(), + new LightGBMImporter(), + new XGBoostImporter(), + new VespaImporter()); private final String modelName; private final Path applicationDir; @@ -69,9 +69,10 @@ public class ImportedModelTester { public void assertLargeConstant(String constantName, VespaModel model, Optional<Long> expectedSize) { try { Path constantApplicationPackagePath = Path.fromString("models.generated/" + modelName + "/constants").append(constantName + ".tbf"); - RankingConstant rankingConstant = model.rankingConstants().get(constantName); - assertEquals(constantName, rankingConstant.getName()); - assertTrue(rankingConstant.getFileName().endsWith(constantApplicationPackagePath.toString())); + var constant = model.rankProfileList().constants().asMap().get(constantName); + assertNotNull(constant); + assertEquals(constantName, constant.getName()); + assertTrue(constant.getFileName().endsWith(constantApplicationPackagePath.toString())); if (expectedSize.isPresent()) { Path constantPath = applicationDir.append(constantApplicationPackagePath); |