aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/IndexFacts.java31
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java8
-rw-r--r--container-search/src/main/java/com/yahoo/search/Query.java3
-rw-r--r--container-search/src/main/java/com/yahoo/search/federation/FederationResult.java11
-rw-r--r--container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java24
-rw-r--r--container-search/src/main/java/com/yahoo/search/federation/sourceref/SearchChainInvocationSpec.java8
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java9
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariant.java16
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariants.java17
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java8
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java12
-rw-r--r--container-search/src/main/java/com/yahoo/search/searchchain/model/federation/FederationSearcherModel.java3
-rw-r--r--container-search/src/main/java/com/yahoo/search/searchchain/model/federation/LocalProviderSpec.java3
-rw-r--r--container-search/src/main/java/com/yahoo/search/yql/ProgramParser.java91
-rw-r--r--container-search/src/main/java/com/yahoo/search/yql/ProjectionBuilder.java30
15 files changed, 109 insertions, 165 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 c9a855c2f34..90194f3ba6a 100644
--- a/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java
+++ b/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java
@@ -1,10 +1,16 @@
// 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.*;
+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 static com.yahoo.text.Lowercase.toLowerCase;
@@ -57,7 +63,6 @@ public class IndexFacts {
public IndexFacts() {}
- @SuppressWarnings({"deprecation"})
public IndexFacts(IndexModel indexModel) {
if (indexModel.getSearchDefinitions() != null) {
this.searchDefinitions = indexModel.getSearchDefinitions();
@@ -85,20 +90,16 @@ public class IndexFacts {
}
private static void addEntry(Map<String, List<String>> result, String key, String value) {
- List<String> values = result.get(key);
- if (values == null) {
- values = new ArrayList<>();
- result.put(key, values);
- }
+ List<String> values = result.computeIfAbsent(key, k -> new ArrayList<>());
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 Collections.emptyList();
+ if (clusterByDocument == null) return List.of();
List<String> clusters = clusterByDocument.get(searchDefinitionName);
- return clusters != null ? clusters : Collections.<String>emptyList();
+ return clusters != null ? clusters : List.of();
}
private boolean isInitialized() {
@@ -168,9 +169,9 @@ public class IndexFacts {
}
private Collection<Index> getIndexes(String documentType) {
- if ( ! isInitialized()) return Collections.emptyList();
+ if ( ! isInitialized()) return List.of();
SearchDefinition sd = searchDefinitions.get(documentType);
- if (sd == null) return Collections.emptyList();
+ if (sd == null) return List.of();
return sd.indices().values();
}
@@ -231,7 +232,7 @@ public class IndexFacts {
}
private Collection<String> emptyCollectionIfNull(Collection<String> collection) {
- return collection == null ? Collections.<String>emptyList() : collection;
+ return collection == null ? List.of() : collection;
}
/**
@@ -318,7 +319,7 @@ public class IndexFacts {
private final List<String> documentTypes;
private Session(Query query) {
- documentTypes = ImmutableList.copyOf(resolveDocumentTypes(query));
+ documentTypes = List.copyOf(resolveDocumentTypes(query));
}
private Session(Collection<String> sources, Collection<String> restrict) {
@@ -347,7 +348,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, Collections.singletonList(documentType));
+ return IndexFacts.this.getIndexFromDocumentTypes(indexName, List.of(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 59dad29ab5c..ea78b2365c5 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,7 +9,6 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
-import com.google.common.collect.ImmutableList;
import com.yahoo.compress.IntegerCompressor;
/**
@@ -30,7 +29,7 @@ public class WordAlternativesItem extends TermItem {
this.alternatives = uniqueAlternatives(terms);
}
- private static ImmutableList<Alternative> uniqueAlternatives(Collection<Alternative> terms) {
+ private static List<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));
@@ -43,7 +42,7 @@ public class WordAlternativesItem extends TermItem {
uniqueTerms.add(~i, term);
}
}
- return ImmutableList.copyOf(uniqueTerms);
+ return List.copyOf(uniqueTerms);
}
@Override
@@ -177,8 +176,7 @@ public class WordAlternativesItem extends TermItem {
@Override
public boolean equals(Object o) {
- if ( ! (o instanceof Alternative)) return false;
- var other = (Alternative)o;
+ if ( ! (o instanceof Alternative other)) return false;
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 be964081326..cff43e07d70 100644
--- a/container-search/src/main/java/com/yahoo/search/Query.java
+++ b/container-search/src/main/java/com/yahoo/search/Query.java
@@ -2,7 +2,6 @@
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;
@@ -262,7 +261,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 =
- ImmutableList.copyOf(namesUnder(CompoundName.empty, Query.getArgumentType()));
+ List.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 f6cbb49f7d5..89c45fde6ae 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,7 +1,6 @@
// 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;
@@ -27,9 +26,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 List<TargetResult> targetsToWaitFor;
+ private final List<TargetResult> targetsToWaitFor;
- private FederationResult(ImmutableList<TargetResult> targetResults) {
+ private FederationResult(List<TargetResult> targetResults) {
this.targetResults = targetResults;
if (targetResults.stream().anyMatch(TargetResult::isMandatory))
@@ -94,7 +93,7 @@ class FederationResult {
public Optional<Result> getIfAvailable(long timeout) {
if (availableResult.isPresent()) return availableResult;
availableResult = futureResult.getIfAvailable(timeout, TimeUnit.MILLISECONDS);
- availableResult.ifPresent(result -> target.modifyTargetResult(result));
+ availableResult.ifPresent(target::modifyTargetResult);
return availableResult;
}
@@ -121,14 +120,14 @@ class FederationResult {
public static class Builder {
- private final ImmutableList.Builder<TargetResult> results = new ImmutableList.Builder();
+ private final List<TargetResult> results = new ArrayList<>();
public void add(FederationSearcher.Target target, FutureResult futureResult) {
results.add(new TargetResult(target, futureResult));
}
public FederationResult build() {
- return new FederationResult(results.build());
+ return new FederationResult(List.copyOf(results));
}
}
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 21b4d1d538f..80a41ffdf22 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,7 +1,6 @@
// 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;
@@ -10,7 +9,6 @@ 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;
@@ -28,7 +26,6 @@ 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;
@@ -77,11 +74,9 @@ 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();
@@ -338,22 +333,6 @@ 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();
@@ -662,9 +641,8 @@ public class FederationSearcher extends ForkingSearcher {
@Override
public boolean equals(Object o) {
if (o == this) return true;
- if ( ! ( o instanceof StandardTarget)) return false;
+ if ( ! (o instanceof StandardTarget other)) 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 34eeb3ce82c..f432289d2c1 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,7 +1,6 @@
// 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;
@@ -24,7 +23,7 @@ public class SearchChainInvocationSpec implements Cloneable {
public final ComponentId provider;
public final FederationOptions federationOptions;
- public final ImmutableList<String> documentTypes;
+ public final List<String> documentTypes;
SearchChainInvocationSpec(ComponentId searchChainId,
ComponentId source, ComponentId provider, FederationOptions federationOptions,
@@ -33,7 +32,7 @@ public class SearchChainInvocationSpec implements Cloneable {
this.source = source;
this.provider = provider;
this.federationOptions = federationOptions;
- this.documentTypes = ImmutableList.copyOf(documentTypes);
+ this.documentTypes = List.copyOf(documentTypes);
}
@Override
@@ -44,9 +43,8 @@ public class SearchChainInvocationSpec implements Cloneable {
@Override
public boolean equals(Object o) {
if (o == this) return true;
- if ( ! ( o instanceof SearchChainInvocationSpec)) return false;
+ if ( ! (o instanceof SearchChainInvocationSpec other)) 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 e3ab49f0e32..b58bd64209b 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,7 +1,6 @@
// 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;
@@ -420,7 +419,7 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable
content.freeze();
- inherited= inherited==null ? ImmutableList.of() : ImmutableList.copyOf(inherited);
+ inherited= inherited==null ? List.of() : List.copyOf(inherited);
super.freeze();
}
@@ -616,8 +615,7 @@ 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) {
- QueryProfile newProfile = (QueryProfile)newValue;
+ if (newValue instanceof QueryProfile newProfile) {
if ( ! (existingValue instanceof QueryProfile)) {
if ( ! isModifiable(newProfile)) {
// Make the query profile reference overridable
@@ -631,8 +629,7 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable
return combineProfiles(newProfile, (QueryProfile)existingValue);
}
else {
- if (existingValue instanceof QueryProfile) { // we need to set a non-leaf value on a query profile
- QueryProfile existingProfile = (QueryProfile)existingValue;
+ if (existingValue instanceof QueryProfile existingProfile) { // we need to set a non-leaf value on a query profile
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 7fc8bfd40ab..57aa3516dfc 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,11 +1,13 @@
// 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.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/**
* A variant of a query profile
@@ -40,7 +42,7 @@ public class QueryProfileVariant implements Cloneable, Comparable<QueryProfileVa
public Map<String, Object> values() {
if (values == null) {
if (frozen)
- return Collections.emptyMap();
+ return Map.of();
else
values = new HashMap<>();
}
@@ -54,7 +56,7 @@ public class QueryProfileVariant implements Cloneable, Comparable<QueryProfileVa
public List<QueryProfile> inherited() {
if (inherited == null) {
if (frozen)
- return Collections.emptyList();
+ return List.of();
else
inherited = new ArrayList<>();
}
@@ -140,9 +142,9 @@ public class QueryProfileVariant implements Cloneable, Comparable<QueryProfileVa
public void freeze() {
if (frozen) return;
if (inherited != null)
- inherited = ImmutableList.copyOf(inherited);
+ inherited = List.copyOf(inherited);
if (values != null)
- values = ImmutableMap.copyOf(values);
+ values = Map.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 845c2cfd384..1b0472c5b17 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,12 +1,15 @@
// 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.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
* This class represent a set of query profiles virtually - rather
@@ -54,7 +57,7 @@ public class QueryProfileVariants implements Freezable, Cloneable {
* on lookup time to influence the value returned.
*/
public QueryProfileVariants(String[] dimensions, QueryProfile owner) {
- this(Arrays.asList(dimensions), owner);
+ this(List.of(dimensions), owner);
}
/**
@@ -77,13 +80,13 @@ public class QueryProfileVariants implements Freezable, Cloneable {
if (frozen) return;
for (FieldValues fieldValues : fieldValuesByName.values())
fieldValues.freeze();
- fieldValuesByName = ImmutableMap.copyOf(fieldValuesByName);
+ fieldValuesByName = Map.copyOf(fieldValuesByName);
inheritedProfiles.freeze();
Collections.sort(variants);
for (QueryProfileVariant variant : variants)
variant.freeze();
- variants = ImmutableList.copyOf(variants);
+ variants = List.copyOf(variants);
frozen=true;
}
@@ -331,7 +334,7 @@ public class QueryProfileVariants implements Freezable, Cloneable {
if (frozen) return;
sort();
if (resolutionList != null)
- resolutionList = ImmutableList.copyOf(resolutionList);
+ resolutionList = List.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 f30a3cc5ae6..8fdbf8b2281 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,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.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;
/**
@@ -96,14 +94,14 @@ public class FieldDescription implements Comparable<FieldDescription> {
if (name.isCompound() && ! aliases.isEmpty())
throw new IllegalArgumentException("Aliases are not allowed with compound names");
- this.aliases = ImmutableList.copyOf(aliases);
+ this.aliases = List.copyOf(aliases);
this.mandatory = mandatory;
this.overridable = overridable;
}
private static List<String> toList(String string) {
- if (string == null || string.isEmpty()) return ImmutableList.of();
- return ImmutableList.copyOf(Arrays.asList(string.split(" ")));
+ if (string == null || string.isEmpty()) return List.of();
+ return List.of(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 02a4199d32e..3da2ad53f9a 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,12 +1,9 @@
// 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;
@@ -83,8 +80,7 @@ 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 queryProfileFieldType = (QueryProfileFieldType)field.getValue().getType();
+ if (field.getValue().getType() instanceof QueryProfileFieldType queryProfileFieldType) {
if (queryProfileFieldType.getQueryProfileType() != null) {
QueryProfileFieldType unfrozenType =
new QueryProfileFieldType(queryProfileFieldType.getQueryProfileType().unfrozen());
@@ -185,8 +181,8 @@ public class QueryProfileType extends FreezableSimpleComponent {
fields.put(field.getName(), field);
}
}
- fields = ImmutableMap.copyOf(fields);
- inherited = ImmutableList.copyOf(inherited);
+ fields = Collections.unmodifiableMap(fields);
+ inherited = List.copyOf(inherited);
strict = isStrict();
matchAsPath = getMatchAsPath();
super.freeze();
@@ -382,7 +378,7 @@ public class QueryProfileType extends FreezableSimpleComponent {
*/
public Map<String, String> aliases() {
if (isFrozen()) return aliases;
- if (aliases == null) return Collections.emptyMap();
+ if (aliases == null) return Map.of();
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 8acac776ae8..f39528b3c0f 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,7 +3,6 @@ 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;
@@ -31,7 +30,7 @@ public class FederationSearcherModel extends ChainedComponentModel {
super(BundleInstantiationSpecification.fromSearchAndDocproc(componentId, federationSearcherComponentSpecification),
dependencies);
this.inheritDefaultSources = inheritDefaultSources;
- this.targets = ImmutableList.copyOf(targets);
+ this.targets = List.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 c4e5f26a3eb..37175df7c35 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,7 +1,6 @@
// 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;
@@ -67,6 +66,6 @@ public class LocalProviderSpec {
Dependencies.emptyDependencies()));
}
- return ImmutableList.copyOf(searcherModels);
+ return List.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 32880f9b1a8..2c5c1ad83fe 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,13 +2,7 @@
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;
@@ -66,21 +60,20 @@ import org.antlr.v4.runtime.tree.RuleNode;
import org.antlr.v4.runtime.tree.TerminalNode;
import java.io.IOException;
-import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
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)));
}
@@ -142,13 +135,9 @@ final class ProgramParser {
}
private List<String> readName(Namespaced_nameContext node) {
- List<String> path = Lists.newArrayList();
- for (ParseTree elt:node.children) {
- if (!(getParseTreeIndex(elt) == yqlplusParser.DOT)) {
- path.add(elt.getText());
- }
- }
- return path;
+ return node.children.stream()
+ .filter(elt -> !(getParseTreeIndex(elt) == yqlplusParser.DOT))
+ .map(ParseTree::getText).toList();
}
static class Binding {
@@ -164,7 +153,7 @@ final class ProgramParser {
}
public List<String> toPathWith(List<String> rest) {
- return ImmutableList.copyOf(Iterables.concat(toPath(), rest));
+ return Stream.concat(toPath().stream(), rest.stream()).toList();
}
}
@@ -173,9 +162,9 @@ final class ProgramParser {
final Scope root;
final Scope parent;
- Set<String> cursors = ImmutableSet.of();
- Set<String> variables = ImmutableSet.of();
- Map<String, Binding> bindings = Maps.newHashMap();
+ Set<String> cursors = Set.of();
+ Set<String> variables = Set.of();
+ Map<String, Binding> bindings = new HashMap<>();
final yqlplusParser parser;
final String programName;
@@ -231,7 +220,7 @@ final class ProgramParser {
throw new ProgramCompileException(loc, "Alias '%s' is already used.", name);
}
if (cursors.isEmpty()) {
- cursors = Sets.newHashSet();
+ cursors = new HashSet<>();
}
cursors.add(name);
}
@@ -241,7 +230,7 @@ final class ProgramParser {
throw new ProgramCompileException(loc, "Variable/argument '%s' is already used.", name);
}
if (variables.isEmpty()) {
- variables = Sets.newHashSet();
+ variables = new HashSet<>();
}
variables.add(name);
@@ -311,7 +300,7 @@ final class ProgramParser {
// OrderbyContext orderby()
List<Orderby_fieldContext> orderFieds = ((OrderbyContext) child)
.orderby_fields().orderby_field();
- orderby = Lists.newArrayListWithExpectedSize(orderFieds.size());
+ orderby = new ArrayList<>(orderFieds.size());
for (var field: orderFieds) {
orderby.add(convertSortKey(field, scope));
}
@@ -375,7 +364,7 @@ final class ProgramParser {
}
private OperatorNode<SequenceOperator> readMultiSource(Scope scope, Source_listContext multiSource) {
- List<List<String>> sourceNameList = Lists.newArrayList();
+ List<List<String>> sourceNameList = new ArrayList<>();
List<Namespaced_nameContext> nameSpaces = multiSource.namespaced_name();
for(Namespaced_nameContext node : nameSpaces) {
List<String> name = readName(node);
@@ -389,16 +378,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(),
- ImmutableList.of(convertExpr(step.getChild(0), scope)));
+ List.of(convertExpr(step.getChild(0), scope)));
} else {
List<String> name = readName(step.namespaced_name());
- List<OperatorNode<ExpressionOperator>> args = ImmutableList.of();
+ List<OperatorNode<ExpressionOperator>> args = List.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 = Lists.newArrayListWithExpectedSize(argumentContextList.size());
+ args = new ArrayList<>(argumentContextList.size());
for (ArgumentContext argumentContext: argumentContextList) {
args.add(convertExpr(argumentContext.expression(), scope.getRoot()));
@@ -471,11 +460,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 = ImmutableList.of();
+ List<OperatorNode<ExpressionOperator>> arguments = List.of();
ArgumentsContext argumentsContext = dataSourceNode.getRuleContext(ArgumentsContext.class, 0);
if (argumentsContext != null) {
List<ArgumentContext> argumentContexts = argumentsContext.argument();
- arguments = Lists.newArrayListWithExpectedSize(argumentContexts.size());
+ arguments = new ArrayList<>(argumentContexts.size());
for (ArgumentContext argumentContext : argumentContexts) {
arguments.add(convertExpr(argumentContext, scope));
}
@@ -514,7 +503,7 @@ final class ProgramParser {
yqlplusParser parser,
String programName) {
Scope scope = new Scope(parser, programName);
- List<OperatorNode<StatementOperator>> stmts = Lists.newArrayList();
+ List<OperatorNode<StatementOperator>> stmts = new ArrayList<>();
int output = 0;
for (ParseTree node : program.children) {
if (!(node instanceof ParserRuleContext ruleContext)) continue;
@@ -624,8 +613,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 = Lists.newArrayListWithExpectedSize(propertyList.size());
- List<OperatorNode<ExpressionOperator>> exprs = Lists.newArrayListWithCapacity(propertyList.size());
+ List<String> names = new ArrayList<>(propertyList.size());
+ List<OperatorNode<ExpressionOperator>> exprs = new ArrayList<>(propertyList.size());
for (Property_name_and_valueContext child : propertyList) {
// : propertyName ':' expression[$expression::namespace] ->
// ^(PROPERTY propertyName expression)
@@ -636,7 +625,7 @@ final class ProgramParser {
}
case yqlplusParser.RULE_array_literal: {
List<Constant_expressionContext> expressionList = ((Array_literalContext) parseTree).constant_expression();
- List<OperatorNode<ExpressionOperator>> values = Lists.newArrayListWithExpectedSize(expressionList.size());
+ List<OperatorNode<ExpressionOperator>> values = new ArrayList<>(expressionList.size());
for (Constant_expressionContext expr : expressionList) {
values.add(convertExpr(expr, scope));
}
@@ -668,7 +657,7 @@ final class ProgramParser {
}
case yqlplusParser.RULE_call_expression: {
List<ArgumentContext> args = ((ArgumentsContext) firstChild.getChild(1)).argument();
- List<OperatorNode<ExpressionOperator>> arguments = Lists.newArrayListWithExpectedSize(args.size());
+ List<OperatorNode<ExpressionOperator>> arguments = new ArrayList<>(args.size());
for (ArgumentContext argContext : args) {
arguments.add(convertExpr(argContext.expression(),scope));
}
@@ -889,7 +878,7 @@ final class ProgramParser {
if (elements.size() == 1 && scope.getParser().isArrayParameter(firldElement)) {
return convertExpr(firldElement, scope);
} else {
- List<OperatorNode<ExpressionOperator>> values = Lists.newArrayListWithExpectedSize(elements.size());
+ List<OperatorNode<ExpressionOperator>> values = new ArrayList<>(elements.size());
for (Literal_elementContext child : elements) {
values.add(convertExpr(child.getChild(0), scope));
}
@@ -906,10 +895,10 @@ final class ProgramParser {
String text = literal.getChild(0).getText();
switch(parseTreeIndex) {
case yqlplusParser.INT:
- Long as_long = Long.valueOf(text);
- int as_int = as_long.intValue();
+ long as_long = Long.parseLong(text);
+ int as_int = (int)as_long;
if (as_int == as_long) {
- return Integer.valueOf(as_int);
+ return as_int;
} else {
return as_long;
}
@@ -943,11 +932,7 @@ final class ProgramParser {
}
case ARRAY: {
List<OperatorNode<ExpressionOperator>> exprs = node.getArgument(0);
- ImmutableList.Builder<Object> lst = ImmutableList.builder();
- for (OperatorNode<ExpressionOperator> expr : exprs) {
- lst.add(readConstantExpression(expr));
- }
- return lst.build();
+ return exprs.stream().map(expr -> readConstantExpression(expr)).toList();
}
case VARREF: {
return node; // must be dereferenced in YqlParser when we have userQuery
@@ -967,7 +952,7 @@ final class ProgramParser {
}
private OperatorNode<ExpressionOperator> readConjOp(ExpressionOperator op, List<Equality_expressionContext> nodes, Scope scope) {
- List<OperatorNode<ExpressionOperator>> arguments = Lists.newArrayListWithExpectedSize(nodes.size());
+ List<OperatorNode<ExpressionOperator>> arguments = new ArrayList<>(nodes.size());
for (ParseTree child : nodes) {
arguments.add(convertExpr(child, scope));
}
@@ -976,13 +961,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 = Lists.newArrayListWithExpectedSize(andExpressionList.size());
+ List<OperatorNode<ExpressionOperator>> arguments = new ArrayList<>(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 = Lists.newArrayListWithExpectedSize(equalities.size());
+ List<OperatorNode<ExpressionOperator>> andArguments = new ArrayList<>(equalities.size());
for (Equality_expressionContext subTreeChild:equalities) {
andArguments.add(convertExpr(subTreeChild, scope));
}
@@ -1015,19 +1000,17 @@ final class ProgramParser {
* @return list of READ_FIELD expressions
*/
private List<OperatorNode<ExpressionOperator>> getReadFieldExpressions(OperatorNode<ExpressionOperator> in) {
- List<OperatorNode<ExpressionOperator>> readFieldList = Lists.newArrayList();
+ List<OperatorNode<ExpressionOperator>> readFieldList = new ArrayList<>();
switch (in.getOperator()) {
- case READ_FIELD:
- readFieldList.add(in);
- break;
- case CALL:
+ case READ_FIELD -> readFieldList.add(in);
+ 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 e7ec28a9b97..92f25d57e8a 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,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.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;
@@ -32,22 +34,14 @@ class ProjectionBuilder {
}
private String assignName(OperatorNode<ExpressionOperator> 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;
+ 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";
// fall through, leaving baseName alone
- }
+ };
int c = 0;
String candidate = baseName;
while (fields.containsKey(candidate)) {
@@ -57,7 +51,7 @@ class ProjectionBuilder {
}
public OperatorNode<SequenceOperator> make(OperatorNode<SequenceOperator> target) {
- ImmutableList.Builder<OperatorNode<ProjectOperator>> lst = ImmutableList.builder();
+ List<OperatorNode<ProjectOperator>> lst = new ArrayList<>();
for (Map.Entry<String, OperatorNode<ExpressionOperator>> e : fields.entrySet()) {
if (e.getKey().startsWith("*")) {
lst.add(OperatorNode.create(ProjectOperator.MERGE_RECORD, e.getValue().getArgument(0)));
@@ -67,7 +61,7 @@ class ProjectionBuilder {
lst.add(OperatorNode.create(ProjectOperator.FIELD, e.getValue(), e.getKey()));
}
}
- return OperatorNode.create(SequenceOperator.PROJECT, target, lst.build());
+ return OperatorNode.create(SequenceOperator.PROJECT, target, List.copyOf(lst));
}
}