summaryrefslogtreecommitdiffstats
path: root/container-search/src
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2019-10-27 21:46:07 +0100
committerJon Bratseth <bratseth@verizonmedia.com>2019-10-27 21:46:07 +0100
commit21b31f89dc40b7edb6d7542bd6091a206b9a3053 (patch)
treed235e962b31b3129829b7a88cfd1214155de3713 /container-search/src
parent4bc2dbc4e3ff6d5dd08db7b1bf17a28c34f291e2 (diff)
Generate combinations of variants found in all paths
Diffstat (limited to 'container-search/src')
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java34
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java26
2 files changed, 43 insertions, 17 deletions
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 fd2852fda60..60be7e2b74b 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
@@ -7,12 +7,9 @@ import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
import com.yahoo.search.query.profile.compiled.DimensionalMap;
import com.yahoo.search.query.profile.types.QueryProfileType;
-import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
-import java.util.Optional;
import java.util.Set;
-import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -38,6 +35,7 @@ public class QueryProfileCompiler {
DimensionalMap.Builder<CompoundName, QueryProfileType> types = new DimensionalMap.Builder<>();
DimensionalMap.Builder<CompoundName, Object> references = new DimensionalMap.Builder<>();
DimensionalMap.Builder<CompoundName, Object> unoverridables = new DimensionalMap.Builder<>();
+ System.out.println("Compiling " + in.toString());
// Resolve values for each existing variant and combine into a single data structure
Set<DimensionBindingForPath> variants = collectVariants(CompoundName.empty, in, DimensionBinding.nullBinding);
@@ -45,6 +43,7 @@ public class QueryProfileCompiler {
log.fine(() -> "Compiling " + in.toString() + " having " + variants.size() + " variants");
for (DimensionBindingForPath variant : variants) {
log.finer(() -> " Compiling variant " + variant);
+ System.out.println(" Compiling variant " + variant);
for (Map.Entry<String, Object> entry : in.listValues(variant.path(), variant.binding().getContext(), null).entrySet()) {
values.put(variant.path().append(entry.getKey()), variant.binding(), entry.getValue());
}
@@ -85,12 +84,12 @@ public class QueryProfileCompiler {
variants.addAll(combined(variants, parentVariants)); // parents and children may have different variant dimensions
}
- variants.addAll(leftExpanded(variants));
+ variants.addAll(wildcardExpanded(variants));
return variants;
}
/**
- * For variants which are underspecified on the left we must explicitly resolve each possible combination
+ * For variants which are underspecified we must explicitly resolve each possible combination
* of actual left-side values.
*
* I.e if we have the variants [-,b=b1], [a=a1,-], [a=a2,-],
@@ -100,16 +99,16 @@ public class QueryProfileCompiler {
* lead us to the compiled profile [a=a1,-], which may contain default values for properties where
* we should have preferred variant values in [-,b=b1].
*/
- private static Set<DimensionBindingForPath> leftExpanded(Set<DimensionBindingForPath> variants) {
+ private static Set<DimensionBindingForPath> wildcardExpanded(Set<DimensionBindingForPath> variants) {
Set<DimensionBindingForPath> expanded = new HashSet<>();
for (var variant : variants) {
- if (hasLeftWildcard(variant.binding()))
- expanded.addAll(leftExpanded(variant, variants));
+ if (hasWildcardBeforeEnd(variant.binding()))
+ expanded.addAll(wildcardExpanded(variant, variants));
}
return expanded;
}
- private static boolean hasLeftWildcard(DimensionBinding variant) {
+ private static boolean hasWildcardBeforeEnd(DimensionBinding variant) {
for (int i = 0; i < variant.getValues().size() - 1; i++) { // -1 to not check the rightmost
if (variant.getValues().get(i) == null)
return true;
@@ -117,15 +116,15 @@ public class QueryProfileCompiler {
return false;
}
- private static Set<DimensionBindingForPath> leftExpanded(DimensionBindingForPath variantToExpand,
- Set<DimensionBindingForPath> variants) {
+ private static Set<DimensionBindingForPath> wildcardExpanded(DimensionBindingForPath variantToExpand,
+ Set<DimensionBindingForPath> variants) {
Set<DimensionBindingForPath> expanded = new HashSet<>();
for (var variant : variants) {
- if ( ! variantToExpand.path().equals(variant.path())) continue;
-
- DimensionBinding combined = variantToExpand.binding().combineWith(variant.binding);
- if ( ! combined.isInvalid() )
+ if (variant.binding().isNull()) continue;
+ DimensionBinding combined = variantToExpand.binding().combineWith(variant.binding());
+ if ( ! combined.isInvalid() ) {
expanded.add(new DimensionBindingForPath(combined, variantToExpand.path()));
+ }
}
return expanded;
}
@@ -136,10 +135,11 @@ public class QueryProfileCompiler {
Set<DimensionBindingForPath> v2s) {
Set<DimensionBindingForPath> combinedVariants = new HashSet<>();
for (DimensionBindingForPath v1 : v1s) {
+ if (v1.binding().isNull()) continue;
for (DimensionBindingForPath v2 : v2s) {
- if ( ! v1.path().equals(v2.path())) continue;
+ if (v1.binding().isNull()) continue;
- DimensionBinding combined = v1.binding().combineWith(v2.binding);
+ DimensionBinding combined = v1.binding().combineWith(v2.binding());
if ( combined.isInvalid() ) continue;
combinedVariants.add(new DimensionBindingForPath(combined, v1.path()));
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 3da4558d67c..b4112b17c92 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
@@ -8,7 +8,9 @@ import com.yahoo.search.query.Properties;
import com.yahoo.search.query.profile.BackedOverridableQueryProfile;
import com.yahoo.search.query.profile.QueryProfile;
import com.yahoo.search.query.profile.QueryProfileProperties;
+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.yolean.trace.TraceNode;
import org.junit.Test;
@@ -70,6 +72,30 @@ public class QueryProfileVariantsTestCase {
}
@Test
+ public void testVariantInReferencedAndParentWithOtherMatchingVariant() {
+ QueryProfileRegistry registry = new QueryProfileRegistry();
+ QueryProfile parent = new QueryProfile("parent");
+ parent.setDimensions(new String[] { "x", "y" } );
+ parent.set("other", "otherValue", new String[] { "x1", "y1" }, registry );
+ QueryProfile profile = new QueryProfile("test");
+ profile.addInherited(parent);
+ QueryProfile referenced = new QueryProfile("referenced");
+ referenced.setDimensions(new String[] { "x", "y", "z" });
+ registry.register(parent);
+ registry.register(profile);
+ registry.register(referenced);
+ profile.set("feed.main", referenced, registry);
+ referenced.set("streams", "default_value", registry);
+ referenced.set("streams", "variant_value", new String[] { "x1", null, "z1" }, registry);
+
+ CompiledQueryProfileRegistry cRegistry = registry.compile();
+ CompiledQueryProfile cTest = cRegistry.findQueryProfile("test");
+
+ assertEquals("default_value", new Query("?", cTest).properties().get("feed.main.streams"));
+ assertEquals("variant_value", new Query("?x=x1&y=y1&z=z1", cTest).properties().get("feed.main.streams"));
+ }
+
+ @Test
public void testMultipleMatchingVariantsAndDefault() {
QueryProfile profile = new QueryProfile("test");
profile.setDimensions(new String[] { "a", "b" });