diff options
author | Bjørn Christian Seime <bjorn.christian@seime.no> | 2022-12-02 14:52:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-02 14:52:26 +0100 |
commit | 81b884ac555806ae2f0a75773accfd8fe27ecbe1 (patch) | |
tree | 0f92b9ef73a90854cacc96796562d3f21ff1cff6 /container-search/src | |
parent | c956ac4cb73b329243072aabe35f0da508c02d0f (diff) |
Revert "Let list handling catch up with Java 17"
Diffstat (limited to 'container-search/src')
22 files changed, 218 insertions, 137 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java b/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java index 90194f3ba6a..c9a855c2f34 100644 --- a/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java +++ b/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java @@ -1,16 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude; +import com.google.common.collect.ImmutableList; import com.yahoo.search.Query; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; import static com.yahoo.text.Lowercase.toLowerCase; @@ -63,6 +57,7 @@ public class IndexFacts { public IndexFacts() {} + @SuppressWarnings({"deprecation"}) public IndexFacts(IndexModel indexModel) { if (indexModel.getSearchDefinitions() != null) { this.searchDefinitions = indexModel.getSearchDefinitions(); @@ -90,16 +85,20 @@ public class IndexFacts { } private static void addEntry(Map<String, List<String>> result, String key, String value) { - List<String> values = result.computeIfAbsent(key, k -> new ArrayList<>()); + List<String> values = result.get(key); + if (values == null) { + values = new ArrayList<>(); + result.put(key, values); + } values.add(value); } // Assumes that document names are equal to the search definition that contain them. public List<String> clustersHavingSearchDefinition(String searchDefinitionName) { - if (clusterByDocument == null) return List.of(); + if (clusterByDocument == null) return Collections.emptyList(); List<String> clusters = clusterByDocument.get(searchDefinitionName); - return clusters != null ? clusters : List.of(); + return clusters != null ? clusters : Collections.<String>emptyList(); } private boolean isInitialized() { @@ -169,9 +168,9 @@ public class IndexFacts { } private Collection<Index> getIndexes(String documentType) { - if ( ! isInitialized()) return List.of(); + if ( ! isInitialized()) return Collections.emptyList(); SearchDefinition sd = searchDefinitions.get(documentType); - if (sd == null) return List.of(); + if (sd == null) return Collections.emptyList(); return sd.indices().values(); } @@ -232,7 +231,7 @@ public class IndexFacts { } private Collection<String> emptyCollectionIfNull(Collection<String> collection) { - return collection == null ? List.of() : collection; + return collection == null ? Collections.<String>emptyList() : collection; } /** @@ -319,7 +318,7 @@ public class IndexFacts { private final List<String> documentTypes; private Session(Query query) { - documentTypes = List.copyOf(resolveDocumentTypes(query)); + documentTypes = ImmutableList.copyOf(resolveDocumentTypes(query)); } private Session(Collection<String> sources, Collection<String> restrict) { @@ -348,7 +347,7 @@ public class IndexFacts { // currently by the flat structure in IndexFacts. // That can be fixed without changing this API. public Index getIndex(String indexName, String documentType) { - return IndexFacts.this.getIndexFromDocumentTypes(indexName, List.of(documentType)); + return IndexFacts.this.getIndexFromDocumentTypes(indexName, Collections.singletonList(documentType)); } /** Returns all the indexes of a given search definition */ diff --git a/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java b/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java index ea78b2365c5..59dad29ab5c 100644 --- a/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java +++ b/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import com.google.common.collect.ImmutableList; import com.yahoo.compress.IntegerCompressor; /** @@ -29,7 +30,7 @@ public class WordAlternativesItem extends TermItem { this.alternatives = uniqueAlternatives(terms); } - private static List<Alternative> uniqueAlternatives(Collection<Alternative> terms) { + private static ImmutableList<Alternative> uniqueAlternatives(Collection<Alternative> terms) { List<Alternative> uniqueTerms = new ArrayList<>(terms.size()); for (Alternative term : terms) { int i = Collections.binarySearch(uniqueTerms, term, (t0, t1) -> t0.word.compareTo(t1.word)); @@ -42,7 +43,7 @@ public class WordAlternativesItem extends TermItem { uniqueTerms.add(~i, term); } } - return List.copyOf(uniqueTerms); + return ImmutableList.copyOf(uniqueTerms); } @Override @@ -176,7 +177,8 @@ public class WordAlternativesItem extends TermItem { @Override public boolean equals(Object o) { - if ( ! (o instanceof Alternative other)) return false; + if ( ! (o instanceof Alternative)) return false; + var other = (Alternative)o; if ( ! Objects.equals(this.word, other.word)) return false; if (this.exactness != other.exactness) return false; return true; diff --git a/container-search/src/main/java/com/yahoo/search/Query.java b/container-search/src/main/java/com/yahoo/search/Query.java index cff43e07d70..be964081326 100644 --- a/container-search/src/main/java/com/yahoo/search/Query.java +++ b/container-search/src/main/java/com/yahoo/search/Query.java @@ -2,6 +2,7 @@ package com.yahoo.search; import ai.vespa.cloud.ZoneInfo; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.language.process.Embedder; @@ -261,7 +262,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { /** Returns an unmodifiable list of all the native properties under a Query */ public static final List<CompoundName> nativeProperties = - List.copyOf(namesUnder(CompoundName.empty, Query.getArgumentType())); + ImmutableList.copyOf(namesUnder(CompoundName.empty, Query.getArgumentType())); private static List<CompoundName> namesUnder(CompoundName prefix, QueryProfileType type) { if (type == null) return Collections.emptyList(); // Names not known statically diff --git a/container-search/src/main/java/com/yahoo/search/federation/FederationResult.java b/container-search/src/main/java/com/yahoo/search/federation/FederationResult.java index 89c45fde6ae..f6cbb49f7d5 100644 --- a/container-search/src/main/java/com/yahoo/search/federation/FederationResult.java +++ b/container-search/src/main/java/com/yahoo/search/federation/FederationResult.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.federation; +import com.google.common.collect.ImmutableList; import com.yahoo.search.Result; import com.yahoo.search.searchchain.FutureResult; @@ -26,9 +27,9 @@ class FederationResult { * The remaining targets to wait for. * Other targets are either complete, or should only be included if they are available when we complete */ - private final List<TargetResult> targetsToWaitFor; + private List<TargetResult> targetsToWaitFor; - private FederationResult(List<TargetResult> targetResults) { + private FederationResult(ImmutableList<TargetResult> targetResults) { this.targetResults = targetResults; if (targetResults.stream().anyMatch(TargetResult::isMandatory)) @@ -93,7 +94,7 @@ class FederationResult { public Optional<Result> getIfAvailable(long timeout) { if (availableResult.isPresent()) return availableResult; availableResult = futureResult.getIfAvailable(timeout, TimeUnit.MILLISECONDS); - availableResult.ifPresent(target::modifyTargetResult); + availableResult.ifPresent(result -> target.modifyTargetResult(result)); return availableResult; } @@ -120,14 +121,14 @@ class FederationResult { public static class Builder { - private final List<TargetResult> results = new ArrayList<>(); + private final ImmutableList.Builder<TargetResult> results = new ImmutableList.Builder(); public void add(FederationSearcher.Target target, FutureResult futureResult) { results.add(new TargetResult(target, futureResult)); } public FederationResult build() { - return new FederationResult(List.copyOf(results)); + return new FederationResult(results.build()); } } diff --git a/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java b/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java index 80a41ffdf22..21b4d1d538f 100644 --- a/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.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.federation; +import com.google.common.collect.ImmutableList; import com.yahoo.component.annotation.Inject; import com.yahoo.collections.Pair; import com.yahoo.component.ComponentId; @@ -9,6 +10,7 @@ import com.yahoo.component.chain.Chain; import com.yahoo.component.chain.dependencies.After; import com.yahoo.component.chain.dependencies.Provides; import com.yahoo.component.provider.ComponentRegistry; +import com.yahoo.concurrent.CopyOnWriteHashMap; import com.yahoo.errorhandling.Results; import com.yahoo.errorhandling.Results.Builder; import com.yahoo.prelude.IndexFacts; @@ -26,6 +28,7 @@ import com.yahoo.search.federation.sourceref.SourceRefResolver; import com.yahoo.search.federation.sourceref.SourcesTarget; import com.yahoo.search.federation.sourceref.UnresolvedSearchChainException; import com.yahoo.search.query.Properties; +import com.yahoo.search.query.properties.SubProperties; import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.result.Hit; import com.yahoo.search.result.HitGroup; @@ -74,9 +77,11 @@ public class FederationSearcher extends ForkingSearcher { public final static CompoundName PROVIDERNAME = new CompoundName("providerName"); public static final String FEDERATION = "Federation"; public static final String LOG_COUNT_PREFIX = "count_"; + private static final List<CompoundName> queryAndHits = ImmutableList.of(Query.OFFSET, Query.HITS); private final SearchChainResolver searchChainResolver; private final SourceRefResolver sourceRefResolver; + private final CopyOnWriteHashMap<CompoundKey, CompoundName> map = new CopyOnWriteHashMap<>(); private final TargetSelector<?> targetSelector; private final Clock clock = Clock.systemUTC(); @@ -333,6 +338,22 @@ public class FederationSearcher extends ForkingSearcher { return commentedSearchChains; } + /** + * Returns the set of properties set for the source or provider given in the query (if any). + * + * If the query has not set sourceName or providerName, null will be returned + */ + public static Properties getSourceProperties(Query query) { + String sourceName = query.properties().getString(SOURCENAME); + String providerName = query.properties().getString(PROVIDERNAME); + if (sourceName == null || providerName == null) + return null; + Properties sourceProperties = new SubProperties("source." + sourceName, query.properties()); + Properties providerProperties = new SubProperties("provider." + providerName, query.properties()); + sourceProperties.chain(providerProperties); + return sourceProperties; + } + @Override public void fill(Result result, String summaryClass, Execution execution) { UniqueExecutionsToResults uniqueExecutionsToResults = new UniqueExecutionsToResults(); @@ -641,8 +662,9 @@ public class FederationSearcher extends ForkingSearcher { @Override public boolean equals(Object o) { if (o == this) return true; - if ( ! (o instanceof StandardTarget other)) return false; + if ( ! ( o instanceof StandardTarget)) return false; + StandardTarget other = (StandardTarget)o; if ( ! Objects.equals(other.chain.getId(), this.chain.getId())) return false; if ( ! Objects.equals(other.target, this.target)) return false; return true; diff --git a/container-search/src/main/java/com/yahoo/search/federation/sourceref/SearchChainInvocationSpec.java b/container-search/src/main/java/com/yahoo/search/federation/sourceref/SearchChainInvocationSpec.java index f432289d2c1..34eeb3ce82c 100644 --- a/container-search/src/main/java/com/yahoo/search/federation/sourceref/SearchChainInvocationSpec.java +++ b/container-search/src/main/java/com/yahoo/search/federation/sourceref/SearchChainInvocationSpec.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.federation.sourceref; +import com.google.common.collect.ImmutableList; import com.yahoo.component.ComponentId; import com.yahoo.search.searchchain.model.federation.FederationOptions; @@ -23,7 +24,7 @@ public class SearchChainInvocationSpec implements Cloneable { public final ComponentId provider; public final FederationOptions federationOptions; - public final List<String> documentTypes; + public final ImmutableList<String> documentTypes; SearchChainInvocationSpec(ComponentId searchChainId, ComponentId source, ComponentId provider, FederationOptions federationOptions, @@ -32,7 +33,7 @@ public class SearchChainInvocationSpec implements Cloneable { this.source = source; this.provider = provider; this.federationOptions = federationOptions; - this.documentTypes = List.copyOf(documentTypes); + this.documentTypes = ImmutableList.copyOf(documentTypes); } @Override @@ -43,8 +44,9 @@ public class SearchChainInvocationSpec implements Cloneable { @Override public boolean equals(Object o) { if (o == this) return true; - if ( ! (o instanceof SearchChainInvocationSpec other)) return false; + if ( ! ( o instanceof SearchChainInvocationSpec)) return false; + SearchChainInvocationSpec other = (SearchChainInvocationSpec)o; if ( ! Objects.equals(this.searchChainId, other.searchChainId)) return false; if ( ! Objects.equals(this.source, other.source)) return false; if ( ! Objects.equals(this.provider, other.provider)) return false; diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java index b58bd64209b..e3ab49f0e32 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.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; +import com.google.common.collect.ImmutableList; import com.yahoo.component.ComponentId; import com.yahoo.component.provider.FreezableSimpleComponent; import com.yahoo.processing.IllegalInputException; @@ -419,7 +420,7 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable content.freeze(); - inherited= inherited==null ? List.of() : List.copyOf(inherited); + inherited= inherited==null ? ImmutableList.of() : ImmutableList.copyOf(inherited); super.freeze(); } @@ -615,7 +616,8 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable * be added (usually because the new value was added to the existing). */ static Object combineValues(Object newValue, Object existingValue) { - if (newValue instanceof QueryProfile newProfile) { + if (newValue instanceof QueryProfile) { + QueryProfile newProfile = (QueryProfile)newValue; if ( ! (existingValue instanceof QueryProfile)) { if ( ! isModifiable(newProfile)) { // Make the query profile reference overridable @@ -629,7 +631,8 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable return combineProfiles(newProfile, (QueryProfile)existingValue); } else { - if (existingValue instanceof QueryProfile existingProfile) { // we need to set a non-leaf value on a query profile + if (existingValue instanceof QueryProfile) { // we need to set a non-leaf value on a query profile + QueryProfile existingProfile = (QueryProfile)existingValue; if (isModifiable(existingProfile)) { existingProfile.setValue(newValue); return null; diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariant.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariant.java index 57aa3516dfc..7fc8bfd40ab 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariant.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariant.java @@ -1,13 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.profile; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.yahoo.search.query.profile.types.QueryProfileType; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import java.util.*; /** * A variant of a query profile @@ -42,7 +40,7 @@ public class QueryProfileVariant implements Cloneable, Comparable<QueryProfileVa public Map<String, Object> values() { if (values == null) { if (frozen) - return Map.of(); + return Collections.emptyMap(); else values = new HashMap<>(); } @@ -56,7 +54,7 @@ public class QueryProfileVariant implements Cloneable, Comparable<QueryProfileVa public List<QueryProfile> inherited() { if (inherited == null) { if (frozen) - return List.of(); + return Collections.emptyList(); else inherited = new ArrayList<>(); } @@ -142,9 +140,9 @@ public class QueryProfileVariant implements Cloneable, Comparable<QueryProfileVa public void freeze() { if (frozen) return; if (inherited != null) - inherited = List.copyOf(inherited); + inherited = ImmutableList.copyOf(inherited); if (values != null) - values = Map.copyOf(values); + values = ImmutableMap.copyOf(values); frozen=true; } diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariants.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariants.java index 1b0472c5b17..845c2cfd384 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariants.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariants.java @@ -1,15 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.profile; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.yahoo.component.provider.Freezable; import com.yahoo.search.query.profile.types.QueryProfileType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * This class represent a set of query profiles virtually - rather @@ -57,7 +54,7 @@ public class QueryProfileVariants implements Freezable, Cloneable { * on lookup time to influence the value returned. */ public QueryProfileVariants(String[] dimensions, QueryProfile owner) { - this(List.of(dimensions), owner); + this(Arrays.asList(dimensions), owner); } /** @@ -80,13 +77,13 @@ public class QueryProfileVariants implements Freezable, Cloneable { if (frozen) return; for (FieldValues fieldValues : fieldValuesByName.values()) fieldValues.freeze(); - fieldValuesByName = Map.copyOf(fieldValuesByName); + fieldValuesByName = ImmutableMap.copyOf(fieldValuesByName); inheritedProfiles.freeze(); Collections.sort(variants); for (QueryProfileVariant variant : variants) variant.freeze(); - variants = List.copyOf(variants); + variants = ImmutableList.copyOf(variants); frozen=true; } @@ -334,7 +331,7 @@ public class QueryProfileVariants implements Freezable, Cloneable { if (frozen) return; sort(); if (resolutionList != null) - resolutionList = List.copyOf(resolutionList); + resolutionList = ImmutableList.copyOf(resolutionList); frozen = true; } 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..f30a3cc5ae6 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 @@ -1,9 +1,11 @@ // 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.google.common.collect.ImmutableList; import com.yahoo.processing.request.CompoundName; import com.yahoo.search.query.profile.QueryProfile; +import java.util.Arrays; import java.util.List; /** @@ -94,14 +96,14 @@ public class FieldDescription implements Comparable<FieldDescription> { if (name.isCompound() && ! aliases.isEmpty()) throw new IllegalArgumentException("Aliases are not allowed with compound names"); - this.aliases = List.copyOf(aliases); + this.aliases = ImmutableList.copyOf(aliases); this.mandatory = mandatory; this.overridable = overridable; } private static List<String> toList(String string) { - if (string == null || string.isEmpty()) return List.of(); - return List.of(string.split(" ")); + if (string == null || string.isEmpty()) return ImmutableList.of(); + return ImmutableList.copyOf(Arrays.asList(string.split(" "))); } /** Returns the full name of this as a string */ 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..02a4199d32e 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 @@ -1,9 +1,12 @@ // 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.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.yahoo.component.ComponentId; import com.yahoo.component.provider.FreezableSimpleComponent; import com.yahoo.processing.request.CompoundName; +import com.yahoo.search.query.profile.OverridableQueryProfile; import com.yahoo.search.query.profile.QueryProfile; import java.util.ArrayList; @@ -80,7 +83,8 @@ public class QueryProfileType extends FreezableSimpleComponent { Map<String, FieldDescription> unfrozenFields = new LinkedHashMap<>(); for (Map.Entry<String, FieldDescription> field : fields.entrySet()) { FieldDescription unfrozenFieldValue = field.getValue(); - if (field.getValue().getType() instanceof QueryProfileFieldType queryProfileFieldType) { + if (field.getValue().getType() instanceof QueryProfileFieldType) { + QueryProfileFieldType queryProfileFieldType = (QueryProfileFieldType)field.getValue().getType(); if (queryProfileFieldType.getQueryProfileType() != null) { QueryProfileFieldType unfrozenType = new QueryProfileFieldType(queryProfileFieldType.getQueryProfileType().unfrozen()); @@ -181,8 +185,8 @@ public class QueryProfileType extends FreezableSimpleComponent { fields.put(field.getName(), field); } } - fields = Collections.unmodifiableMap(fields); - inherited = List.copyOf(inherited); + fields = ImmutableMap.copyOf(fields); + inherited = ImmutableList.copyOf(inherited); strict = isStrict(); matchAsPath = getMatchAsPath(); super.freeze(); @@ -378,7 +382,7 @@ public class QueryProfileType extends FreezableSimpleComponent { */ public Map<String, String> aliases() { if (isFrozen()) return aliases; - if (aliases == null) return Map.of(); + if (aliases == null) return Collections.emptyMap(); return Collections.unmodifiableMap(aliases); } diff --git a/container-search/src/main/java/com/yahoo/search/searchchain/model/federation/FederationSearcherModel.java b/container-search/src/main/java/com/yahoo/search/searchchain/model/federation/FederationSearcherModel.java index f39528b3c0f..8acac776ae8 100644 --- a/container-search/src/main/java/com/yahoo/search/searchchain/model/federation/FederationSearcherModel.java +++ b/container-search/src/main/java/com/yahoo/search/searchchain/model/federation/FederationSearcherModel.java @@ -3,6 +3,7 @@ package com.yahoo.search.searchchain.model.federation; import java.util.List; +import com.google.common.collect.ImmutableList; import com.yahoo.container.bundle.BundleInstantiationSpecification; import com.yahoo.component.ComponentSpecification; @@ -30,7 +31,7 @@ public class FederationSearcherModel extends ChainedComponentModel { super(BundleInstantiationSpecification.fromSearchAndDocproc(componentId, federationSearcherComponentSpecification), dependencies); this.inheritDefaultSources = inheritDefaultSources; - this.targets = List.copyOf(targets); + this.targets = ImmutableList.copyOf(targets); } /** Specifies one or more search chains that can be addressed as a single source. */ diff --git a/container-search/src/main/java/com/yahoo/search/searchchain/model/federation/LocalProviderSpec.java b/container-search/src/main/java/com/yahoo/search/searchchain/model/federation/LocalProviderSpec.java index 37175df7c35..c4e5f26a3eb 100644 --- a/container-search/src/main/java/com/yahoo/search/searchchain/model/federation/LocalProviderSpec.java +++ b/container-search/src/main/java/com/yahoo/search/searchchain/model/federation/LocalProviderSpec.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.searchchain.model.federation; +import com.google.common.collect.ImmutableList; import com.yahoo.container.bundle.BundleInstantiationSpecification; import com.yahoo.component.chain.dependencies.Dependencies; import com.yahoo.component.chain.model.ChainedComponentModel; @@ -66,6 +67,6 @@ public class LocalProviderSpec { Dependencies.emptyDependencies())); } - return List.copyOf(searcherModels); + return ImmutableList.copyOf(searcherModels); } } diff --git a/container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java b/container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java index 2c5c1ad83fe..32880f9b1a8 100644 --- a/container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java +++ b/container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java @@ -2,7 +2,13 @@ package com.yahoo.search.yql; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.yahoo.search.yql.yqlplusParser.Annotate_expressionContext; import com.yahoo.search.yql.yqlplusParser.AnnotationContext; import com.yahoo.search.yql.yqlplusParser.ArgumentContext; @@ -60,20 +66,21 @@ import org.antlr.v4.runtime.tree.RuleNode; import org.antlr.v4.runtime.tree.TerminalNode; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; +import java.io.InputStream; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Stream; /** * Translate the ANTLR grammar into the logical representation. */ final class ProgramParser { + public yqlplusParser prepareParser(String programName, InputStream input) throws IOException { + return prepareParser(programName, new CaseInsensitiveCharStream(CharStreams.fromStream(input))); + } + public yqlplusParser prepareParser(String programName, String input) throws IOException { return prepareParser(programName, new CaseInsensitiveCharStream(CharStreams.fromString(input))); } @@ -135,9 +142,13 @@ final class ProgramParser { } private List<String> readName(Namespaced_nameContext node) { - return node.children.stream() - .filter(elt -> !(getParseTreeIndex(elt) == yqlplusParser.DOT)) - .map(ParseTree::getText).toList(); + List<String> path = Lists.newArrayList(); + for (ParseTree elt:node.children) { + if (!(getParseTreeIndex(elt) == yqlplusParser.DOT)) { + path.add(elt.getText()); + } + } + return path; } static class Binding { @@ -153,7 +164,7 @@ final class ProgramParser { } public List<String> toPathWith(List<String> rest) { - return Stream.concat(toPath().stream(), rest.stream()).toList(); + return ImmutableList.copyOf(Iterables.concat(toPath(), rest)); } } @@ -162,9 +173,9 @@ final class ProgramParser { final Scope root; final Scope parent; - Set<String> cursors = Set.of(); - Set<String> variables = Set.of(); - Map<String, Binding> bindings = new HashMap<>(); + Set<String> cursors = ImmutableSet.of(); + Set<String> variables = ImmutableSet.of(); + Map<String, Binding> bindings = Maps.newHashMap(); final yqlplusParser parser; final String programName; @@ -220,7 +231,7 @@ final class ProgramParser { throw new ProgramCompileException(loc, "Alias '%s' is already used.", name); } if (cursors.isEmpty()) { - cursors = new HashSet<>(); + cursors = Sets.newHashSet(); } cursors.add(name); } @@ -230,7 +241,7 @@ final class ProgramParser { throw new ProgramCompileException(loc, "Variable/argument '%s' is already used.", name); } if (variables.isEmpty()) { - variables = new HashSet<>(); + variables = Sets.newHashSet(); } variables.add(name); @@ -300,7 +311,7 @@ final class ProgramParser { // OrderbyContext orderby() List<Orderby_fieldContext> orderFieds = ((OrderbyContext) child) .orderby_fields().orderby_field(); - orderby = new ArrayList<>(orderFieds.size()); + orderby = Lists.newArrayListWithExpectedSize(orderFieds.size()); for (var field: orderFieds) { orderby.add(convertSortKey(field, scope)); } @@ -364,7 +375,7 @@ final class ProgramParser { } private OperatorNode<SequenceOperator> readMultiSource(Scope scope, Source_listContext multiSource) { - List<List<String>> sourceNameList = new ArrayList<>(); + List<List<String>> sourceNameList = Lists.newArrayList(); List<Namespaced_nameContext> nameSpaces = multiSource.namespaced_name(); for(Namespaced_nameContext node : nameSpaces) { List<String> name = readName(node); @@ -378,16 +389,16 @@ final class ProgramParser { for (Pipeline_stepContext step:nodes) { if (getParseTreeIndex(step.getChild(0)) == yqlplusParser.RULE_vespa_grouping) { result = OperatorNode.create(SequenceOperator.PIPE, result, List.of(), - List.of(convertExpr(step.getChild(0), scope))); + ImmutableList.of(convertExpr(step.getChild(0), scope))); } else { List<String> name = readName(step.namespaced_name()); - List<OperatorNode<ExpressionOperator>> args = List.of(); + List<OperatorNode<ExpressionOperator>> args = ImmutableList.of(); // LPAREN (argument[$in_select] (COMMA argument[$in_select])*) RPAREN if (step.getChildCount() > 1) { ArgumentsContext arguments = step.arguments(); if (arguments.getChildCount() > 2) { List<ArgumentContext> argumentContextList = arguments.argument(); - args = new ArrayList<>(argumentContextList.size()); + args = Lists.newArrayListWithExpectedSize(argumentContextList.size()); for (ArgumentContext argumentContext: argumentContextList) { args.add(convertExpr(argumentContext.expression(), scope.getRoot())); @@ -460,11 +471,11 @@ final class ProgramParser { case yqlplusParser.RULE_call_source -> { List<String> names = readName(dataSourceNode.getChild(Namespaced_nameContext.class, 0)); alias = assignAlias(names.get(names.size() - 1), aliasContext, scope); - List<OperatorNode<ExpressionOperator>> arguments = List.of(); + List<OperatorNode<ExpressionOperator>> arguments = ImmutableList.of(); ArgumentsContext argumentsContext = dataSourceNode.getRuleContext(ArgumentsContext.class, 0); if (argumentsContext != null) { List<ArgumentContext> argumentContexts = argumentsContext.argument(); - arguments = new ArrayList<>(argumentContexts.size()); + arguments = Lists.newArrayListWithExpectedSize(argumentContexts.size()); for (ArgumentContext argumentContext : argumentContexts) { arguments.add(convertExpr(argumentContext, scope)); } @@ -503,7 +514,7 @@ final class ProgramParser { yqlplusParser parser, String programName) { Scope scope = new Scope(parser, programName); - List<OperatorNode<StatementOperator>> stmts = new ArrayList<>(); + List<OperatorNode<StatementOperator>> stmts = Lists.newArrayList(); int output = 0; for (ParseTree node : program.children) { if (!(node instanceof ParserRuleContext ruleContext)) continue; @@ -613,8 +624,8 @@ final class ProgramParser { } case yqlplusParser.RULE_map_expression: { List<Property_name_and_valueContext> propertyList = ((Map_expressionContext)parseTree).property_name_and_value(); - List<String> names = new ArrayList<>(propertyList.size()); - List<OperatorNode<ExpressionOperator>> exprs = new ArrayList<>(propertyList.size()); + List<String> names = Lists.newArrayListWithExpectedSize(propertyList.size()); + List<OperatorNode<ExpressionOperator>> exprs = Lists.newArrayListWithCapacity(propertyList.size()); for (Property_name_and_valueContext child : propertyList) { // : propertyName ':' expression[$expression::namespace] -> // ^(PROPERTY propertyName expression) @@ -625,7 +636,7 @@ final class ProgramParser { } case yqlplusParser.RULE_array_literal: { List<Constant_expressionContext> expressionList = ((Array_literalContext) parseTree).constant_expression(); - List<OperatorNode<ExpressionOperator>> values = new ArrayList<>(expressionList.size()); + List<OperatorNode<ExpressionOperator>> values = Lists.newArrayListWithExpectedSize(expressionList.size()); for (Constant_expressionContext expr : expressionList) { values.add(convertExpr(expr, scope)); } @@ -657,7 +668,7 @@ final class ProgramParser { } case yqlplusParser.RULE_call_expression: { List<ArgumentContext> args = ((ArgumentsContext) firstChild.getChild(1)).argument(); - List<OperatorNode<ExpressionOperator>> arguments = new ArrayList<>(args.size()); + List<OperatorNode<ExpressionOperator>> arguments = Lists.newArrayListWithExpectedSize(args.size()); for (ArgumentContext argContext : args) { arguments.add(convertExpr(argContext.expression(),scope)); } @@ -878,7 +889,7 @@ final class ProgramParser { if (elements.size() == 1 && scope.getParser().isArrayParameter(firldElement)) { return convertExpr(firldElement, scope); } else { - List<OperatorNode<ExpressionOperator>> values = new ArrayList<>(elements.size()); + List<OperatorNode<ExpressionOperator>> values = Lists.newArrayListWithExpectedSize(elements.size()); for (Literal_elementContext child : elements) { values.add(convertExpr(child.getChild(0), scope)); } @@ -895,10 +906,10 @@ final class ProgramParser { String text = literal.getChild(0).getText(); switch(parseTreeIndex) { case yqlplusParser.INT: - long as_long = Long.parseLong(text); - int as_int = (int)as_long; + Long as_long = Long.valueOf(text); + int as_int = as_long.intValue(); if (as_int == as_long) { - return as_int; + return Integer.valueOf(as_int); } else { return as_long; } @@ -932,7 +943,11 @@ final class ProgramParser { } case ARRAY: { List<OperatorNode<ExpressionOperator>> exprs = node.getArgument(0); - return exprs.stream().map(expr -> readConstantExpression(expr)).toList(); + ImmutableList.Builder<Object> lst = ImmutableList.builder(); + for (OperatorNode<ExpressionOperator> expr : exprs) { + lst.add(readConstantExpression(expr)); + } + return lst.build(); } case VARREF: { return node; // must be dereferenced in YqlParser when we have userQuery @@ -952,7 +967,7 @@ final class ProgramParser { } private OperatorNode<ExpressionOperator> readConjOp(ExpressionOperator op, List<Equality_expressionContext> nodes, Scope scope) { - List<OperatorNode<ExpressionOperator>> arguments = new ArrayList<>(nodes.size()); + List<OperatorNode<ExpressionOperator>> arguments = Lists.newArrayListWithExpectedSize(nodes.size()); for (ParseTree child : nodes) { arguments.add(convertExpr(child, scope)); } @@ -961,13 +976,13 @@ final class ProgramParser { private OperatorNode<ExpressionOperator> readConjOrOp(ExpressionOperator op, Logical_OR_expressionContext node, Scope scope) { List<Logical_AND_expressionContext> andExpressionList = node.logical_AND_expression(); - List<OperatorNode<ExpressionOperator>> arguments = new ArrayList<>(andExpressionList.size()); + List<OperatorNode<ExpressionOperator>> arguments = Lists.newArrayListWithExpectedSize(andExpressionList.size()); for (Logical_AND_expressionContext child : andExpressionList) { List<Equality_expressionContext> equalities = child.equality_expression(); if (equalities.size() == 1) { arguments.add(convertExpr(equalities.get(0), scope)); } else { - List<OperatorNode<ExpressionOperator>> andArguments = new ArrayList<>(equalities.size()); + List<OperatorNode<ExpressionOperator>> andArguments = Lists.newArrayListWithExpectedSize(equalities.size()); for (Equality_expressionContext subTreeChild:equalities) { andArguments.add(convertExpr(subTreeChild, scope)); } @@ -1000,17 +1015,19 @@ final class ProgramParser { * @return list of READ_FIELD expressions */ private List<OperatorNode<ExpressionOperator>> getReadFieldExpressions(OperatorNode<ExpressionOperator> in) { - List<OperatorNode<ExpressionOperator>> readFieldList = new ArrayList<>(); + List<OperatorNode<ExpressionOperator>> readFieldList = Lists.newArrayList(); switch (in.getOperator()) { - case READ_FIELD -> readFieldList.add(in); - case CALL -> { + case READ_FIELD: + readFieldList.add(in); + break; + case CALL: List<OperatorNode<ExpressionOperator>> callArgs = in.getArgument(1); for (OperatorNode<ExpressionOperator> callArg : callArgs) { if (callArg.getOperator() == ExpressionOperator.READ_FIELD) { readFieldList.add(callArg); } } - } + break; } return readFieldList; } diff --git a/container-search/src/main/java/com/yahoo/search/yql/ProjectionBuilder.java b/container-search/src/main/java/com/yahoo/search/yql/ProjectionBuilder.java index 92f25d57e8a..e7ec28a9b97 100644 --- a/container-search/src/main/java/com/yahoo/search/yql/ProjectionBuilder.java +++ b/container-search/src/main/java/com/yahoo/search/yql/ProjectionBuilder.java @@ -1,11 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.yql; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import com.google.common.collect.Sets; - -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.Set; @@ -34,14 +32,22 @@ class ProjectionBuilder { } private String assignName(OperatorNode<ExpressionOperator> expr) { - String baseName = switch (expr.getOperator()) { - case PROPREF -> (String) expr.getArgument(1); - case READ_RECORD -> (String) expr.getArgument(0); - case READ_FIELD -> (String) expr.getArgument(1); - case VARREF -> (String) expr.getArgument(0); - default -> "expr"; + String baseName = "expr"; + switch (expr.getOperator()) { + case PROPREF: + baseName = (String) expr.getArgument(1); + break; + case READ_RECORD: + baseName = (String) expr.getArgument(0); + break; + case READ_FIELD: + baseName = (String) expr.getArgument(1); + break; + case VARREF: + baseName = (String) expr.getArgument(0); + break; // fall through, leaving baseName alone - }; + } int c = 0; String candidate = baseName; while (fields.containsKey(candidate)) { @@ -51,7 +57,7 @@ class ProjectionBuilder { } public OperatorNode<SequenceOperator> make(OperatorNode<SequenceOperator> target) { - List<OperatorNode<ProjectOperator>> lst = new ArrayList<>(); + ImmutableList.Builder<OperatorNode<ProjectOperator>> lst = ImmutableList.builder(); for (Map.Entry<String, OperatorNode<ExpressionOperator>> e : fields.entrySet()) { if (e.getKey().startsWith("*")) { lst.add(OperatorNode.create(ProjectOperator.MERGE_RECORD, e.getValue().getArgument(0))); @@ -61,7 +67,7 @@ class ProjectionBuilder { lst.add(OperatorNode.create(ProjectOperator.FIELD, e.getValue(), e.getKey())); } } - return OperatorNode.create(SequenceOperator.PROJECT, target, List.copyOf(lst)); + return OperatorNode.create(SequenceOperator.PROJECT, target, lst.build()); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java index 73975ecaa96..e9b1cbabc79 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.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.prelude.fastsearch.test; +import com.google.common.collect.ImmutableList; import com.yahoo.component.chain.Chain; import com.yahoo.container.QrSearchersConfig; import com.yahoo.container.handler.VipStatus; @@ -142,7 +143,7 @@ public class FastSearcherTestCase { @Test void testSinglePassGroupingIsNotForcedWithSingleNodeGroups() { - MockDispatcher dispatcher = MockDispatcher.create(List.of(new Node(0, "host0", 0), new Node(2, "host1", 0))); + MockDispatcher dispatcher = MockDispatcher.create(ImmutableList.of(new Node(0, "host0", 0), new Node(2, "host1", 0))); FastSearcher fastSearcher = new FastSearcher("container.0", dispatcher, @@ -184,7 +185,7 @@ public class FastSearcherTestCase { searchClusterB.name(clusterName); b.searchcluster(searchClusterB); VipStatus vipStatus = new VipStatus(b.build()); - List<Node> nodes_1 = List.of(new Node(0, "host0", 0)); + List<Node> nodes_1 = ImmutableList.of(new Node(0, "host0", 0)); RpcResourcePool rpcPool_1 = new RpcResourcePool(MockDispatcher.toDispatchConfig(), MockDispatcher.toNodesConfig(nodes_1)); MockDispatcher dispatch_1 = MockDispatcher.create(nodes_1, rpcPool_1, vipStatus); dispatch_1.clusterMonitor.shutdown(); diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/LiteralBoostSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/LiteralBoostSearcherTestCase.java index 5f9d0a53f06..16e27303fa8 100644 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/LiteralBoostSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/LiteralBoostSearcherTestCase.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.prelude.querytransform.test; +import com.google.common.collect.ImmutableList; import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; import com.yahoo.prelude.IndexModel; @@ -11,10 +12,7 @@ import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; import org.junit.jupiter.api.Test; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -85,9 +83,9 @@ public class LiteralBoostSearcherTestCase { private IndexFacts createIndexFacts() { Map<String, List<String>> clusters = new LinkedHashMap<>(); - clusters.put("cluster1", List.of("type1", "type2", "type3")); - clusters.put("cluster2", List.of("type4", "type5")); - Collection<SearchDefinition> searchDefs = List.of( + clusters.put("cluster1", Arrays.asList("type1", "type2", "type3")); + clusters.put("cluster2", Arrays.asList("type4", "type5")); + Collection<SearchDefinition> searchDefs = ImmutableList.of( createSearchDefinitionWithFields("type1", true), createSearchDefinitionWithFields("type2", false), new SearchDefinition("type3"), diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NormalizingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NormalizingSearcherTestCase.java index 9eba23e3ab6..239f4500297 100644 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NormalizingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NormalizingSearcherTestCase.java @@ -4,6 +4,7 @@ package com.yahoo.prelude.querytransform.test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import com.google.common.collect.ImmutableList; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.prelude.Index; @@ -22,8 +23,8 @@ import org.junit.jupiter.api.Test; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; @@ -72,7 +73,12 @@ public class NormalizingSearcherTestCase { } private String enc(String s) { - return URLEncoder.encode(s, StandardCharsets.UTF_8); + try { + return URLEncoder.encode(s, "utf-8"); + } + catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } } @Test @@ -123,9 +129,9 @@ public class NormalizingSearcherTestCase { private IndexFacts createIndexFacts() { Map<String, List<String>> clusters = new LinkedHashMap<>(); - clusters.put("cluster1", List.of("type1", "type2", "type3")); - clusters.put("cluster2", List.of("type4", "type5")); - Collection<SearchDefinition> searchDefs = List.of( + clusters.put("cluster1", Arrays.asList("type1", "type2", "type3")); + clusters.put("cluster2", Arrays.asList("type4", "type5")); + Collection<SearchDefinition> searchDefs = ImmutableList.of( createSearchDefinitionWithFields("type1", true), createSearchDefinitionWithFields("type2", false), new SearchDefinition("type3"), diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java index e064f8f2ba0..d374bfdeb7b 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java @@ -3,6 +3,7 @@ package com.yahoo.prelude.searcher.test; import static org.junit.jupiter.api.Assertions.*; +import com.google.common.collect.ImmutableList; import com.yahoo.component.ComponentId; import com.yahoo.component.chain.Chain; import com.yahoo.container.QrSearchersConfig; @@ -83,7 +84,7 @@ public class JuniperSearcherTestCase { private Execution createExecution(Chain<Searcher> chain) { Map<String, List<String>> clusters = new LinkedHashMap<>(); - Collection<SearchDefinition> searchDefs = List.of(createSearchDefinitionOne(), createSearchDefinitionTwo()); + Collection<SearchDefinition> searchDefs = ImmutableList.of(createSearchDefinitionOne(), createSearchDefinitionTwo()); IndexModel indexModel = new IndexModel(clusters, searchDefs); return new Execution(chain, Execution.Context.createContextStub(new IndexFacts(indexModel))); } diff --git a/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java index e6c5a18c9da..4b24ba3671e 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.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.prelude.test; +import com.google.common.collect.ImmutableList; import com.yahoo.config.subscription.ConfigGetter; import com.yahoo.language.process.StemMode; import com.yahoo.prelude.Index; @@ -12,7 +13,11 @@ import com.yahoo.search.config.IndexInfoConfig; import com.yahoo.search.searchchain.Execution; import org.junit.jupiter.api.Test; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -23,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.*; * * @author Steinar Knutsen */ +@SuppressWarnings({"rawtypes", "unchecked"}) public class IndexFactsTestCase { private static final String INDEXFACTS_TESTING = "file:src/test/java/com/yahoo/prelude/test/indexfactstesting.cfg"; @@ -39,8 +45,14 @@ public class IndexFactsTestCase { } private Map<String, List<String>> createClusters() { - return Map.of("clusterOne", List.of("one", "two"), - "clusterTwo", List.of("one", "three")); + List<String> clusterOne = new ArrayList<>(); + List<String> clusterTwo = new ArrayList<>(); + clusterOne.addAll(Arrays.asList("one", "two")); + clusterTwo.addAll(Arrays.asList("one", "three")); + Map<String, List<String>> clusters = new HashMap<>(); + clusters.put("clusterOne", clusterOne); + clusters.put("clusterTwo", clusterTwo); + return clusters; } @Test @@ -74,7 +86,7 @@ public class IndexFactsTestCase { sd2.addIndex(a); assertEquals(sd2.getDefaultPosition(), "a"); - IndexFacts indexFacts = createIndexFacts(List.of(sd, sd2)); + IndexFacts indexFacts = createIndexFacts(ImmutableList.of(sd, sd2)); assertEquals(indexFacts.getDefaultPosition(null), "a"); assertEquals(indexFacts.getDefaultPosition("sd"), "c"); } @@ -130,6 +142,8 @@ public class IndexFactsTestCase { assertExactIsWorking("test"); assertExactIsWorking("artist_name_ft_norm1"); + List search = new ArrayList(); + search.add("three"); Query query = new Query(); query.getModel().getSources().add("three"); IndexFacts.Session threeSession = createIndexFacts().newSession(query); @@ -180,7 +194,7 @@ public class IndexFactsTestCase { query.getModel().getSources().add("one"); query.getModel().getRestrict().add("two"); - IndexFacts.Session indexFacts = createIndexFacts().newSession(List.of("clusterOne"), List.of()); + IndexFacts.Session indexFacts = createIndexFacts().newSession(Collections.singleton("clusterOne"), Collections.emptyList()); assertTrue(indexFacts.isIndex("a")); assertFalse(indexFacts.isIndex("b")); assertTrue(indexFacts.isIndex("d")); @@ -268,7 +282,7 @@ public class IndexFactsTestCase { b.indexinfo(b3); IndexInfoConfig config = new IndexInfoConfig(b); - IndexFacts indexFacts = new IndexFacts(new IndexModel(config, Map.of())); + IndexFacts indexFacts = new IndexFacts(new IndexModel(config, Collections.emptyMap())); Query query1 = new Query("?query=url:https://foo.bar"); Query query2 = new Query("?query=url:https://foo.bar&restrict=hasUri"); assertEquals(0, query1.getModel().getRestrict().size()); @@ -294,7 +308,7 @@ public class IndexFactsTestCase { // Alias to field1 conflics with field1 in the "union" search definition. // Should not produce an exception (but a log message): - new IndexFacts(new IndexModel(Map.of(), List.of(first, second))); + new IndexFacts(new IndexModel(Collections.emptyMap(), ImmutableList.of(first, second))); } } diff --git a/container-search/src/test/java/com/yahoo/search/federation/DuplicateSourceTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/DuplicateSourceTestCase.java index ea29e0a15ff..cb0d4ab923f 100644 --- a/container-search/src/test/java/com/yahoo/search/federation/DuplicateSourceTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/federation/DuplicateSourceTestCase.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.federation; +import com.google.common.collect.ImmutableList; import com.yahoo.component.ComponentId; import com.yahoo.component.chain.Chain; import com.yahoo.prelude.IndexFacts; @@ -13,6 +14,7 @@ import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.SearchChainRegistry; import org.junit.jupiter.api.Test; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -36,10 +38,10 @@ public class DuplicateSourceTestCase { SearchChainRegistry searchChains = new SearchChainRegistry(); searchChains.register(new Chain<>("chain1", mockBackendSearcher)); Map<String, List<String>> clusters = new HashMap<>(); - clusters.put("chain1", List.of("doc1", "doc2")); - IndexFacts indexFacts = new IndexFacts(new IndexModel(clusters, List.of())); + clusters.put("chain1", ImmutableList.of("doc1", "doc2")); + IndexFacts indexFacts = new IndexFacts(new IndexModel(clusters, Collections.emptyList())); SearchChainResolver resolver = new SearchChainResolver.Builder() - .addSearchChain(new ComponentId("chain1"), List.of("doc1", "doc2")) + .addSearchChain(new ComponentId("chain1"), ImmutableList.of("doc1", "doc2")) .build(); FederationSearcher searcher = new FederationSearcher(new ComponentId("test"), resolver); diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/test/NGramSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/querytransform/test/NGramSearcherTestCase.java index 49449153d1f..8dccf7d0f38 100644 --- a/container-search/src/test/java/com/yahoo/search/querytransform/test/NGramSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/querytransform/test/NGramSearcherTestCase.java @@ -1,10 +1,13 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.querytransform.test; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import com.google.common.collect.ImmutableList; import com.yahoo.component.chain.Chain; import com.yahoo.language.Language; import com.yahoo.language.simple.SimpleLinguistics; @@ -89,11 +92,11 @@ public class NGramSearcherTestCase { song.addIndex(songDefault); Map<String, List<String>> clusters = new HashMap<>(); - clusters.put("musicOnly", List.of(music.getName())); - clusters.put("songOnly", List.of(song.getName())); - clusters.put("musicAndSong", List.of(music.getName(), song.getName())); + clusters.put("musicOnly", Collections.singletonList(music.getName())); + clusters.put("songOnly", Collections.singletonList(song.getName())); + clusters.put("musicAndSong", Arrays.asList(music.getName(), song.getName())); - IndexFacts indexFacts = new IndexFacts(new IndexModel(clusters, List.of(music, song))); + IndexFacts indexFacts = new IndexFacts(new IndexModel(clusters, ImmutableList.of(music, song))); return new Execution(createSearcher(), Execution.Context.createContextStub(indexFacts)); } |