diff options
53 files changed, 422 insertions, 268 deletions
diff --git a/athenz-identity-provider-service/src/main/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidator.java b/athenz-identity-provider-service/src/main/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidator.java index 6b7a4835aee..fc21f8271c4 100644 --- a/athenz-identity-provider-service/src/main/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidator.java +++ b/athenz-identity-provider-service/src/main/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidator.java @@ -19,11 +19,11 @@ import com.yahoo.vespa.hosted.provision.NodeRepository; import java.net.InetAddress; import java.security.PublicKey; import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -119,7 +119,10 @@ public class InstanceValidator { // Find a list of SAN DNS List<String> sanDNS = Optional.ofNullable(instanceConfirmation.attributes.get(SAN_DNS_ATTRNAME)) .map(s -> s.split(",")) - .map(Arrays::asList).stream().flatMap(Collection::stream).toList(); + .map(Arrays::asList) + .map(List::stream) + .orElse(Stream.empty()) + .collect(Collectors.toList()); return sanDNS.stream() .filter(dns -> dns.contains(INSTANCE_ID_DELIMITER)) @@ -149,13 +152,15 @@ public class InstanceValidator { // Find list of ipaddresses List<InetAddress> ips = Optional.ofNullable(confirmation.attributes.get(SAN_IPS_ATTRNAME)) .map(s -> s.split(",")) - .map(Arrays::asList).stream().flatMap(Collection::stream) + .map(Arrays::asList) + .map(List::stream) + .orElse(Stream.empty()) .map(InetAddresses::forString) - .toList(); + .collect(Collectors.toList()); List<InetAddress> nodeIpAddresses = node.ipConfig().primary().stream() .map(InetAddresses::forString) - .toList(); + .collect(Collectors.toList()); // Validate that ipaddresses in request are valid for node @@ -182,7 +187,7 @@ public class InstanceValidator { Optional<ApplicationInfo> applicationInfo = superModelProvider.getSuperModel().getApplicationInfo(applicationId); - if (applicationInfo.isEmpty()) { + if (!applicationInfo.isPresent()) { log.info(String.format("Could not find application info for %s, existing applications: %s", applicationId.serializedForm(), superModelProvider.getSuperModel().getAllApplicationInfos())); @@ -202,7 +207,7 @@ public class InstanceValidator { .filter(serviceInfo -> serviceInfo.getProperty(SERVICE_PROPERTIES_SERVICE_KEY).isPresent()) .findFirst(); - if (matchingServiceInfo.isEmpty()) { + if (!matchingServiceInfo.isPresent()) { log.info(String.format("Application %s has not specified domain/service", applicationId.serializedForm())); return false; } diff --git a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidatorTest.java b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidatorTest.java index c3e4ba44fc8..9a91d7372da 100644 --- a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidatorTest.java +++ b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/InstanceValidatorTest.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.vespa.hosted.athenz.instanceproviderservice; +import com.google.common.collect.ImmutableList; import com.yahoo.component.Version; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.model.api.HostInfo; @@ -144,7 +145,7 @@ public class InstanceValidatorTest { nodeList = allocateNode(nodeList, node, applicationId); when(nodes.list()).thenReturn(NodeList.copyOf(nodeList)); String nodeIp = node.ipConfig().primary().stream().findAny().orElseThrow(() -> new RuntimeException("No ipaddress for mocked node")); - InstanceConfirmation instanceConfirmation = createRefreshInstanceConfirmation(applicationId, domain, service, List.of(nodeIp)); + InstanceConfirmation instanceConfirmation = createRefreshInstanceConfirmation(applicationId, domain, service, ImmutableList.of(nodeIp)); assertTrue(instanceValidator.isValidRefresh(instanceConfirmation)); } @@ -178,7 +179,7 @@ public class InstanceValidatorTest { List<Node> nodeList = createNodes(10); when(nodes.list()).thenReturn(NodeList.copyOf(nodeList)); - InstanceConfirmation instanceConfirmation = createRefreshInstanceConfirmation(applicationId, domain, service, List.of("::11")); + InstanceConfirmation instanceConfirmation = createRefreshInstanceConfirmation(applicationId, domain, service, ImmutableList.of("::11")); assertFalse(instanceValidator.isValidRefresh(instanceConfirmation)); diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.java index e2de90a6463..2ad77e2433b 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.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.container.plugin.classanalysis; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Sets; import com.yahoo.container.plugin.util.Maps; @@ -20,6 +21,7 @@ public class PackageTally { private final Map<String, Optional<ExportPackageAnnotation>> definedPackagesMap; private final Set<String> referencedPackagesUnfiltered; + @VisibleForTesting PackageTally(Map<String, Optional<ExportPackageAnnotation>> definedPackagesMap, Set<String> referencedPackagesUnfiltered) { this.definedPackagesMap = definedPackagesMap; this.referencedPackagesUnfiltered = referencedPackagesUnfiltered; diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.java index 9a7aade7ffb..8f78363dab5 100644 --- a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.java +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.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.container.plugin.classanalysis; +import com.google.common.collect.ImmutableList; import com.yahoo.container.plugin.classanalysis.sampleclasses.Base; import com.yahoo.container.plugin.classanalysis.sampleclasses.ClassAnnotation; import com.yahoo.container.plugin.classanalysis.sampleclasses.InvisibleAnnotation; @@ -24,7 +25,6 @@ import java.awt.image.ImagingOpException; import java.awt.image.Kernel; import java.util.List; import java.util.Optional; -import java.util.Set; import static com.yahoo.container.plugin.classanalysis.TestUtilities.analyzeClass; import static com.yahoo.container.plugin.classanalysis.TestUtilities.classFile; @@ -176,7 +176,7 @@ public class AnalyzeClassTest { @Test void switch_statements_are_analyzed() { var referencedClasses = analyzeClass(SwitchStatement.class).getReferencedClasses(); - assertTrue(referencedClasses.contains(name(List.class))); + assertTrue(referencedClasses.contains(name(ImmutableList.class))); assertTrue(referencedClasses.contains(name(IllegalArgumentException.class))); } @@ -184,9 +184,9 @@ public class AnalyzeClassTest { void records_are_analyzed() { var referencedClasses = analyzeClass(RecordWithOverride.class).getReferencedClasses(); assertTrue(referencedClasses.containsAll(List.of( - name(List.class), + name(java.util.List.class), name(Byte.class), - name(String.class), + name(ImmutableList.class), name(IllegalArgumentException.class) ))); diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/RecordWithOverride.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/RecordWithOverride.java index 67c6430ce06..299a9930215 100644 --- a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/RecordWithOverride.java +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/RecordWithOverride.java @@ -1,6 +1,7 @@ package com.yahoo.container.plugin.classanalysis.sampleclasses; -import java.util.ArrayList; +import com.google.common.collect.ImmutableList; + import java.util.List; /** @@ -12,7 +13,7 @@ import java.util.List; public record RecordWithOverride(List<Byte> list) { public RecordWithOverride { - if (list instanceof ArrayList<Byte> l) { + if (list instanceof ImmutableList<Byte> l) { throw new IllegalArgumentException(l.toString()); } } diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/SwitchStatement.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/SwitchStatement.java index f665d31150e..5dbe90e2b58 100644 --- a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/SwitchStatement.java +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/SwitchStatement.java @@ -1,8 +1,9 @@ package com.yahoo.container.plugin.classanalysis.sampleclasses; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; + import java.util.Collection; -import java.util.List; -import java.util.Set; /** * Input for class analysis test verifying Java 14 switch statement. @@ -14,8 +15,8 @@ public class SwitchStatement { void switchStatement() throws Exception{ String foo = ""; Collection<?> c = switch (foo) { - case "list" -> List.of(); - case "set" -> Set.of(); + case "list" -> ImmutableList.of(); + case "set" -> ImmutableSet.of(); default -> throw new IllegalArgumentException(); }; } diff --git a/config-model/src/main/java/com/yahoo/config/model/admin/AdminModel.java b/config-model/src/main/java/com/yahoo/config/model/admin/AdminModel.java index 7fe7c4b9f68..4ae9834b87f 100644 --- a/config-model/src/main/java/com/yahoo/config/model/admin/AdminModel.java +++ b/config-model/src/main/java/com/yahoo/config/model/admin/AdminModel.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.config.model.admin; +import com.google.common.collect.ImmutableList; import com.yahoo.config.model.ApplicationConfigProducerRoot; import com.yahoo.config.model.ConfigModel; import com.yahoo.config.model.ConfigModelContext; @@ -64,8 +65,8 @@ public class AdminModel extends ConfigModel { public static class BuilderV2 extends ConfigModelBuilder<AdminModel> { public static final List<ConfigModelId> configModelIds = - List.of(ConfigModelId.fromNameAndVersion("admin", "2.0"), - ConfigModelId.fromNameAndVersion("admin", "1.0")); + ImmutableList.of(ConfigModelId.fromNameAndVersion("admin", "2.0"), + ConfigModelId.fromNameAndVersion("admin", "1.0")); public BuilderV2() { super(AdminModel.class); @@ -97,8 +98,8 @@ public class AdminModel extends ConfigModel { public static class BuilderV4 extends ConfigModelBuilder<AdminModel> { public static final List<ConfigModelId> configModelIds = - List.of(ConfigModelId.fromNameAndVersion("admin", "3.0"), - ConfigModelId.fromNameAndVersion("admin", "4.0")); + ImmutableList.of(ConfigModelId.fromNameAndVersion("admin", "3.0"), + ConfigModelId.fromNameAndVersion("admin", "4.0")); public BuilderV4() { super(AdminModel.class); diff --git a/config-model/src/main/java/com/yahoo/config/model/provision/Host.java b/config-model/src/main/java/com/yahoo/config/model/provision/Host.java index e4bbf55b541..ea7a0bc0504 100644 --- a/config-model/src/main/java/com/yahoo/config/model/provision/Host.java +++ b/config-model/src/main/java/com/yahoo/config/model/provision/Host.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.config.model.provision; +import com.google.common.collect.ImmutableList; import com.yahoo.component.Version; import com.yahoo.config.provision.Flavor; @@ -15,12 +16,12 @@ import java.util.Optional; public class Host { private final String hostname; - private final List<String> aliases; + private final ImmutableList<String> aliases; private final Optional<Flavor> flavor; private final Optional<Version> version; public Host(String hostname) { - this(hostname, List.of(), Optional.empty()); + this(hostname, ImmutableList.of(), Optional.empty()); } public Host(String hostname, List<String> hostAliases) { @@ -33,7 +34,7 @@ public class Host { public Host(String hostname, List<String> hostAliases, Optional<Flavor> flavor, Optional<Version> version) { this.hostname = hostname; - this.aliases = List.copyOf(hostAliases); + this.aliases = ImmutableList.copyOf(hostAliases); this.flavor = flavor; this.version = version; } @@ -51,7 +52,7 @@ public class Host { @Override public String toString() { return hostname + (aliases.size() > 0 ? " (aliases: " + aliases + ")" : "" ) + - (flavor.map(value -> " (flavor: " + value + ")").orElse("")); + (flavor.isPresent() ? " (flavor: " + flavor.get() + ")" : ""); } } diff --git a/config-model/src/main/java/com/yahoo/schema/derived/RawRankProfile.java b/config-model/src/main/java/com/yahoo/schema/derived/RawRankProfile.java index 8bdbe574b0e..14ee60bb9a6 100644 --- a/config-model/src/main/java/com/yahoo/schema/derived/RawRankProfile.java +++ b/config-model/src/main/java/com/yahoo/schema/derived/RawRankProfile.java @@ -2,6 +2,7 @@ package com.yahoo.schema.derived; import ai.vespa.rankingexpression.importer.configmodelview.ImportedMlModels; +import com.google.common.collect.ImmutableList; import com.yahoo.collections.Pair; import com.yahoo.compress.Compressor; import com.yahoo.config.model.api.ModelContext; @@ -85,9 +86,9 @@ public class RawRankProfile implements RankProfilesConfig.Producer { private List<Pair<String, String>> decompress(Compressor.Compression compression) { String propertiesString = new String(compressor.decompress(compression), StandardCharsets.UTF_8); - if (propertiesString.isEmpty()) return List.of(); + if (propertiesString.isEmpty()) return ImmutableList.of(); - List<Pair<String, String>> properties = new ArrayList<>(); + ImmutableList.Builder<Pair<String, String>> properties = new ImmutableList.Builder<>(); for (int pos = 0; pos < propertiesString.length();) { int keyEndPos = propertiesString.indexOf(keyEndMarker, pos); String key = propertiesString.substring(pos, keyEndPos); @@ -97,7 +98,7 @@ public class RawRankProfile implements RankProfilesConfig.Producer { pos = valueEndPos + valueEndMarker.length(); properties.add(new Pair<>(key, value)); } - return List.copyOf(properties); + return properties.build(); } public String getName() { return name; } diff --git a/config-model/src/main/java/com/yahoo/schema/expressiontransforms/ExpressionTransforms.java b/config-model/src/main/java/com/yahoo/schema/expressiontransforms/ExpressionTransforms.java index 42e99f6aa45..132597ee75e 100644 --- a/config-model/src/main/java/com/yahoo/schema/expressiontransforms/ExpressionTransforms.java +++ b/config-model/src/main/java/com/yahoo/schema/expressiontransforms/ExpressionTransforms.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.schema.expressiontransforms; +import com.google.common.collect.ImmutableList; import com.yahoo.searchlib.rankingexpression.RankingExpression; import com.yahoo.searchlib.rankingexpression.transform.ConstantDereferencer; import com.yahoo.searchlib.rankingexpression.transform.ExpressionTransformer; @@ -23,19 +24,19 @@ public class ExpressionTransforms { public ExpressionTransforms() { transforms = - List.of(new TensorFlowFeatureConverter(), - new OnnxFeatureConverter(), - new OnnxModelTransformer(), - new XgboostFeatureConverter(), - new LightGBMFeatureConverter(), - new TokenTransformer(), - new ConstantDereferencer(), - new ConstantTensorTransformer(), - new FunctionInliner(), - new FunctionShadower(), - new TensorMaxMinTransformer(), - new Simplifier(), - new BooleanExpressionTransformer()); + ImmutableList.of(new TensorFlowFeatureConverter(), + new OnnxFeatureConverter(), + new OnnxModelTransformer(), + new XgboostFeatureConverter(), + new LightGBMFeatureConverter(), + new TokenTransformer(), + new ConstantDereferencer(), + new ConstantTensorTransformer(), + new FunctionInliner(), + new FunctionShadower(), + new TensorMaxMinTransformer(), + new Simplifier(), + new BooleanExpressionTransformer()); } public RankingExpression transform(RankingExpression expression, RankProfileTransformContext context) { diff --git a/config-model/src/main/java/com/yahoo/schema/processing/ReservedFunctionNames.java b/config-model/src/main/java/com/yahoo/schema/processing/ReservedFunctionNames.java index e1054c365b0..1ec4d5b58f2 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/ReservedFunctionNames.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/ReservedFunctionNames.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.schema.processing; +import com.google.common.collect.ImmutableSet; import com.yahoo.config.application.api.DeployLogger; import com.yahoo.schema.RankProfile; import com.yahoo.schema.RankProfileRegistry; @@ -8,10 +9,8 @@ import com.yahoo.schema.Schema; import com.yahoo.searchlib.rankingexpression.parser.RankingExpressionParserConstants; import com.yahoo.vespa.model.container.search.QueryProfiles; -import java.util.Arrays; import java.util.Set; import java.util.logging.Level; -import java.util.stream.Collectors; /** * Issues a warning if some function has a reserved name. This is not necessarily @@ -21,7 +20,7 @@ import java.util.stream.Collectors; */ public class ReservedFunctionNames extends Processor { - private static final Set<String> reservedNames = getReservedNames(); + private static Set<String> reservedNames = getReservedNames(); public ReservedFunctionNames(Schema schema, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) { super(schema, deployLogger, rankProfileRegistry, queryProfiles); @@ -45,9 +44,13 @@ public class ReservedFunctionNames extends Processor { } } - private static Set<String> getReservedNames() { - return Arrays.stream(RankingExpressionParserConstants.tokenImage) - .map(token -> token.substring(1, token.length()-1)).collect(Collectors.toUnmodifiableSet()); + private static ImmutableSet<String> getReservedNames() { + ImmutableSet.Builder<String> names = ImmutableSet.builder(); + for (String token : RankingExpressionParserConstants.tokenImage) { + String tokenWithoutQuotes = token.substring(1, token.length()-1); + names.add(tokenWithoutQuotes); + } + return names.build(); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/DefaultMetrics.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/DefaultMetrics.java index 6f4535bf4a1..2348970ed1a 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/DefaultMetrics.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/DefaultMetrics.java @@ -2,11 +2,14 @@ package com.yahoo.vespa.model.admin.monitoring; -import java.util.Collections; + +import com.google.common.collect.ImmutableSet; + import java.util.LinkedHashSet; import java.util.Set; import static com.yahoo.vespa.model.admin.monitoring.DefaultVespaMetrics.defaultVespaMetricSet; +import static java.util.Collections.singleton; /** * Metrics for the 'default' consumer, which is used by default for the generic metrics api and @@ -23,19 +26,20 @@ public class DefaultMetrics { private static MetricSet createMetricSet() { return new MetricSet(defaultMetricSetId, getAllMetrics(), - Set.of(defaultVespaMetricSet)); + singleton(defaultVespaMetricSet)); } private static Set<Metric> getAllMetrics() { - Set<Metric> metrics = new LinkedHashSet<>(); - - addContentMetrics(metrics); - addContainerMetrics(metrics); - addSearchChainMetrics(metrics); - return Collections.unmodifiableSet(metrics); + return ImmutableSet.<Metric>builder() + .addAll(getContentMetrics()) + .addAll(getContainerMetrics()) + .addAll(getSearchChainMetrics()) + .build(); } - private static void addContainerMetrics(Set<Metric> metrics) { + private static Set<Metric> getContainerMetrics() { + Set<Metric> metrics = new LinkedHashSet<>(); + metrics.add(new Metric("http.status.1xx.rate")); metrics.add(new Metric("http.status.2xx.rate")); metrics.add(new Metric("http.status.3xx.rate")); @@ -43,9 +47,13 @@ public class DefaultMetrics { metrics.add(new Metric("http.status.5xx.rate")); metrics.add(new Metric("jdisc.gc.ms.average")); metrics.add(new Metric("mem.heap.free.average")); + + return metrics; } - private static void addSearchChainMetrics(Set<Metric> metrics) { + private static Set<Metric> getSearchChainMetrics() { + Set<Metric> metrics = new LinkedHashSet<>(); + metrics.add(new Metric("queries.rate")); metrics.add(new Metric("query_latency.sum")); metrics.add(new Metric("query_latency.count")); @@ -64,9 +72,13 @@ public class DefaultMetrics { metrics.add(new Metric("degraded_queries.rate")); metrics.add(new Metric("failed_queries.rate")); metrics.add(new Metric("serverActiveThreads.average")); + + return metrics; } - private static void addContentMetrics(Set<Metric> metrics) { + private static Set<Metric> getContentMetrics() { + Set<Metric> metrics = new LinkedHashSet<>(); + metrics.add(new Metric("content.proton.search_protocol.docsum.requested_documents.rate")); metrics.add(new Metric("content.proton.search_protocol.docsum.latency.sum")); metrics.add(new Metric("content.proton.search_protocol.docsum.latency.count")); @@ -102,6 +114,8 @@ public class DefaultMetrics { metrics.add(new Metric("content.proton.documentdb.matching.rank_profile.rerank_time.average")); // TODO: Remove with Vespa 9 metrics.add(new Metric("content.proton.transactionlog.disk_usage.last")); + + return metrics; } private DefaultMetrics() { } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/MetricSet.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/MetricSet.java index fb67100b435..41204ce6e9a 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/MetricSet.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/MetricSet.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.model.admin.monitoring; import java.util.Collection; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; @@ -23,7 +24,7 @@ public class MetricSet { private final Set<MetricSet> children; public MetricSet(String id, Collection<Metric> metrics) { - this(id, metrics, Set.of()); + this(id, metrics, Collections.emptySet()); } public MetricSet(String id, Collection<Metric> metrics, Collection<MetricSet> children) { @@ -56,7 +57,9 @@ public class MetricSet { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof MetricSet that)) return false; + if (!(o instanceof MetricSet)) return false; + + MetricSet that = (MetricSet) o; return Objects.equals(id, that.id); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/NetworkMetrics.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/NetworkMetrics.java index 2f9c97f0488..4b905f35eab 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/NetworkMetrics.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/NetworkMetrics.java @@ -22,6 +22,10 @@ public class NetworkMetrics { new Metric("net.out.dropped") ); - return new MetricSet("network", dockerNetworkMetrics); + Set<Metric> networkMetrics = ImmutableSet.<Metric>builder() + .addAll(dockerNetworkMetrics) + .build(); + + return new MetricSet("network", networkMetrics); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/SecretStore.java b/config-model/src/main/java/com/yahoo/vespa/model/container/SecretStore.java index 8ddf08a593e..076fe7c0c53 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/SecretStore.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/SecretStore.java @@ -1,7 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.container; - +import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; @@ -17,7 +17,7 @@ public class SecretStore { } public List<Group> getGroups() { - return List.copyOf(groups); + return ImmutableList.copyOf(groups); } public static class Group { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ml/ModelsEvaluatorTester.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ml/ModelsEvaluatorTester.java index 1232e32a633..4afde25cafd 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ml/ModelsEvaluatorTester.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ml/ModelsEvaluatorTester.java @@ -8,6 +8,7 @@ import ai.vespa.rankingexpression.importer.onnx.OnnxImporter; import ai.vespa.rankingexpression.importer.tensorflow.TensorFlowImporter; import ai.vespa.rankingexpression.importer.vespa.VespaImporter; import ai.vespa.rankingexpression.importer.xgboost.XGBoostImporter; +import com.google.common.collect.ImmutableList; import com.yahoo.config.FileReference; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.application.api.FileRegistry; @@ -33,7 +34,6 @@ import java.nio.ByteBuffer; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -49,7 +49,7 @@ import java.util.Map; */ public class ModelsEvaluatorTester { - private static final List<MlModelImporter> importers = List.of(new TensorFlowImporter(), + private static final ImmutableList<MlModelImporter> importers = ImmutableList.of(new TensorFlowImporter(), new OnnxImporter(), new LightGBMImporter(), new XGBoostImporter(), diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java index 0722a9dc15a..007e8401c70 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.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.vespa.model.container.xml; +import com.google.common.collect.ImmutableList; import com.yahoo.component.ComponentId; import com.yahoo.component.ComponentSpecification; import com.yahoo.component.Version; @@ -153,7 +154,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { private final boolean httpServerEnabled; protected DeployLogger log; - public static final List<ConfigModelId> configModelIds = List.of(ConfigModelId.fromName(CONTAINER_TAG)); + public static final List<ConfigModelId> configModelIds = ImmutableList.of(ConfigModelId.fromName(CONTAINER_TAG)); private static final String xmlRendererId = RendererRegistry.xmlRendererId.getName(); private static final String jsonRendererId = RendererRegistry.jsonRendererId.getName(); @@ -216,7 +217,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { addStatusHandlers(cluster, context.getDeployState().isHosted()); addUserHandlers(deployState, cluster, spec, context); - addClients(deployState, spec, cluster); + addClients(deployState, spec, cluster, context); addHttp(deployState, spec, cluster, context); addAccessLogs(deployState, cluster, spec); @@ -379,7 +380,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { // Only consider global endpoints. .filter(endpoint -> endpoint.scope() == ApplicationClusterEndpoint.Scope.global) .flatMap(endpoint -> endpoint.names().stream()) - .collect(Collectors.toCollection(LinkedHashSet::new)); + .collect(Collectors.toCollection(() -> new LinkedHashSet<>())); // Build the comma delimited list of endpoints this container should be known as. // Confusingly called 'rotations' for legacy reasons. @@ -490,7 +491,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { } - protected void addClients(DeployState deployState, Element spec, ApplicationContainerCluster cluster) { + protected void addClients(DeployState deployState, Element spec, ApplicationContainerCluster cluster, ConfigModelContext context) { if (!deployState.isHosted() || !deployState.zone().system().isPublic() || !deployState.featureFlags().enableDataPlaneFilter()) return; List<Client> clients; @@ -768,10 +769,11 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { return new JvmGcOptions(context.getDeployState(), jvmGCOptions).build(); } - private static String getJvmOptions(Element nodesElement, + private static String getJvmOptions(ApplicationContainerCluster cluster, + Element nodesElement, DeployState deployState, boolean legacyOptions) { - return new JvmOptions(nodesElement, deployState, legacyOptions).build(); + return new JvmOptions(cluster, nodesElement, deployState, legacyOptions).build(); } private static String extractAttribute(Element element, String attrName) { @@ -792,7 +794,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { private void extractJvmFromLegacyNodesTag(List<ApplicationContainer> nodes, ApplicationContainerCluster cluster, Element nodesElement, ConfigModelContext context) { - applyNodesTagJvmArgs(nodes, getJvmOptions(nodesElement, context.getDeployState(), true)); + applyNodesTagJvmArgs(nodes, getJvmOptions(cluster, nodesElement, context.getDeployState(), true)); if (cluster.getJvmGCOptions().isEmpty()) { String jvmGCOptions = extractAttribute(nodesElement, VespaDomBuilder.JVM_GC_OPTIONS); @@ -804,7 +806,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { private void extractJvmTag(List<ApplicationContainer> nodes, ApplicationContainerCluster cluster, Element nodesElement, Element jvmElement, ConfigModelContext context) { - applyNodesTagJvmArgs(nodes, getJvmOptions(nodesElement, context.getDeployState(), false)); + applyNodesTagJvmArgs(nodes, getJvmOptions(cluster, nodesElement, context.getDeployState(), false)); applyMemoryPercentage(cluster, jvmElement.getAttribute(VespaDomBuilder.Allocated_MEMORY_ATTRIB_NAME)); String jvmGCOptions = extractAttribute(jvmElement, VespaDomBuilder.GC_OPTIONS); cluster.setJvmGCOptions(buildJvmGCOptions(context, jvmGCOptions)); @@ -1193,12 +1195,14 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { // debug port will not be available in hosted, don't allow private static final Pattern invalidInHostedatttern = Pattern.compile("-Xrunjdwp:transport=.*"); + private final ContainerCluster<?> cluster; private final Element nodesElement; private final DeployLogger logger; private final boolean legacyOptions; private final boolean isHosted; - public JvmOptions(Element nodesElement, DeployState deployState, boolean legacyOptions) { + public JvmOptions(ContainerCluster<?> cluster, Element nodesElement, DeployState deployState, boolean legacyOptions) { + this.cluster = cluster; this.nodesElement = nodesElement; this.logger = deployState.getDeployLogger(); this.legacyOptions = legacyOptions; @@ -1243,9 +1247,10 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { .collect(Collectors.toList()); if (isHosted) invalidOptions.addAll(Arrays.stream(optionList) - .filter(option -> !option.isEmpty()) - .filter(option -> Pattern.matches(invalidInHostedatttern.pattern(), option)) - .sorted().toList()); + .filter(option -> !option.isEmpty()) + .filter(option -> Pattern.matches(invalidInHostedatttern.pattern(), option)) + .sorted() + .collect(Collectors.toList())); if (invalidOptions.isEmpty()) return; @@ -1294,9 +1299,10 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { if (isHosted) { // CMS GC options cannot be used in hosted, CMS is unsupported in JDK 17 invalidOptions.addAll(Arrays.stream(optionList) - .filter(option -> !option.isEmpty()) - .filter(option -> Pattern.matches(invalidCMSPattern.pattern(), option) || - option.equals("-XX:+UseConcMarkSweepGC")).toList()); + .filter(option -> !option.isEmpty()) + .filter(option -> Pattern.matches(invalidCMSPattern.pattern(), option) || + option.equals("-XX:+UseConcMarkSweepGC")) + .collect(Collectors.toList())); } logOrFailInvalidOptions(invalidOptions); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankProfileSearchFixture.java b/config-model/src/test/java/com/yahoo/schema/processing/RankProfileSearchFixture.java index 58c514bdda8..15fe8250b71 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankProfileSearchFixture.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankProfileSearchFixture.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.schema.processing; +import com.google.common.collect.ImmutableList; import com.yahoo.config.application.api.ApplicationPackage; import ai.vespa.rankingexpression.importer.configmodelview.MlModelImporter; import com.yahoo.config.model.application.provider.BaseDeployLogger; @@ -36,10 +37,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; */ class RankProfileSearchFixture { - private final List<MlModelImporter> importers = List.of(new TensorFlowImporter(), - new OnnxImporter(), - new LightGBMImporter(), - new XGBoostImporter()); + private final ImmutableList<MlModelImporter> importers = ImmutableList.of(new TensorFlowImporter(), + new OnnxImporter(), + new LightGBMImporter(), + new XGBoostImporter()); private final RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); private final QueryProfileRegistry queryProfileRegistry; private final Schema schema; @@ -50,6 +51,10 @@ class RankProfileSearchFixture { return rankProfileRegistry; } + public QueryProfileRegistry getQueryProfileRegistry() { + return queryProfileRegistry; + } + RankProfileSearchFixture(String rankProfiles) throws ParseException { this(MockApplicationPackage.createEmpty(), new QueryProfileRegistry(), rankProfiles); } @@ -108,6 +113,11 @@ class RankProfileSearchFixture { return compiled; } + /** Returns the given uncompiled profile */ + public RankProfile rankProfile(String rankProfile) { + return rankProfileRegistry.get(schema, rankProfile); + } + /** Returns the given compiled profile, or null if not compiled yet or not present at all */ public RankProfile compiledRankProfile(String rankProfile) { return compiledRankProfiles.get(rankProfile); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/admin/monitoring/MetricSetTest.java b/config-model/src/test/java/com/yahoo/vespa/model/admin/monitoring/MetricSetTest.java index 7eec4450f33..8a15d87b6c5 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/admin/monitoring/MetricSetTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/admin/monitoring/MetricSetTest.java @@ -1,10 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.admin.monitoring; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; import org.junit.jupiter.api.Test; -import java.util.List; import java.util.Map; import static java.util.Collections.emptyList; @@ -18,9 +19,9 @@ public class MetricSetTest { @Test void metrics_from_children_are_added() { - MetricSet child1 = new MetricSet("child1", List.of(new Metric("child1_metric"))); - MetricSet child2 = new MetricSet("child2", List.of(new Metric("child2_metric"))); - MetricSet parent = new MetricSet("parent", emptyList(), List.of(child1, child2)); + MetricSet child1 = new MetricSet("child1", ImmutableList.of(new Metric("child1_metric"))); + MetricSet child2 = new MetricSet("child2", ImmutableList.of(new Metric("child2_metric"))); + MetricSet parent = new MetricSet("parent", emptyList(), ImmutableList.of(child1, child2)); Map<String, Metric> parentMetrics = parent.getMetrics(); assertEquals(2, parentMetrics.size()); @@ -30,8 +31,8 @@ public class MetricSetTest { @Test void adding_the_same_child_set_twice_has_no_effect() { - MetricSet child = new MetricSet("child", List.of(new Metric("child_metric"))); - MetricSet parent = new MetricSet("parent", emptyList(), List.of(child, child)); + MetricSet child = new MetricSet("child", ImmutableList.of(new Metric("child_metric"))); + MetricSet parent = new MetricSet("parent", emptyList(), ImmutableList.of(child, child)); Map<String, Metric> parentMetrics = parent.getMetrics(); assertEquals(1, parentMetrics.size()); @@ -43,10 +44,16 @@ public class MetricSetTest { String METRIC_NAME = "metric1"; String COMMON_DIMENSION_KEY = "commonKey"; - Map<String, String> childDimensions = Map.of(COMMON_DIMENSION_KEY, "childCommonVal", "childKey", "childVal"); + Map<String, String> childDimensions = ImmutableMap.<String, String>builder() + .put(COMMON_DIMENSION_KEY, "childCommonVal") + .put("childKey", "childVal") + .build(); Metric childMetric = new Metric(METRIC_NAME, "child-output-name", "child-description", childDimensions); - Map<String, String> parentDimensions = Map.of(COMMON_DIMENSION_KEY, "parentCommonVal","parentKey", "parentVal"); + Map<String, String> parentDimensions = ImmutableMap.<String, String>builder() + .put(COMMON_DIMENSION_KEY, "parentCommonVal") + .put("parentKey", "parentVal") + .build(); Metric parentMetric = new Metric(METRIC_NAME, "parent-output-name", "parent-description", parentDimensions); MetricSet child = new MetricSet("set1", Sets.newHashSet(childMetric)); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ValidationTester.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ValidationTester.java index cb535380b18..a7f3d134b57 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ValidationTester.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ValidationTester.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.vespa.model.application.validation; +import com.google.common.collect.ImmutableList; import com.yahoo.collections.Pair; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.model.api.ConfigChangeAction; @@ -76,7 +77,7 @@ public class ValidationTester { Provisioned provisioned = hostProvisioner.startProvisionedRecording(); ApplicationPackage newApp = new MockApplicationPackage.Builder() .withServices(services) - .withSchemas(List.of(MUSIC_SCHEMA, BOOK_SCHEMA)) + .withSchemas(ImmutableList.of(MUSIC_SCHEMA, BOOK_SCHEMA)) .withValidationOverrides(validationOverrides) .build(); VespaModelCreatorWithMockPkg newModelCreator = new VespaModelCreatorWithMockPkg(newApp); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/test/VespaModelTester.java b/config-model/src/test/java/com/yahoo/vespa/model/test/VespaModelTester.java index a31d4cd4e20..ed0cedd4e87 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/test/VespaModelTester.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/test/VespaModelTester.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.vespa.model.test; +import com.google.common.collect.ImmutableList; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.model.ConfigModelRegistry; import com.yahoo.config.model.NullConfigModelRegistry; @@ -89,7 +90,7 @@ public class VespaModelTester { "-" + Math.round(resources.memoryGb()) + "-" + Math.round(resources.diskGb()), count - i); - hosts.add(new Host(hostname, List.of(), flavor)); + hosts.add(new Host(hostname, ImmutableList.of(), flavor)); } this.hostsByResources.put(resources, hosts); diff --git a/container-core/src/main/java/com/yahoo/component/chain/Chain.java b/container-core/src/main/java/com/yahoo/component/chain/Chain.java index 24c4a0a0e2e..e44eba35efe 100644 --- a/container-core/src/main/java/com/yahoo/component/chain/Chain.java +++ b/container-core/src/main/java/com/yahoo/component/chain/Chain.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.component.chain; +import com.google.common.collect.ImmutableList; import com.yahoo.component.ComponentId; import com.yahoo.component.chain.dependencies.ordering.ChainBuilder; @@ -27,7 +28,7 @@ public class Chain<COMPONENT extends ChainedComponent> { /** Create a chain directly. This will NOT order the chain by the ordering constraints. */ public Chain(ComponentId id, List<COMPONENT> componentList) { this.id = id; - this.componentList = List.copyOf(componentList); + this.componentList = ImmutableList.copyOf(componentList); } /** Create a chain directly. This will NOT order the chain by the ordering constraints. */ diff --git a/container-core/src/main/java/com/yahoo/processing/handler/ProcessingResponse.java b/container-core/src/main/java/com/yahoo/processing/handler/ProcessingResponse.java index 959caa215be..28645b4bde0 100644 --- a/container-core/src/main/java/com/yahoo/processing/handler/ProcessingResponse.java +++ b/container-core/src/main/java/com/yahoo/processing/handler/ProcessingResponse.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.processing.handler; +import com.google.common.collect.ImmutableList; import com.yahoo.container.jdisc.AsyncHttpResponse; import com.yahoo.container.jdisc.VespaHeaders; import com.yahoo.jdisc.handler.CompletionHandler; @@ -109,13 +110,13 @@ public class ProcessingResponse extends AsyncHttpResponse { private List<ErrorMessage> flattenErrors(Response processingResponse) { Set<ErrorMessage> errors = flattenErrors(null, processingResponse.data()); - if (errors == null) return List.of(); - return List.copyOf(errors); + if (errors == null) return Collections.emptyList(); + return ImmutableList.copyOf(errors); } @SuppressWarnings("unchecked") private Set<ErrorMessage> flattenErrors(Set<ErrorMessage> errors, Data data) { - if (data.request() == null) return Set.of(); // Not allowed, but handle anyway + if (data.request() == null) return Collections.EMPTY_SET; // Not allowed, but handle anyway errors = addTo(errors, data.request().errors()); if (data instanceof DataList) { 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)); } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ServiceConvergence.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ServiceConvergence.java index f0f0078be5a..f0ed73c2dc9 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ServiceConvergence.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ServiceConvergence.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.vespa.hosted.controller.api.integration.configserver; +import com.google.common.collect.ImmutableList; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.HostName; import com.yahoo.config.provision.zone.ZoneId; @@ -27,7 +28,7 @@ public class ServiceConvergence { this.zone = zone; this.converged = converged; this.wantedGeneration = wantedGeneration; - this.services = List.copyOf(services); + this.services = ImmutableList.copyOf(services); } public ApplicationId application() { return application; } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/entity/MemoryEntityService.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/entity/MemoryEntityService.java index ae71c5893e8..a33ef135adf 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/entity/MemoryEntityService.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/entity/MemoryEntityService.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.vespa.hosted.controller.api.integration.entity; +import com.google.common.collect.ImmutableMap; import com.yahoo.vespa.hosted.controller.api.identifiers.Property; import com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId; @@ -18,8 +19,8 @@ public class MemoryEntityService implements EntityService { @Override public Map<PropertyId, Property> listProperties() { - return Map.of(new PropertyId("1234"), new Property("foo"), - new PropertyId("4321"), new Property("bar")); + return ImmutableMap.of(new PropertyId("1234"), new Property("foo"), + new PropertyId("4321"), new Property("bar")); } @Override diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Contact.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Contact.java index 7e566e07c7f..a1f27f85500 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Contact.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Contact.java @@ -1,6 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.organization; +import com.google.common.collect.ImmutableList; + import java.net.URI; import java.util.List; import java.util.Objects; @@ -24,7 +26,7 @@ public class Contact { this.propertyUrl = Objects.requireNonNull(propertyUrl, "propertyUrl must be non-null"); this.url = Objects.requireNonNull(url, "url must be non-null"); this.issueTrackerUrl = Objects.requireNonNull(issueTrackerUrl, "issueTrackerUrl must be non-null"); - this.persons = List.copyOf(Objects.requireNonNull(persons, "persons must be non-null")); + this.persons = ImmutableList.copyOf(Objects.requireNonNull(persons, "persons must be non-null")); this.queue = queue; this.component = component; } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Issue.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Issue.java index 7db85da1dbb..55f65d71165 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Issue.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Issue.java @@ -1,6 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.organization; +import com.google.common.collect.ImmutableList; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -28,7 +30,7 @@ public class Issue { this.summary = summary; this.description = description; - this.labels = List.copyOf(labels); + this.labels = ImmutableList.copyOf(labels); this.assignee = assignee; this.type = type; this.queue = queue; diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Mail.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Mail.java index e84578790ab..36b6e251fbc 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Mail.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Mail.java @@ -1,10 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.organization; -import com.yahoo.prelude.IndexFacts; +import com.google.common.collect.ImmutableList; import java.util.Collection; -import java.util.List; import java.util.Objects; import java.util.Optional; @@ -32,7 +31,7 @@ public class Mail { if (recipients.isEmpty()) throw new IllegalArgumentException("Empty recipient list is not allowed."); recipients.forEach(Objects::requireNonNull); - this.recipients = List.copyOf(recipients); + this.recipients = ImmutableList.copyOf(recipients); this.subject = Objects.requireNonNull(subject); this.message = Objects.requireNonNull(message); this.htmlMessage = Objects.requireNonNull(htmlMessage); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/athenz/responses/property-list.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/athenz/responses/property-list.json index 2913769999d..2931fc8b162 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/athenz/responses/property-list.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/athenz/responses/property-list.json @@ -1,12 +1,12 @@ { "properties": [ { - "propertyid": "4321", - "property": "bar" - }, - { "propertyid": "1234", "property": "foo" + }, + { + "propertyid": "4321", + "property": "bar" } ] } diff --git a/standalone-container/src/main/java/com/yahoo/application/container/impl/ClassLoaderOsgiFramework.java b/standalone-container/src/main/java/com/yahoo/application/container/impl/ClassLoaderOsgiFramework.java index 48f1efc7615..1526bc3dc5d 100644 --- a/standalone-container/src/main/java/com/yahoo/application/container/impl/ClassLoaderOsgiFramework.java +++ b/standalone-container/src/main/java/com/yahoo/application/container/impl/ClassLoaderOsgiFramework.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.application.container.impl; +import com.google.common.collect.Lists; import com.yahoo.container.standalone.StandaloneContainerApplication; import com.yahoo.jdisc.application.OsgiFramework; import com.yahoo.jdisc.application.OsgiHeader; @@ -50,15 +51,15 @@ import java.util.jar.JarFile; */ public final class ClassLoaderOsgiFramework implements OsgiFramework { - private final BundleContextImpl bundleContextImpl = new BundleContextImpl(); - private final SystemBundleImpl systemBundleImpl = new SystemBundleImpl(); - private final BundleWiringImpl bundleWiringImpl = new BundleWiringImpl(); + private BundleContextImpl bundleContextImpl = new BundleContextImpl(); + private SystemBundleImpl systemBundleImpl = new SystemBundleImpl(); + private BundleWiringImpl bundleWiringImpl = new BundleWiringImpl(); - private final List<URL> bundleLocations = new ArrayList<>(); - private final List<Bundle> bundleList = new ArrayList<>(List.of(systemBundleImpl)); + private List<URL> bundleLocations = new ArrayList<>(); + private List<Bundle> bundleList = Lists.newArrayList(systemBundleImpl); private ClassLoader classLoader = null; - private final AtomicInteger nextBundleId = new AtomicInteger(1); + private AtomicInteger nextBundleId = new AtomicInteger(1); @Override public List<Bundle> installBundle(String bundleLocation) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java index 2027dcfb60f..fed9f7017ed 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java @@ -2,6 +2,7 @@ package com.yahoo.tensor; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; @@ -10,6 +11,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; /** * A mixed tensor type. This is class is currently suitable for serialization @@ -28,14 +30,14 @@ public class MixedTensor implements Tensor { private final TensorType type; /** The list of cells in the tensor */ - private final List<Cell> cells; + private final ImmutableList<Cell> cells; /** An index structure over the cell list */ private final Index index; - private MixedTensor(TensorType type, List<Cell> cells, Index index) { + private MixedTensor(TensorType type, ImmutableList<Cell> cells, Index index) { this.type = type; - this.cells = List.copyOf(cells); + this.cells = ImmutableList.copyOf(cells); this.index = index; } @@ -89,7 +91,7 @@ public class MixedTensor implements Tensor { @Override public Iterator<Double> valueIterator() { return new Iterator<>() { - final Iterator<Cell> cellIterator = cellIterator(); + Iterator<Cell> cellIterator = cellIterator(); @Override public boolean hasNext() { return cellIterator.hasNext(); @@ -152,14 +154,14 @@ public class MixedTensor implements Tensor { @Override public String toAbbreviatedString(boolean withType, boolean shortForms) { - return toString(withType, shortForms, Math.max(2, 10 / (type().dimensions().stream().filter(TensorType.Dimension::isMapped).count() + 1))); + return toString(withType, shortForms, Math.max(2, 10 / (type().dimensions().stream().filter(d -> d.isMapped()).count() + 1))); } private String toString(boolean withType, boolean shortForms, long maxCells) { if (! shortForms || type.rank() == 0 - || type.rank() > 1 && type.dimensions().stream().filter(TensorType.Dimension::isIndexed).anyMatch(d -> d.size().isEmpty()) - || type.dimensions().stream().filter(TensorType.Dimension::isMapped).count() > 1) + || type.rank() > 1 && type.dimensions().stream().filter(d -> d.isIndexed()).anyMatch(d -> d.size().isEmpty()) + || type.dimensions().stream().filter(d -> d.isMapped()).count() > 1) return Tensor.toStandardString(this, withType, shortForms, maxCells); return (withType ? type + ":" : "") + index.contentToString(this, maxCells); @@ -241,7 +243,7 @@ public class MixedTensor implements Tensor { indexBuilder = new Index.Builder(type); index = indexBuilder.index(); denseSubtype = new TensorType(type.valueType(), - type.dimensions().stream().filter(TensorType.Dimension::isIndexed).toList()); + type.dimensions().stream().filter(d -> d.isIndexed()).collect(Collectors.toList())); } public long denseSubspaceSize() { @@ -288,7 +290,7 @@ public class MixedTensor implements Tensor { @Override public MixedTensor build() { long count = 0; - List<Cell> builder = new ArrayList<>(); + ImmutableList.Builder<Cell> builder = new ImmutableList.Builder<>(); for (Map.Entry<TensorAddress, double[]> entry : denseSubspaceMap.entrySet()) { TensorAddress sparsePart = entry.getKey(); @@ -302,7 +304,7 @@ public class MixedTensor implements Tensor { count++; } } - return new MixedTensor(type, builder, indexBuilder.build()); + return new MixedTensor(type, builder.build(), indexBuilder.build()); } } @@ -317,7 +319,7 @@ public class MixedTensor implements Tensor { */ public static class UnboundBuilder extends Builder { - private final Map<TensorAddress, Double> cells; + private Map<TensorAddress, Double> cells; private final long[] dimensionBounds; private UnboundBuilder(TensorType type) { @@ -392,8 +394,8 @@ public class MixedTensor implements Tensor { private Index(TensorType type) { this.type = type; - this.mappedDimensions = type.dimensions().stream().filter(d -> !d.isIndexed()).toList(); - this.indexedDimensions = type.dimensions().stream().filter(TensorType.Dimension::isIndexed).toList(); + this.mappedDimensions = type.dimensions().stream().filter(d -> !d.isIndexed()).collect(Collectors.toList()); + this.indexedDimensions = type.dimensions().stream().filter(d -> d.isIndexed()).collect(Collectors.toList()); this.sparseType = createPartialType(type.valueType(), mappedDimensions); this.denseType = createPartialType(type.valueType(), indexedDimensions); } |