diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-10-29 15:04:12 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-10-29 15:04:12 +0200 |
commit | 08621c467af33aefb5e5ebf8761951b2ee662f2e (patch) | |
tree | 697145fcd4d6f0336c7b2639aa1df150caccaf85 /container-search | |
parent | 91d9fdf134e51322d57d1634253ded11a5ad9f48 (diff) |
Stable query profile type ids
Diffstat (limited to 'container-search')
8 files changed, 24 insertions, 5 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileRegistry.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileRegistry.java index 74d3b4a3525..1910078058a 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileRegistry.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileRegistry.java @@ -92,5 +92,4 @@ public class QueryProfileRegistry extends ComponentRegistry<QueryProfile> { return ComponentId.newAnonymous(name + "_" + (nextAnonymousId++)); } - } diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java index c9fcb854771..8b6470996d5 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java @@ -321,13 +321,13 @@ public class QueryProfileType extends FreezableSimpleComponent { // found in registry but not already added in *this* type (getField also checks parents): extend it if (type != null && ! fields.containsKey(name)) { - type = new QueryProfileType(ComponentId.createAnonymousComponentId(type.getIdString()), + type = new QueryProfileType(registry.createAnonymousId(type.getIdString()), new HashMap<>(), List.of(type)); } if (type == null) { // create it - type = new QueryProfileType(ComponentId.createAnonymousComponentId(name)); + type = new QueryProfileType(registry.createAnonymousId(name)); } if (fieldDescription == null) { diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileTypeRegistry.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileTypeRegistry.java index 58a1ae7ad14..201f246b30c 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileTypeRegistry.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileTypeRegistry.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.profile.types; +import com.yahoo.component.ComponentId; import com.yahoo.component.provider.ComponentRegistry; import com.yahoo.search.Query; import com.yahoo.search.query.profile.QueryProfileRegistry; @@ -12,6 +13,8 @@ import com.yahoo.search.query.profile.QueryProfileRegistry; */ public class QueryProfileTypeRegistry extends ComponentRegistry<QueryProfileType> { + private int nextAnonymousId = 0; + private final int nativeProfileCount; public QueryProfileTypeRegistry() { @@ -42,4 +45,8 @@ public class QueryProfileTypeRegistry extends ComponentRegistry<QueryProfileType return registry; } + public ComponentId createAnonymousId(String name) { + return ComponentId.newAnonymous(name + "_" + (nextAnonymousId++)); + } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java index a24e9af5928..c47e1e5b23c 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java @@ -456,11 +456,17 @@ public class XmlReadingTestCase { public void testAnonymousIdsAreStableBetweenImports() { QueryProfileRegistry registry1 = new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance"); var childIn1 = registry1.findQueryProfile("child"); + var childTypeIn1 = registry1.getType("childType"); QueryProfileRegistry registry2 = new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance"); var childIn2 = registry2.findQueryProfile("child"); + var childTypeIn2 = registry2.getType("childType"); + assertEquals(((QueryProfile)childIn1.lookup("a", Map.of())).getId().stringValue(), ((QueryProfile)childIn2.lookup("a", Map.of())).getId().stringValue()); + + assertEquals(childTypeIn1.getType("a").getId().stringValue(), + childTypeIn2.getType("a").getId().stringValue()); } @Test diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/child.xml b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/child.xml index 10edbacba60..20186c440df 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/child.xml +++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/child.xml @@ -1,5 +1,5 @@ <!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> -<query-profile id="child" inherits="parent"> +<query-profile id="child" inherits="parent" type="childType"> <field name="a.b.c">a.b.c-child</field> </query-profile> diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/parent.xml b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/parent.xml index 2e576186628..21a19eda24f 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/parent.xml +++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/parent.xml @@ -1,5 +1,5 @@ <!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> -<query-profile id="parent"> +<query-profile id="parent" type="parentType"> <field name="a.b">a.b-parent</field> <field name="a.b.c">a.b.c-parent</field> </query-profile> diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/types/childType.xml b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/types/childType.xml new file mode 100644 index 00000000000..18665d195b9 --- /dev/null +++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/types/childType.xml @@ -0,0 +1,4 @@ +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<query-profile-type id="childType" inherits="parentType"> + <field name="a.b.c" type="string"/> +</query-profile-type> diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/types/parentType.xml b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/types/parentType.xml new file mode 100644 index 00000000000..771c373df12 --- /dev/null +++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/typedinheritance/types/parentType.xml @@ -0,0 +1,3 @@ +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<query-profile-type id="parentType"> +</query-profile-type> |