From bfc460a89a117706dc54342707abb45a5f18252e Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 29 Mar 2023 17:27:23 +0200 Subject: - Use CompoundName.from - Deprecate unused SubProperties --- .../java/com/yahoo/search/dispatch/Dispatcher.java | 2 +- .../search/grouping/result/FlatteningSearcher.java | 2 +- .../search/grouping/vespa/GroupingExecutor.java | 2 +- .../profile/compiled/CompiledQueryProfile.java | 2 +- .../query/profile/types/FieldDescription.java | 2 +- .../query/profile/types/QueryProfileType.java | 8 ++--- .../search/query/properties/SubProperties.java | 4 ++- .../yahoo/search/query/ranking/SoftTimeout.java | 3 +- .../query/properties/SubPropertiesTestCase.java | 40 ++++++++++++++++++++++ .../properties/test/SubPropertiesTestCase.java | 39 --------------------- 10 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 container-search/src/test/java/com/yahoo/search/query/properties/SubPropertiesTestCase.java delete mode 100644 container-search/src/test/java/com/yahoo/search/query/properties/test/SubPropertiesTestCase.java (limited to 'container-search/src') diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java b/container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java index 09db1be4732..4e4b77422c1 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java @@ -52,7 +52,7 @@ public class Dispatcher extends AbstractComponent { private static final int MAX_GROUP_SELECTION_ATTEMPTS = 3; /** If set will control computation of how many hits will be fetched from each partition.*/ - public static final CompoundName topKProbability = CompoundName.fromComponents(DISPATCH, TOP_K_PROBABILITY); + public static final CompoundName topKProbability = CompoundName.from(DISPATCH + "." + TOP_K_PROBABILITY); private final DispatchConfig dispatchConfig; private final RpcResourcePool rpcResourcePool; diff --git a/container-search/src/main/java/com/yahoo/search/grouping/result/FlatteningSearcher.java b/container-search/src/main/java/com/yahoo/search/grouping/result/FlatteningSearcher.java index e56b88c3d3e..027ba92f587 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/result/FlatteningSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/result/FlatteningSearcher.java @@ -22,7 +22,7 @@ import java.util.Iterator; @Before(GroupingExecutor.COMPONENT_NAME) public class FlatteningSearcher extends Searcher { - private final CompoundName flatten = CompoundName.fromComponents("grouping", "flatten"); + private final CompoundName flatten = CompoundName.from("grouping.flatten"); @Override public Result search(Query query, Execution execution) { diff --git a/container-search/src/main/java/com/yahoo/search/grouping/vespa/GroupingExecutor.java b/container-search/src/main/java/com/yahoo/search/grouping/vespa/GroupingExecutor.java index 2ba33f60ea1..c85dbed83c8 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/vespa/GroupingExecutor.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/vespa/GroupingExecutor.java @@ -379,7 +379,7 @@ public class GroupingExecutor extends Searcher { } private static CompoundName newCompoundName(String name) { - return new CompoundName(GroupingExecutor.class.getName() + "." + name); + return CompoundName.from(GroupingExecutor.class.getName() + "." + name); } private static class RequestContext { diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java index ad9d3f4c1a5..ae531c67dd1 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java @@ -169,7 +169,7 @@ public class CompiledQueryProfile extends AbstractComponent implements Cloneable } public final Object get(String name) { - return get(name, Collections.emptyMap()); + return get(name, Map.of()); } public final Object get(String name, Map context) { return get(name, context, new QueryProfileProperties(this)); diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java index 8fdbf8b2281..719a5a2c281 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java @@ -64,7 +64,7 @@ public class FieldDescription implements Comparable { } public FieldDescription(String name, FieldType type, String aliases, boolean mandatory, boolean overridable) { - this(new CompoundName(name), type, aliases, mandatory, overridable); + this(CompoundName.from(name), type, aliases, mandatory, overridable); } /** 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 3da2ad53f9a..9cbfe5b7112 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 @@ -52,7 +52,7 @@ public class QueryProfileType extends FreezableSimpleComponent { private QueryProfileType(ComponentId id, Map fields, List inherited) { super(id); QueryProfile.validateName(id.getName()); - componentIdAsCompoundName = new CompoundName(getId().getName()); + componentIdAsCompoundName = CompoundName.from(getId().getName()); this.fields = fields; this.inherited = inherited; } @@ -318,10 +318,9 @@ public class QueryProfileType extends FreezableSimpleComponent { QueryProfileType type = null; FieldDescription fieldDescription = getField(name); if (fieldDescription != null) { - if ( ! (fieldDescription.getType() instanceof QueryProfileFieldType)) + if ( ! (fieldDescription.getType() instanceof QueryProfileFieldType fieldType)) throw new IllegalArgumentException("Cannot use name '" + name + "' as a prefix because it is " + "already a " + fieldDescription.getType()); - QueryProfileFieldType fieldType = (QueryProfileFieldType) fieldDescription.getType(); type = fieldType.getQueryProfileType(); } @@ -399,8 +398,7 @@ public class QueryProfileType extends FreezableSimpleComponent { @Override public boolean equals(Object o) { if (o == this) return true; - if ( ! (o instanceof QueryProfileType)) return false; - QueryProfileType other = (QueryProfileType)o; + if ( ! (o instanceof QueryProfileType other)) return false; return other.getId().equals(this.getId()); } diff --git a/container-search/src/main/java/com/yahoo/search/query/properties/SubProperties.java b/container-search/src/main/java/com/yahoo/search/query/properties/SubProperties.java index 42fb4e44040..4fc9dfa03cd 100644 --- a/container-search/src/main/java/com/yahoo/search/query/properties/SubProperties.java +++ b/container-search/src/main/java/com/yahoo/search/query/properties/SubProperties.java @@ -10,14 +10,16 @@ import java.util.Map; * A wrapper around a chain of property objects that prefixes all gets/sets with a given path * * @author Arne Bergene Fossaa + * @deprecated Unused and will go away on vespa 9 */ +@Deprecated (forRemoval = true) public class SubProperties extends com.yahoo.search.query.Properties { final private CompoundName pathPrefix; final private Properties parent; public SubProperties(String pathPrefix, Properties properties) { - this(new CompoundName(pathPrefix),properties); + this(CompoundName.from(pathPrefix), properties); } public SubProperties(CompoundName pathPrefix, Properties properties) { diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java b/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java index 30ee2f473b7..c49b14f0978 100644 --- a/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java +++ b/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java @@ -24,8 +24,7 @@ public class SoftTimeout implements Cloneable { public static final String TAILCOST = "tailcost"; /** The full property name for turning softtimeout on or off */ - public static final CompoundName enableProperty = - CompoundName.fromComponents(Ranking.RANKING, Ranking.SOFTTIMEOUT, ENABLE); + public static final CompoundName enableProperty = CompoundName.from(Ranking.RANKING + "." + Ranking.SOFTTIMEOUT + "." + ENABLE); static { argumentType = new QueryProfileType(Ranking.SOFTTIMEOUT); diff --git a/container-search/src/test/java/com/yahoo/search/query/properties/SubPropertiesTestCase.java b/container-search/src/test/java/com/yahoo/search/query/properties/SubPropertiesTestCase.java new file mode 100644 index 00000000000..6b25dc526d9 --- /dev/null +++ b/container-search/src/test/java/com/yahoo/search/query/properties/SubPropertiesTestCase.java @@ -0,0 +1,40 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.search.query.properties; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.util.Arrays; +import java.util.HashSet; + +import com.yahoo.processing.request.properties.PropertyMap; +import org.junit.jupiter.api.Test; + +/** + * @author Arne Bergene Fossaa + */ +@SuppressWarnings({"removal"}) + +public class SubPropertiesTestCase { + + @Test + void testSubProperties() { + PropertyMap map = new PropertyMap() { + { + set("a.e", "1"); + set("a.f", 2); + set("b.e", "3"); + set("f", 3); + set("e", "2"); + set("d", "a"); + } + }; + + SubProperties sub = new SubProperties("a", map); + assertEquals("1", sub.get("e")); + assertEquals(2, sub.get("f")); + assertNull(sub.get("d")); + assertEquals(new HashSet<>(Arrays.asList("e", "f")), sub.listProperties("").keySet()); + } + +} diff --git a/container-search/src/test/java/com/yahoo/search/query/properties/test/SubPropertiesTestCase.java b/container-search/src/test/java/com/yahoo/search/query/properties/test/SubPropertiesTestCase.java deleted file mode 100644 index 0e9bf8d41ec..00000000000 --- a/container-search/src/test/java/com/yahoo/search/query/properties/test/SubPropertiesTestCase.java +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.query.properties.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.util.Arrays; -import java.util.HashSet; - -import com.yahoo.processing.request.properties.PropertyMap; -import org.junit.jupiter.api.Test; -import com.yahoo.search.query.properties.SubProperties; - -/** - * @author Arne Bergene Fossaa - */ -public class SubPropertiesTestCase { - - @Test - void testSubProperties() { - PropertyMap map = new PropertyMap() { - { - set("a.e", "1"); - set("a.f", 2); - set("b.e", "3"); - set("f", 3); - set("e", "2"); - set("d", "a"); - } - }; - - SubProperties sub = new SubProperties("a", map); - assertEquals("1", sub.get("e")); - assertEquals(2, sub.get("f")); - assertNull(sub.get("d")); - assertEquals(new HashSet<>(Arrays.asList("e", "f")), sub.listProperties("").keySet()); - } - -} -- cgit v1.2.3