summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2020-08-07 19:35:37 +0200
committerGitHub <noreply@github.com>2020-08-07 19:35:37 +0200
commit6e3fb9bf6fde44d1ebc194b53f2d3683032456c5 (patch)
treeb41600d0cb2367fb8f36b227ad8931f3948cb71a
parent8c7f94d5e49634068595af964d69587d6b117853 (diff)
parentcfaebe9b2d7b30df734e6613a536430d5e4dd597 (diff)
Merge pull request #14009 from vespa-engine/bratseth/compact-2
Bratseth/compact 2
-rw-r--r--config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/compiled/Binding.java12
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/compiled/DimensionalValue.java3
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileXMLReader.java6
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/compiled/BindingTestCase.java56
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java1
6 files changed, 68 insertions, 12 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java b/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java
index 7c2c491ccf1..5b76163e97f 100644
--- a/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java
+++ b/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java
@@ -181,7 +181,7 @@ public final class ClusterSpec {
* are ignored.
*/
public boolean satisfies(ClusterSpec other) {
- if (!other.id.equals(this.id)) return false; // ID mismatch
+ if ( ! other.id.equals(this.id)) return false; // ID mismatch
if (other.type.isContent() || this.type.isContent()) // Allow seamless transition between content and combined
return other.type.isContent() == this.type.isContent();
return other.type.equals(this.type);
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/Binding.java b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/Binding.java
index 3812cdaac3c..8638a99172f 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/Binding.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/Binding.java
@@ -90,12 +90,12 @@ public class Binding implements Comparable<Binding> {
* Returns whether this binding is a proper generalization of the given binding:
* Meaning it contains a proper subset of the given bindings.
*/
- public boolean generalizes(Binding binding) {
- if ( dimensions.length >= binding.dimensions.length) return false;
- for (int i = 0; i < dimensions.length; i++) {
- int indexOfDimension = indexOf(dimensions[i], binding.dimensions);
- if (indexOfDimension < 0) return false;
- if ( ! binding.dimensionValues[i].equals(binding.dimensionValues[indexOfDimension])) return false;
+ public boolean generalizes(Binding other) {
+ if ( this.dimensions.length >= other.dimensions.length) return false;
+ for (int i = 0; i < this.dimensions.length; i++) {
+ int otherIndexOfDimension = this.indexOf(dimensions[i], other.dimensions);
+ if (otherIndexOfDimension < 0) return false;
+ if ( ! this.dimensionValues[i].equals(other.dimensionValues[otherIndexOfDimension])) return false;
}
return true;
}
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/DimensionalValue.java b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/DimensionalValue.java
index a44ce2034fc..fb62cfca7d3 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/DimensionalValue.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/DimensionalValue.java
@@ -179,12 +179,13 @@ public class DimensionalValue<VALUE> {
void compact() {
Collections.sort(variants);
List<Binding> compacted = new ArrayList<>();
+
if (variants.get(variants.size() - 1).dimensions().length == 0) { // Shortcut
variants = List.of(variants.get(variants.size() - 1));
}
else {
for (int i = variants.size() - 1; i >= 0; i--) {
- if (!containsGeneralizationOf(variants.get(i), compacted))
+ if ( ! containsGeneralizationOf(variants.get(i), compacted))
compacted.add(variants.get(i));
}
Collections.reverse(compacted);
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileXMLReader.java b/container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileXMLReader.java
index 1b1cdce5890..db6d0560c5f 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileXMLReader.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileXMLReader.java
@@ -45,17 +45,17 @@ public class QueryProfileXMLReader {
for (File file : sortFiles(dir)) {
if ( ! file.getName().endsWith(".xml")) continue;
- queryProfileReaders.add(new NamedReader(file.getName(),new FileReader(file)));
+ queryProfileReaders.add(new NamedReader(file.getName(), new FileReader(file)));
}
File typeDir=new File(dir,"types");
if (typeDir.isDirectory()) {
for (File file : sortFiles(typeDir)) {
if ( ! file.getName().endsWith(".xml")) continue;
- queryProfileTypeReaders.add(new NamedReader(file.getName(),new FileReader(file)));
+ queryProfileTypeReaders.add(new NamedReader(file.getName(), new FileReader(file)));
}
}
- return read(queryProfileTypeReaders,queryProfileReaders);
+ return read(queryProfileTypeReaders, queryProfileReaders);
}
catch (IOException e) {
throw new IllegalArgumentException("Could not read query profiles from '" + directory + "'", e);
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/compiled/BindingTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/compiled/BindingTestCase.java
new file mode 100644
index 00000000000..621950ebc65
--- /dev/null
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/compiled/BindingTestCase.java
@@ -0,0 +1,56 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.search.query.profile.compiled;
+
+import com.yahoo.search.query.profile.DimensionBinding;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author bratseth
+ */
+public class BindingTestCase {
+
+ @Test
+ public void testGeneralizes() {
+ Map<String, String> m1 = new HashMap<>();
+ m1.put("a", "a1");
+ m1.put("b", "b1");
+ m1.put("c", "c1");
+ m1.put("e", "e1");
+
+ Map<String, String> m2 = new HashMap<>();
+ m2.put("a", "a2");
+ m2.put("b", "b2");
+ m2.put("c", "c2");
+ m2.put("d", "d2");
+ m2.put("e", "e2");
+
+ Map<String, String> m3 = new HashMap<>();
+ m3.put("a", "a1");
+ m3.put("b", "b1");
+ m3.put("c", "c1");
+ m3.put("d", "d1");
+ m3.put("e", "e1");
+
+ Map<String, String> m4 = new HashMap<>();
+ m4.put("a", "a1");
+ m4.put("b", "b1");
+ m4.put("c", "c1");
+ m4.put("d", "d2");
+ m4.put("e", "e1");
+
+ Binding b1 = Binding.createFrom(DimensionBinding.createFrom(m1));
+ Binding b2 = Binding.createFrom(DimensionBinding.createFrom(m2));
+ Binding b3 = Binding.createFrom(DimensionBinding.createFrom(m3));
+ Binding b4 = Binding.createFrom(DimensionBinding.createFrom(m4));
+ assertFalse(b1.generalizes(b2));
+ assertTrue(b1.generalizes(b3));
+ assertTrue(b1.generalizes(b4));
+ }
+
+}
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java
index 7d3bec7cc9e..03faeaae8a0 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java
@@ -13,7 +13,6 @@ import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.search.query.profile.compiled.CompiledQueryProfile;
import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
import com.yahoo.search.query.profile.compiled.ValueWithSource;
-import com.yahoo.yolean.trace.TraceNode;
import org.junit.Ignore;
import org.junit.Test;