diff options
author | Jon Bratseth <jonbratseth@yahoo.com> | 2018-02-20 18:59:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-20 18:59:45 +0100 |
commit | 3f66466af5e58bc37c46b533dfd087c45b210d9b (patch) | |
tree | 1addf3b16a3caec300ce773ee60960ccd78c9570 /config-model/src/test | |
parent | 2a343e5a88a023a3f3246db2f47726e229d28fac (diff) |
Revert "Bratseth/typecheck all 2"
Diffstat (limited to 'config-model/src/test')
16 files changed, 93 insertions, 411 deletions
diff --git a/config-model/src/test/derived/rankexpression/rank-profiles.cfg b/config-model/src/test/derived/rankexpression/rank-profiles.cfg index f5652c31d2a..e890b75770b 100644 --- a/config-model/src/test/derived/rankexpression/rank-profiles.cfg +++ b/config-model/src/test/derived/rankexpression/rank-profiles.cfg @@ -24,7 +24,7 @@ rankprofile[0].fef.property[10].value "4" rankprofile[0].fef.property[11].name "vespa.dump.feature" rankprofile[0].fef.property[11].value "attribute(foo1).out" rankprofile[0].fef.property[12].name "vespa.dump.feature" -rankprofile[0].fef.property[12].value "attribute(bar1)" +rankprofile[0].fef.property[12].value "attribute(bar1.out)" rankprofile[0].fef.property[13].name "vespa.dump.feature" rankprofile[0].fef.property[13].value "attribute(foo2).out" rankprofile[0].fef.property[14].name "vespa.dump.feature" @@ -64,7 +64,7 @@ rankprofile[2].fef.property[2].value "10 + feature(arg1).out.out" rankprofile[2].fef.property[3].name "vespa.summary.feature" rankprofile[2].fef.property[3].value "attribute(foo1).out" rankprofile[2].fef.property[4].name "vespa.summary.feature" -rankprofile[2].fef.property[4].value "attribute(bar1)" +rankprofile[2].fef.property[4].value "attribute(bar1.out)" rankprofile[2].fef.property[5].name "vespa.summary.feature" rankprofile[2].fef.property[5].value "attribute(foo2).out" rankprofile[2].fef.property[6].name "vespa.summary.feature" diff --git a/config-model/src/test/derived/rankexpression/rankexpression.sd b/config-model/src/test/derived/rankexpression/rankexpression.sd index d3e0057cfe1..8ed1f2bab4c 100644 --- a/config-model/src/test/derived/rankexpression/rankexpression.sd +++ b/config-model/src/test/derived/rankexpression/rankexpression.sd @@ -5,10 +5,12 @@ search rankexpression { field artist type string { indexing: summary | index + # index-to: artist, default } field title type string { indexing: summary | index + # index-to: title, default } field surl type string { @@ -19,38 +21,6 @@ search rankexpression { indexing: summary | attribute } - field foo1 type int { - indexing: attribute - } - - field foo2 type int { - indexing: attribute - } - - field foo3 type int { - indexing: attribute - } - - field foo4 type int { - indexing: attribute - } - - field bar1 type int { - indexing: attribute - } - - field bar2 type int { - indexing: attribute - } - - field bar3 type int { - indexing: attribute - } - - field bar4 type int { - indexing: attribute - } - } rank-profile default { @@ -63,7 +33,7 @@ search rankexpression { expression: if(3>2,4,2) rerank-count: 10 } - rank-features: attribute(foo1).out attribute(bar1) + rank-features: attribute(foo1).out attribute(bar1.out) rank-features { attribute(foo2).out attribute(bar2).out } rank-features { attribute(foo3).out attribute(bar3).out } @@ -95,7 +65,7 @@ search rankexpression { file:rankexpression } } - summary-features: attribute(foo1).out attribute(bar1) + summary-features: attribute(foo1).out attribute(bar1.out) summary-features { attribute(foo2).out attribute(bar2).out } summary-features { attribute(foo3).out attribute(bar3).out } diff --git a/config-model/src/test/derived/rankexpression/summary.cfg b/config-model/src/test/derived/rankexpression/summary.cfg index 9752a9f55e3..00df2e87144 100644 --- a/config-model/src/test/derived/rankexpression/summary.cfg +++ b/config-model/src/test/derived/rankexpression/summary.cfg @@ -15,25 +15,9 @@ classes[0].fields[5].name "summaryfeatures" classes[0].fields[5].type "featuredata" classes[0].fields[6].name "documentid" classes[0].fields[6].type "longstring" -classes[1].id 1736696699 +classes[1].id 1787488393 classes[1].name "attributeprefetch" classes[1].fields[0].name "year" -classes[].fields[].type "integer" -classes[].fields[].name "foo1" -classes[].fields[].type "integer" -classes[].fields[].name "foo2" -classes[].fields[].type "integer" -classes[].fields[].name "foo3" -classes[].fields[].type "integer" -classes[].fields[].name "foo4" -classes[].fields[].type "integer" -classes[].fields[].name "bar1" -classes[].fields[].type "integer" -classes[].fields[].name "bar2" -classes[].fields[].type "integer" -classes[].fields[].name "bar3" -classes[].fields[].type "integer" -classes[].fields[].name "bar4" classes[1].fields[0].type "integer" classes[1].fields[1].name "rankfeatures" classes[1].fields[1].type "featuredata" diff --git a/config-model/src/test/derived/rankexpression/summarymap.cfg b/config-model/src/test/derived/rankexpression/summarymap.cfg index 21e6cdf346f..c810f7282ba 100644 --- a/config-model/src/test/derived/rankexpression/summarymap.cfg +++ b/config-model/src/test/derived/rankexpression/summarymap.cfg @@ -7,28 +7,4 @@ override[1].command "rankfeatures" override[1].arguments "" override[2].field "summaryfeatures" override[2].command "summaryfeatures" -override[2].arguments "" -override[].field "foo1" -override[].command "attribute" -override[].arguments "foo1" -override[].field "foo2" -override[].command "attribute" -override[].arguments "foo2" -override[].field "foo3" -override[].command "attribute" -override[].arguments "foo3" -override[].field "foo4" -override[].command "attribute" -override[].arguments "foo4" -override[].field "bar1" -override[].command "attribute" -override[].arguments "bar1" -override[].field "bar2" -override[].command "attribute" -override[].arguments "bar2" -override[].field "bar3" -override[].command "attribute" -override[].arguments "bar3" -override[].field "bar4" -override[].command "attribute" -override[].arguments "bar4"
\ No newline at end of file +override[2].arguments ""
\ No newline at end of file diff --git a/config-model/src/test/derived/tensor/rank-profiles.cfg b/config-model/src/test/derived/tensor/rank-profiles.cfg index b6ad5372c05..2b231e0cda2 100644 --- a/config-model/src/test/derived/tensor/rank-profiles.cfg +++ b/config-model/src/test/derived/tensor/rank-profiles.cfg @@ -35,7 +35,7 @@ rankprofile[3].name "profile2" rankprofile[3].fef.property[0].name "vespa.rank.firstphase" rankprofile[3].fef.property[0].value "rankingExpression(firstphase)" rankprofile[3].fef.property[1].name "rankingExpression(firstphase).rankingScript" -rankprofile[3].fef.property[1].value "reduce(reduce(join(attribute(f4), tensor(x[2],y[2],z[3])((x==y)*(y==z)), f(a,b)(a * b)), sum, x), sum)" +rankprofile[3].fef.property[1].value "reduce(join(attribute(f4), tensor(x[2],y[2],z[3])((x==y)*(y==z)), f(a,b)(a * b)), sum, x)" rankprofile[3].fef.property[2].name "vespa.type.attribute.f2" rankprofile[3].fef.property[2].value "tensor(x[2],y[])" rankprofile[3].fef.property[3].name "vespa.type.attribute.f3" diff --git a/config-model/src/test/derived/tensor/tensor.sd b/config-model/src/test/derived/tensor/tensor.sd index 3d64f6b807e..a6a9a98db3a 100644 --- a/config-model/src/test/derived/tensor/tensor.sd +++ b/config-model/src/test/derived/tensor/tensor.sd @@ -28,7 +28,7 @@ search tensor { rank-profile profile2 { first-phase { - expression: sum(matmul(attribute(f4), diag(x[2],y[2],z[3]), x)) + expression: matmul(attribute(f4), diag(x[2],y[2],z[3]), x) } } diff --git a/config-model/src/test/examples/rankpropvars.sd b/config-model/src/test/examples/rankpropvars.sd index 28959edbc09..40f9e73f35a 100644 --- a/config-model/src/test/examples/rankpropvars.sd +++ b/config-model/src/test/examples/rankpropvars.sd @@ -18,8 +18,8 @@ first-phase { second-phase { expression { if (attribute(artist) == query(testvar1), - 0.0 * fieldMatch(title) + 0.0 * attribute(Popularity) + 0.0 * fieldMatch(artist), - 0.0 * attribute(Popularity) + 0.0 * fieldMatch(artist) + 0.0 * fieldMatch(title)) + 0.0 * fieldMatch(title) + 0.0 * attribute(popularity) + 0.0 * fieldMatch(artist), + 0.0 * attribute(popularity) + 0.0 * fieldMatch(artist) + 0.0 * fieldMatch(title)) } } @@ -42,8 +42,8 @@ first-phase { second-phase { expression { if (attribute(artist) == query(testvar1), - 0.0 * fieldMatch(title) + 0.0 * attribute(Popularity) + 0.0 * fieldMatch(artist), - 0.0 * attribute(Popularity) + 0.0 * fieldMatch(artist) + 0.0 * fieldMatch(title)) + 0.0 * fieldMatch(title) + 0.0 * attribute(popularity) + 0.0 * fieldMatch(artist), + 0.0 * attribute(popularity) + 0.0 * fieldMatch(artist) + 0.0 * fieldMatch(title)) } } } diff --git a/config-model/src/test/examples/simple.sd b/config-model/src/test/examples/simple.sd index 96b0fa98098..4fda7f5039e 100644 --- a/config-model/src/test/examples/simple.sd +++ b/config-model/src/test/examples/simple.sd @@ -116,7 +116,7 @@ search simple { first-phase { keep-rank-count:200 rank-score-drop-limit: -13.0 - expression: attribute(popularity) + expression: attribute(year) } second-phase { rerank-count: 99 diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/FeatureNamesTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/FeatureNamesTestCase.java index aa01070d296..1f60ad870ec 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/FeatureNamesTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/FeatureNamesTestCase.java @@ -18,6 +18,17 @@ import static org.junit.Assert.assertFalse; public class FeatureNamesTestCase { @Test + public void testCanonicalization() { + assertFalse(FeatureNames.canonicalizeIfValid("foo").isPresent()); + assertEquals("query(bar)", FeatureNames.canonicalize("query(bar)")); + assertEquals("query(bar)", FeatureNames.canonicalize("query('bar')")); + assertEquals("constant(bar)", FeatureNames.canonicalize("constant(\"bar\")")); + assertEquals("query(\"ba.r\")", FeatureNames.canonicalize("query(ba.r)")); + assertEquals("query(\"ba.r\")", FeatureNames.canonicalize("query('ba.r')")); + assertEquals("attribute(\"ba.r\")", FeatureNames.canonicalize("attribute(\"ba.r\")")); + } + + @Test public void testArgument() { assertFalse(FeatureNames.argumentOf("foo(bar)").isPresent()); assertFalse(FeatureNames.argumentOf("foo(bar.baz)").isPresent()); @@ -31,20 +42,17 @@ public class FeatureNamesTestCase { @Test public void testConstantFeature() { - assertEquals("constant(\"foo/bar\")", - FeatureNames.asConstantFeature("foo/bar").toString()); + assertEquals("constant(\"foo/bar\")", FeatureNames.asConstantFeature("foo/bar")); } @Test public void testAttributeFeature() { - assertEquals("attribute(foo)", - FeatureNames.asAttributeFeature("foo").toString()); + assertEquals("attribute(foo)", FeatureNames.asAttributeFeature("foo")); } @Test public void testQueryFeature() { - assertEquals("query(\"foo.bar\")", - FeatureNames.asQueryFeature("foo.bar").toString()); + assertEquals("query(\"foo.bar\")", FeatureNames.asQueryFeature("foo.bar")); } } 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 11093d9f008..442c8bd41bd 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java @@ -135,13 +135,13 @@ public class RankProfileTestCase extends SearchDefinitionTestCase { @Test public void requireThatConfigIsDerivedForQueryFeatureTypeSettings() throws ParseException { RankProfileRegistry registry = new RankProfileRegistry(); - SearchBuilder builder = new SearchBuilder(registry, setupQueryProfileTypes()); + SearchBuilder builder = new SearchBuilder(registry); builder.importString("search test {\n" + " document test { } \n" + " rank-profile p1 {}\n" + " rank-profile p2 {}\n" + "}"); - builder.build(new BaseDeployLogger()); + builder.build(new BaseDeployLogger(), setupQueryProfileTypes()); Search search = builder.getSearch(); assertEquals(4, registry.allRankProfiles().size()); @@ -151,7 +151,7 @@ public class RankProfileTestCase extends SearchDefinitionTestCase { assertQueryFeatureTypeSettings(registry.getRankProfile(search, "p2"), search); } - private static QueryProfileRegistry setupQueryProfileTypes() { + private static QueryProfiles setupQueryProfileTypes() { QueryProfileRegistry registry = new QueryProfileRegistry(); QueryProfileTypeRegistry typeRegistry = registry.getTypeRegistry(); QueryProfileType type = new QueryProfileType(new ComponentId("testtype")); @@ -164,7 +164,7 @@ public class RankProfileTestCase extends SearchDefinitionTestCase { type.addField(new FieldDescription("ranking.features.query(numeric)", FieldType.fromString("integer", typeRegistry)), typeRegistry); typeRegistry.register(type); - return registry; + return new QueryProfiles(registry); } private static void assertQueryFeatureTypeSettings(RankProfile profile, Search search) { diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionConstantsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionConstantsTestCase.java index 82b9f5ac043..e94880e61c7 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionConstantsTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionConstantsTestCase.java @@ -207,9 +207,6 @@ public class RankingExpressionConstantsTestCase extends SearchDefinitionTestCase builder.importString( "search test {\n" + " document test { \n" + - " field rating_yelp type int {" + - " indexing: attribute" + - " }" + " }\n" + " \n" + " rank-profile test {\n" + diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionShadowingTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionShadowingTestCase.java index ed1b00e2875..5100ac15c40 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionShadowingTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionShadowingTestCase.java @@ -2,10 +2,7 @@ package com.yahoo.searchdefinition; import com.yahoo.collections.Pair; -import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileRegistry; -import com.yahoo.search.query.profile.types.FieldDescription; -import com.yahoo.search.query.profile.types.QueryProfileType; import com.yahoo.searchdefinition.derived.AttributeFields; import com.yahoo.searchdefinition.derived.RawRankProfile; import com.yahoo.searchdefinition.parser.ParseException; @@ -152,12 +149,11 @@ public class RankingExpressionShadowingTestCase extends SearchDefinitionTestCase censorBindingHash(testRankProperties.get(4).toString())); } + @Test public void testNeuralNetworkSetup() throws ParseException { - // Note: the type assigned to query profile and constant tensors here is not the correct type RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); - QueryProfileRegistry queryProfiles = queryProfileWith("query(q)", "tensor(x[])"); - SearchBuilder builder = new SearchBuilder(rankProfileRegistry, queryProfiles); + SearchBuilder builder = new SearchBuilder(rankProfileRegistry); builder.importString( "search test {\n" + " document test { \n" + @@ -180,28 +176,13 @@ public class RankingExpressionShadowingTestCase extends SearchDefinitionTestCase " expression: sum(final_layer)\n" + " }\n" + " }\n" + - " constant W_hidden {\n" + - " type: tensor(x[])\n" + - " file: ignored.json\n" + - " }\n" + - " constant b_input {\n" + - " type: tensor(x[])\n" + - " file: ignored.json\n" + - " }\n" + - " constant W_final {\n" + - " type: tensor(x[])\n" + - " file: ignored.json\n" + - " }\n" + - " constant b_final {\n" + - " type: tensor(x[])\n" + - " file: ignored.json\n" + - " }\n" + + "\n" + "}\n"); builder.build(); Search s = builder.getSearch(); - RankProfile test = rankProfileRegistry.getRankProfile(s, "test").compile(queryProfiles); + RankProfile test = rankProfileRegistry.getRankProfile(s, "test").compile(new QueryProfileRegistry()); List<Pair<String, String>> testRankProperties = new RawRankProfile(test, - queryProfiles, + new QueryProfileRegistry(), new AttributeFields(s)).configProperties(); assertEquals("(rankingExpression(relu).rankingScript,max(1.0,x))", testRankProperties.get(0).toString()); @@ -217,17 +198,6 @@ public class RankingExpressionShadowingTestCase extends SearchDefinitionTestCase testRankProperties.get(5).toString()); } - private QueryProfileRegistry queryProfileWith(String field, String type) { - QueryProfileType queryProfileType = new QueryProfileType("root"); - queryProfileType.addField(new FieldDescription(field, type)); - QueryProfileRegistry queryProfileRegistry = new QueryProfileRegistry(); - queryProfileRegistry.getTypeRegistry().register(queryProfileType); - QueryProfile profile = new QueryProfile("default"); - profile.setType(queryProfileType); - queryProfileRegistry.register(profile); - return queryProfileRegistry; - } - private String censorBindingHash(String s) { StringBuilder b = new StringBuilder(); boolean areInHash = false; diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java index 0ce6129ef7f..800697b3430 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java @@ -38,8 +38,7 @@ class RankProfileSearchFixture { RankProfileSearchFixture(ApplicationPackage applicationpackage, QueryProfileRegistry queryProfileRegistry, String rankProfiles, String constant, String field) throws ParseException { - this.queryProfileRegistry = queryProfileRegistry; - SearchBuilder builder = new SearchBuilder(applicationpackage, rankProfileRegistry, queryProfileRegistry); + SearchBuilder builder = new SearchBuilder(applicationpackage, rankProfileRegistry, new QueryProfileRegistry()); String sdContent = "search test {\n" + " " + (constant != null ? constant : "") + "\n" + " document test {\n" + @@ -51,6 +50,7 @@ class RankProfileSearchFixture { builder.importString(sdContent); builder.build(); search = builder.getSearch(); + this.queryProfileRegistry = queryProfileRegistry; } public void assertFirstPhaseExpression(String expExpression, String rankProfile) { 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 deleted file mode 100644 index 056d2ad534b..00000000000 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.searchdefinition.processing; - -import com.yahoo.searchdefinition.RankProfile; -import com.yahoo.searchdefinition.RankProfileRegistry; -import com.yahoo.searchdefinition.Search; -import com.yahoo.searchdefinition.SearchBuilder; -import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode; -import com.yahoo.tensor.TensorType; -import com.yahoo.yolean.Exceptions; -import org.junit.Test; - -import java.util.Map; -import java.util.stream.Collectors; - -import static com.yahoo.config.model.test.TestUtil.joinLines; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -/** - * @author bratseth - */ -public class RankingExpressionTypeValidatorTestCase { - - @Test - public void tensorFirstPhaseMustProduceDouble() throws Exception { - try { - SearchBuilder builder = new SearchBuilder(); - builder.importString(joinLines( - "search test {", - " document test { ", - " field a type tensor(x[],y[]) {", - " indexing: attribute", - " }", - " }", - " rank-profile my_rank_profile {", - " first-phase {", - " expression: attribute(a)", - " }", - " }", - "}" - )); - builder.build(); - fail("Expected exception"); - } - catch (IllegalArgumentException expected) { - assertEquals("In search definition 'test', rank profile 'my_rank_profile': The first-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x[],y[])", - Exceptions.toMessageString(expected)); - } - } - - @Test - public void tensorSecondPhaseMustProduceDouble() throws Exception { - try { - SearchBuilder builder = new SearchBuilder(); - builder.importString(joinLines( - "search test {", - " document test { ", - " field a type tensor(x[],y[]) {", - " indexing: attribute", - " }", - " }", - " rank-profile my_rank_profile {", - " first-phase {", - " expression: sum(attribute(a))", - " }", - " second-phase {", - " expression: attribute(a)", - " }", - " }", - "}" - )); - builder.build(); - fail("Expected exception"); - } - catch (IllegalArgumentException expected) { - assertEquals("In search definition 'test', rank profile 'my_rank_profile': The second-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x[],y[])", - Exceptions.toMessageString(expected)); - } - } - - @Test - public void tensorConditionsMustHaveTypeCompatibleBranches() throws Exception { - try { - SearchBuilder searchBuilder = new SearchBuilder(); - searchBuilder.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 {", - " first-phase {", - " expression: sum(if(1>0, attribute(a), attribute(b)))", - " }", - " }", - "}" - )); - searchBuilder.build(); - fail("Expected exception"); - } - catch (IllegalArgumentException expected) { - assertEquals("In search definition 'test', rank profile 'my_rank_profile': The first-phase expression is invalid: An if expression must produce compatible types in both alternatives, but the 'true' type is tensor(x[],y[]) while the 'false' type is tensor(z[10])", - Exceptions.toMessageString(expected)); - } - } - - @Test - public void testMacroInvocationTypes() 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 macro1(attribute_to_use) {", - " expression: attribute(attribute_to_use)", - " }", - " summary-features {", - " macro1(a)", - " macro1(b)", - " }", - " }", - "}" - )); - builder.build(); - RankProfile profile = - builder.getRankProfileRegistry().getRankProfile(builder.getSearch(), "my_rank_profile"); - assertEquals(TensorType.fromSpec("tensor(x[],y[])"), - summaryFeatures(profile).get("macro1(a)").type(profile.typeContext(builder.getQueryProfileRegistry()))); - assertEquals(TensorType.fromSpec("tensor(z[10])"), - summaryFeatures(profile).get("macro1(b)").type(profile.typeContext(builder.getQueryProfileRegistry()))); - } - - @Test - public void testTensorMacroInvocationTypes_Nested() throws Exception { - SearchBuilder builder = new SearchBuilder(); - 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 return_a() {", - " expression: return_first(attribute(a), attribute(b))", - " }", - " macro return_b() {", - " expression: return_second(attribute(a), attribute(b))", - " }", - " macro return_first(e1, e2) {", - " expression: e1", - " }", - " macro return_second(e1, e2) {", - " expression: return_first(e2, e1)", - " }", - " summary-features {", - " return_a", - " return_b", - " }", - " }", - "}" - )); - builder.build(); - RankProfile profile = - builder.getRankProfileRegistry().getRankProfile(builder.getSearch(), "my_rank_profile"); - assertEquals(TensorType.fromSpec("tensor(x[],y[])"), - summaryFeatures(profile).get("return_a").type(profile.typeContext(builder.getQueryProfileRegistry()))); - assertEquals(TensorType.fromSpec("tensor(z[10])"), - summaryFeatures(profile).get("return_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/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java index 96795d2b08f..4693ac5cf4d 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java @@ -73,7 +73,7 @@ public class RankingExpressionWithTensorFlowTestCase { public void testTensorFlowReferenceWithQueryFeature() { String queryProfile = "<query-profile id='default' type='root'/>"; String queryProfileType = "<query-profile-type id='root'>" + - " <field name='query(mytensor)' type='tensor(d0[3],d1[784])'/>" + + " <field name='mytensor' type='tensor(d0[3],d1[784])'/>" + "</query-profile-type>"; StoringApplicationPackage application = new StoringApplicationPackage(applicationDir, queryProfile, @@ -107,7 +107,7 @@ public class RankingExpressionWithTensorFlowTestCase { public void testTensorFlowReferenceWithFeatureCombination() { String queryProfile = "<query-profile id='default' type='root'/>"; String queryProfileType = "<query-profile-type id='root'>" + - " <field name='query(mytensor)' type='tensor(d0[3],d1[784],d2[10])'/>" + + " <field name='mytensor' type='tensor(d0[3],d1[784],d2[10])'/>" + "</query-profile-type>"; StoringApplicationPackage application = new StoringApplicationPackage(applicationDir, queryProfile, diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorTransformTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorTransformTestCase.java index 054c9220225..b001db69768 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorTransformTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorTransformTestCase.java @@ -17,129 +17,98 @@ import com.yahoo.searchdefinition.SearchDefinitionTestCase; import com.yahoo.searchdefinition.derived.AttributeFields; import com.yahoo.searchdefinition.derived.RawRankProfile; import com.yahoo.searchdefinition.parser.ParseException; +import com.yahoo.vespa.model.container.search.QueryProfiles; import org.junit.Test; import java.util.List; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; public class TensorTransformTestCase extends SearchDefinitionTestCase { @Test public void requireThatNormalMaxAndMinAreNotReplaced() throws ParseException { - assertTransformedExpression("max(1.0,2.0)", - "max(1.0,2.0)"); - assertTransformedExpression("min(attribute(double_field),x)", - "min(attribute(double_field),x)"); - assertTransformedExpression("max(attribute(double_field),attribute(double_array_field))", - "max(attribute(double_field),attribute(double_array_field))"); - assertTransformedExpression("min(attribute(tensor_field_1),attribute(double_field))", - "min(attribute(tensor_field_1),attribute(double_field))"); - assertTransformedExpression("reduce(max(attribute(tensor_field_1),attribute(tensor_field_2)),sum)", - "reduce(max(attribute(tensor_field_1),attribute(tensor_field_2)),sum)"); - assertTransformedExpression("min(constant(test_constant_tensor),1.0)", - "min(test_constant_tensor,1.0)"); - assertTransformedExpression("max(constant(base_constant_tensor),1.0)", - "max(base_constant_tensor,1.0)"); - assertTransformedExpression("min(constant(file_constant_tensor),1.0)", - "min(constant(file_constant_tensor),1.0)"); - assertTransformedExpression("max(query(q),1.0)", - "max(query(q),1.0)"); - assertTransformedExpression("max(query(n),1.0)", - "max(query(n),1.0)"); + assertContainsExpression("max(1.0,2.0)", "max(1.0,2.0)"); + assertContainsExpression("min(attribute(double_field),x)", "min(attribute(double_field),x)"); + assertContainsExpression("max(attribute(double_field),attribute(double_array_field))", "max(attribute(double_field),attribute(double_array_field))"); + assertContainsExpression("min(attribute(tensor_field_1),attribute(double_field))", "min(attribute(tensor_field_1),attribute(double_field))"); + assertContainsExpression("max(attribute(tensor_field_1),attribute(tensor_field_2))", "max(attribute(tensor_field_1),attribute(tensor_field_2))"); + assertContainsExpression("min(test_constant_tensor,1.0)", "min(constant(test_constant_tensor),1.0)"); + assertContainsExpression("max(base_constant_tensor,1.0)", "max(constant(base_constant_tensor),1.0)"); + assertContainsExpression("min(constant(file_constant_tensor),1.0)", "min(constant(file_constant_tensor),1.0)"); + assertContainsExpression("max(query(q),1.0)", "max(query(q),1.0)"); + assertContainsExpression("max(query(n),1.0)", "max(query(n),1.0)"); } @Test public void requireThatMaxAndMinWithTensorAttributesAreReplaced() throws ParseException { - assertTransformedExpression("reduce(attribute(tensor_field_1),max,x)", - "max(attribute(tensor_field_1),x)"); - assertTransformedExpression("1+reduce(attribute(tensor_field_1),max,x)", - "1 + max(attribute(tensor_field_1),x)"); - assertTransformedExpression("if(attribute(double_field),1+reduce(attribute(tensor_field_1),max,x),0)", - "if(attribute(double_field),1 + max(attribute(tensor_field_1),x),0)"); - assertTransformedExpression("reduce(max(attribute(tensor_field_1),attribute(tensor_field_2)),max,x)", - "max(max(attribute(tensor_field_1),attribute(tensor_field_2)),x)"); - assertTransformedExpression("reduce(if(attribute(double_field),attribute(tensor_field_2),attribute(tensor_field_2)),max,x)", - "max(if(attribute(double_field),attribute(tensor_field_2),attribute(tensor_field_2)),x)"); - assertTransformedExpression("max(reduce(attribute(tensor_field_1),max,x),x)", - "max(max(attribute(tensor_field_1),x),x)"); // will result in deploy error. - assertTransformedExpression("reduce(reduce(attribute(tensor_field_2),max,x),max,y)", - "max(max(attribute(tensor_field_2),x),y)"); + assertContainsExpression("max(attribute(tensor_field_1),x)", "reduce(attribute(tensor_field_1),max,x)"); + assertContainsExpression("1 + max(attribute(tensor_field_1),x)", "1+reduce(attribute(tensor_field_1),max,x)"); + assertContainsExpression("if(attribute(double_field),1 + max(attribute(tensor_field_1),x),0)", "if(attribute(double_field),1+reduce(attribute(tensor_field_1),max,x),0)"); + assertContainsExpression("max(max(attribute(tensor_field_1),attribute(tensor_field_2)),x)", "reduce(max(attribute(tensor_field_1),attribute(tensor_field_2)),max,x)"); + assertContainsExpression("max(if(attribute(double_field),attribute(tensor_field_1),attribute(tensor_field_2)),x)", "reduce(if(attribute(double_field),attribute(tensor_field_1),attribute(tensor_field_2)),max,x)"); + assertContainsExpression("max(max(attribute(tensor_field_1),x),x)", "max(reduce(attribute(tensor_field_1),max,x),x)"); // will result in deploy error. + assertContainsExpression("max(max(attribute(tensor_field_2),x),y)", "reduce(reduce(attribute(tensor_field_2),max,x),max,y)"); } @Test public void requireThatMaxAndMinWithConstantTensorsAreReplaced() throws ParseException { - assertTransformedExpression("reduce(constant(test_constant_tensor),max,x)", - "max(test_constant_tensor,x)"); - assertTransformedExpression("reduce(constant(base_constant_tensor),max,x)", - "max(base_constant_tensor,x)"); - assertTransformedExpression("reduce(constant(file_constant_tensor),min,x)", - "min(constant(file_constant_tensor),x)"); + assertContainsExpression("max(test_constant_tensor,x)", "reduce(constant(test_constant_tensor),max,x)"); + assertContainsExpression("max(base_constant_tensor,x)", "reduce(constant(base_constant_tensor),max,x)"); + assertContainsExpression("min(constant(file_constant_tensor),x)", "reduce(constant(file_constant_tensor),min,x)"); } @Test public void requireThatMaxAndMinWithTensorExpressionsAreReplaced() throws ParseException { - assertTransformedExpression("reduce(attribute(double_field)+attribute(tensor_field_1),min,x)", - "min(attribute(double_field) + attribute(tensor_field_1),x)"); - assertTransformedExpression("reduce(attribute(tensor_field_1)*attribute(tensor_field_2),min,x)", - "min(attribute(tensor_field_1) * attribute(tensor_field_2),x)"); - assertTransformedExpression("reduce(join(attribute(tensor_field_1),attribute(tensor_field_2),f(x,y)(x*y)),min,x)", - "min(join(attribute(tensor_field_1),attribute(tensor_field_2),f(x,y)(x*y)),x)"); - assertTransformedExpression("min(join(tensor_field_1,tensor_field_2,f(x,y)(x*y)),x)", - "min(join(tensor_field_1,tensor_field_2,f(x,y)(x*y)),x)"); // because tensor fields are not in attribute(...) - assertTransformedExpression("reduce(join(attribute(tensor_field_1),backend_rank_feature,f(x,y)(x*y)),min,x)", - "min(join(attribute(tensor_field_1),backend_rank_feature,f(x,y)(x*y)),x)"); + assertContainsExpression("min(attribute(double_field) + attribute(tensor_field_1),x)", "reduce(attribute(double_field)+attribute(tensor_field_1),min,x)"); + assertContainsExpression("min(attribute(tensor_field_1) * attribute(tensor_field_2),x)", "reduce(attribute(tensor_field_1)*attribute(tensor_field_2),min,x)"); + assertContainsExpression("min(join(attribute(tensor_field_1),attribute(tensor_field_2),f(x,y)(x*y)),x)", "reduce(join(attribute(tensor_field_1),attribute(tensor_field_2),f(x,y)(x*y)),min,x)"); + assertContainsExpression("min(join(tensor_field_1,tensor_field_2,f(x,y)(x*y)),x)", "min(join(tensor_field_1,tensor_field_2,f(x,y)(x*y)),x)"); // because tensor fields are not in attribute(...) + assertContainsExpression("min(join(attribute(tensor_field_1),backend_rank_feature,f(x,y)(x*y)),x)", "reduce(join(attribute(tensor_field_1),backend_rank_feature,f(x,y)(x*y)),min,x)"); } @Test public void requireThatMaxAndMinWithTensorFromIsReplaced() throws ParseException { - assertTransformedExpression("reduce(tensorFromLabels(attribute(double_array_field)),max,double_array_field)", - "max(tensorFromLabels(attribute(double_array_field)),double_array_field)"); - assertTransformedExpression("reduce(tensorFromLabels(attribute(double_array_field),x),max,x)", - "max(tensorFromLabels(attribute(double_array_field),x),x)"); - assertTransformedExpression("reduce(tensorFromWeightedSet(attribute(weightedset_field)),max,weightedset_field)", - "max(tensorFromWeightedSet(attribute(weightedset_field)),weightedset_field)"); - assertTransformedExpression("reduce(tensorFromWeightedSet(attribute(weightedset_field),x),max,x)", - "max(tensorFromWeightedSet(attribute(weightedset_field),x),x)"); + assertContainsExpression("max(tensorFromLabels(attribute(double_array_field)),double_array_field)", "reduce(tensorFromLabels(attribute(double_array_field)),max,double_array_field)"); + assertContainsExpression("max(tensorFromLabels(attribute(double_array_field),x),x)", "reduce(tensorFromLabels(attribute(double_array_field),x),max,x)"); + assertContainsExpression("max(tensorFromWeightedSet(attribute(weightedset_field)),weightedset_field)", "reduce(tensorFromWeightedSet(attribute(weightedset_field)),max,weightedset_field)"); + assertContainsExpression("max(tensorFromWeightedSet(attribute(weightedset_field),x),x)", "reduce(tensorFromWeightedSet(attribute(weightedset_field),x),max,x)"); } @Test public void requireThatMaxAndMinWithTensorInQueryIsReplaced() throws ParseException { - assertTransformedExpression("reduce(query(q),max,x)", "max(query(q),x)"); - assertTransformedExpression("max(query(n),x)", "max(query(n),x)"); + assertContainsExpression("max(query(q),x)", "reduce(query(q),max,x)"); + assertContainsExpression("max(query(n),x)", "max(query(n),x)"); } @Test public void requireThatMaxAndMinWithTensoresReturnedFromMacrosAreReplaced() throws ParseException { - assertTransformedExpression("reduce(rankingExpression(returns_tensor),max,x)", - "max(returns_tensor,x)"); - assertTransformedExpression("reduce(rankingExpression(wraps_returns_tensor),max,x)", - "max(wraps_returns_tensor,x)"); - assertTransformedExpression("reduce(rankingExpression(tensor_inheriting),max,x)", - "max(tensor_inheriting,x)"); - assertTransformedExpression("reduce(rankingExpression(returns_tensor_with_arg@),max,x)", - "max(returns_tensor_with_arg(attribute(tensor_field_1)),x)"); + assertContainsExpression("max(returns_tensor,x)", "reduce(rankingExpression(returns_tensor),max,x)"); + assertContainsExpression("max(wraps_returns_tensor,x)", "reduce(rankingExpression(wraps_returns_tensor),max,x)"); + assertContainsExpression("max(tensor_inheriting,x)", "reduce(rankingExpression(tensor_inheriting),max,x)"); + assertContainsExpression("max(returns_tensor_with_arg(attribute(tensor_field_1)),x)", "reduce(rankingExpression(returns_tensor_with_arg@),max,x)"); } - private void assertTransformedExpression(String expected, String original) throws ParseException { - for (Pair<String, String> rankPropertyExpression : buildSearch(original)) { + private void assertContainsExpression(String expr, String transformedExpression) throws ParseException { + assertTrue("Expected expression '" + transformedExpression + "' found", + containsExpression(expr, transformedExpression)); + } + + private boolean containsExpression(String expr, String transformedExpression) throws ParseException { + for (Pair<String, String> rankPropertyExpression : buildSearch(expr)) { String rankProperty = rankPropertyExpression.getFirst(); if (rankProperty.equals("rankingExpression(firstphase).rankingScript")) { String rankExpression = censorBindingHash(rankPropertyExpression.getSecond().replace(" ","")); - assertEquals(expected, rankExpression); - return; + return rankExpression.equals(transformedExpression); } } - fail("No 'rankingExpression(firstphase).rankingScript' property produced"); + return false; } private List<Pair<String, String>> buildSearch(String expression) throws ParseException { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); - QueryProfileRegistry queryProfiles = setupQueryProfileTypes(); - SearchBuilder builder = new SearchBuilder(rankProfileRegistry, queryProfiles); + SearchBuilder builder = new SearchBuilder(rankProfileRegistry); builder.importString( "search test {\n" + " document test { \n" + @@ -198,16 +167,16 @@ public class TensorTransformTestCase extends SearchDefinitionTestCase { " }\n" + " }\n" + "}\n"); - builder.build(new BaseDeployLogger()); + builder.build(new BaseDeployLogger(), setupQueryProfileTypes()); Search s = builder.getSearch(); - RankProfile test = rankProfileRegistry.getRankProfile(s, "test").compile(queryProfiles); + RankProfile test = rankProfileRegistry.getRankProfile(s, "test").compile(new QueryProfileRegistry()); List<Pair<String, String>> testRankProperties = new RawRankProfile(test, - queryProfiles, + new QueryProfileRegistry(), new AttributeFields(s)).configProperties(); return testRankProperties; } - private static QueryProfileRegistry setupQueryProfileTypes() { + private static QueryProfiles setupQueryProfileTypes() { QueryProfileRegistry registry = new QueryProfileRegistry(); QueryProfileTypeRegistry typeRegistry = registry.getTypeRegistry(); QueryProfileType type = new QueryProfileType(new ComponentId("testtype")); @@ -216,7 +185,7 @@ public class TensorTransformTestCase extends SearchDefinitionTestCase { type.addField(new FieldDescription("ranking.features.query(n)", FieldType.fromString("integer", typeRegistry)), typeRegistry); typeRegistry.register(type); - return registry; + return new QueryProfiles(registry); } private String censorBindingHash(String s) { |