summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2020-06-30 20:38:47 +0200
committerJon Bratseth <bratseth@gmail.com>2020-06-30 20:38:47 +0200
commit44d166fc0f0edfd98bad17c45c05e1ca412255f9 (patch)
treea1c3cde1bab39c67e66b21436a2dd4479f4c4716
parent2b5907b1df400a4f7af2dc3e29b4035fd6ce3f49 (diff)
Skip variants on disjoint paths
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/DimensionBinding.java16
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java17
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileRegistry.java1
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariants.java8
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java14
6 files changed, 31 insertions, 27 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/DimensionBinding.java b/container-search/src/main/java/com/yahoo/search/query/profile/DimensionBinding.java
index 0cbfdc5dca0..2d89795a90f 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/DimensionBinding.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/DimensionBinding.java
@@ -116,6 +116,20 @@ public class DimensionBinding {
}
/**
+ * Returns whether this is compatible with the given binding.
+ * Two bindings are compatible if the bind the same values of all shared keys.
+ */
+ public boolean isCompatibleWith(DimensionBinding other) {
+ for (String dimensionInOther : other.dimensions) {
+ String thisValue = this.getContext().get(dimensionInOther);
+ if (thisValue == null) continue;
+ if ( ! thisValue.equals(other.getContext().get(dimensionInOther)))
+ return false;
+ }
+ return true;
+ }
+
+ /**
* Combines this binding with another if compatible.
* Two bindings are incompatible if
* <ul>
@@ -162,7 +176,7 @@ public class DimensionBinding {
combined.add(d2.get(d2Index++));
}
else {
- return null; // no independent and no agreement
+ return null; // not independent and no agreement
}
}
if (d1Index < d1.size())
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 6fe6c03ce4a..b6b03d37da8 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
@@ -526,6 +526,7 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable
QueryProfileVisitor visitor,
DimensionBinding dimensionBinding,
QueryProfile owner) {
+ //System.out.println(" visiting " + this);
visitor.onQueryProfile(this, dimensionBinding, owner, null);
if (visitor.isDone()) return;
@@ -539,6 +540,7 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable
if (visitor.visitInherited())
visitInherited(allowContent, visitor, dimensionBinding, owner);
+ //System.out.println(" done visiting " + this);
}
protected void visitVariants(boolean allowContent, QueryProfileVisitor visitor, DimensionBinding dimensionBinding) {
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java
index 68199777cb7..5dacd347c2c 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java
@@ -12,6 +12,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
+import java.util.stream.Collectors;
/**
* Compile a set of query profiles into compiled profiles.
@@ -24,9 +25,8 @@ public class QueryProfileCompiler {
public static CompiledQueryProfileRegistry compile(QueryProfileRegistry input) {
CompiledQueryProfileRegistry output = new CompiledQueryProfileRegistry(input.getTypeRegistry());
- for (QueryProfile inputProfile : input.allComponents()) {
+ for (QueryProfile inputProfile : input.allComponents())
output.register(compile(inputProfile, output));
- }
return output;
}
@@ -40,13 +40,11 @@ public class QueryProfileCompiler {
// Resolve values for each existing variant and combine into a single data structure
Set<DimensionBindingForPath> variants = collectVariants(CompoundName.empty, in, DimensionBinding.nullBinding);
variants.add(new DimensionBindingForPath(DimensionBinding.nullBinding, CompoundName.empty)); // if this contains no variants
- log.fine(() -> "Compiling " + in.toString() + " having " + variants.size() + " variants");
- System.out.println("Compiling " + in.toString() + " having " + variants.size() + " variants");
+ log.fine(() -> "Compiling " + in + " having " + variants.size() + " variants");
+
for (DimensionBindingForPath variant : variants) {
log.finer(() -> " Compiling variant " + variant);
- System.out.println(" Compiling variant " + variant);
for (Map.Entry<String, ValueWithSource> entry : in.visitValues(variant.path(), variant.binding().getContext()).valuesWithSource().entrySet()) {
- System.out.println(" got " + entry);
CompoundName fullName = variant.path().append(entry.getKey());
values.put(fullName, variant.binding(), entry.getValue());
if (entry.getValue().isUnoverridable())
@@ -104,6 +102,7 @@ public class QueryProfileCompiler {
*/
private static Set<DimensionBindingForPath> wildcardExpanded(Set<DimensionBindingForPath> variants) {
Set<DimensionBindingForPath> expanded = new HashSet<>();
+
for (var variant : variants) {
if (hasWildcardBeforeEnd(variant.binding()))
expanded.addAll(wildcardExpanded(variant, variants));
@@ -124,10 +123,10 @@ public class QueryProfileCompiler {
Set<DimensionBindingForPath> expanded = new HashSet<>();
for (var variant : variants) {
if (variant.binding().isNull()) continue;
+ if ( ! variant.path().hasPrefix(variantToExpand.path())) continue;
DimensionBinding combined = variantToExpand.binding().combineWith(variant.binding());
- if ( ! combined.isInvalid() ) {
+ if ( ! combined.isInvalid() )
expanded.add(new DimensionBindingForPath(combined, variantToExpand.path()));
- }
}
return expanded;
}
@@ -140,7 +139,7 @@ public class QueryProfileCompiler {
for (DimensionBindingForPath v1 : v1s) {
if (v1.binding().isNull()) continue;
for (DimensionBindingForPath v2 : v2s) {
- if (v1.binding().isNull()) continue;
+ if (v2.binding().isNull()) continue;
DimensionBinding combined = v1.binding().combineWith(v2.binding());
if ( combined.isInvalid() ) continue;
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileRegistry.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileRegistry.java
index 0363b50815b..eb7a6d19d91 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileRegistry.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileRegistry.java
@@ -62,7 +62,6 @@ public class QueryProfileRegistry extends ComponentRegistry<QueryProfile> {
int slashIndex=id.getName().lastIndexOf("/");
if (slashIndex<1) return null;
String parentName=id.getName().substring(0,slashIndex);
- if (parentName.equals("")) return null;
ComponentSpecification parentId=new ComponentSpecification(parentName,id.getVersionSpecification());
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 8dedda800ea..4c4d6778d86 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
@@ -30,7 +30,7 @@ public class QueryProfileVariants implements Freezable, Cloneable {
private Map<String,FieldValues> fieldValuesByName = new HashMap<>();
/** The inherited profiles for various dimensions settings - a set of fieldvalues of List&lt;QueryProfile&gt; */
- private FieldValues inheritedProfiles =new FieldValues();
+ private FieldValues inheritedProfiles = new FieldValues();
/**
* Field and inherited profiles sorted by specificity used for all-value visiting.
@@ -105,10 +105,14 @@ public class QueryProfileVariants implements Freezable, Cloneable {
if (contentName != null) {
if (type != null)
contentName = type.unalias(contentName);
+ //System.out.println(" accepting single value in " + this + " for local key " + contentName);
acceptSingleValue(contentName, allowContent, visitor, dimensionBinding); // Special cased for performance
+ //System.out.println(" done accepting single value in " + this + " for local key " + contentName);
}
else {
+ //System.out.println(" accepting all values in " + this);
acceptAllValues(allowContent, visitor, type, dimensionBinding);
+ //System.out.println(" done accepting all values in " + this);
}
}
@@ -144,7 +148,7 @@ public class QueryProfileVariants implements Freezable, Cloneable {
if (visitor.isDone()) return;
fieldIndex++;
}
- else if (inheritedProfileValue != null) { // Inherited is most specific at this point
+ else { // Inherited is most specific at this point
if (inheritedProfileValue.matches(dimensionBinding.getValues())) {
@SuppressWarnings("unchecked")
List<QueryProfile> inheritedProfileList = (List<QueryProfile>)inheritedProfileValue.getValue();
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java
index 20e1370d29d..06434da2478 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java
@@ -3,7 +3,6 @@ package com.yahoo.search.query.profile.config.test;
import com.yahoo.jdisc.http.HttpRequest.Method;
import com.yahoo.container.jdisc.HttpRequest;
-import com.yahoo.processing.execution.Execution;
import com.yahoo.processing.request.CompoundName;
import com.yahoo.yolean.Exceptions;
import com.yahoo.search.Query;
@@ -15,7 +14,6 @@ import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
import com.yahoo.search.query.profile.config.QueryProfileXMLReader;
import com.yahoo.search.query.profile.types.FieldDescription;
import com.yahoo.search.query.profile.types.QueryProfileType;
-import org.junit.Ignore;
import org.junit.Test;
import java.util.HashMap;
@@ -32,18 +30,6 @@ import static org.junit.Assert.fail;
*/
public class XmlReadingTestCase {
- @Ignore
- @Test
- public void testTmp() {
- QueryProfileRegistry registry =
- new QueryProfileXMLReader().read("/Users/bratseth/development/slingstone/massmedia_serving/homerun/src/main/application/search/flattened");
-
- long startTime = System.currentTimeMillis();
- System.out.println("Compiling ...");
- CompiledQueryProfileRegistry cRegistry = registry.compile();
- System.out.println("Done in " + ((System.currentTimeMillis() - startTime) / 1000) + " seconds");
- }
-
@Test
public void testValid() {
QueryProfileRegistry registry=