diff options
Diffstat (limited to 'container-search/src')
8 files changed, 80 insertions, 17 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java b/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java index 6886b53e1d4..f27500085e1 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java @@ -43,7 +43,9 @@ final class AllValuesQueryProfileVisitor extends PrefixQueryProfileVisitor { if (fullName.isEmpty()) return; // Avoid putting a non-leaf (subtree) root in the list if (values.containsKey(fullName.toString())) return; // The first value encountered has priority - values.put(fullName.toString(), new ValueWithSource(value, owner.getSource(), variant)); + values.put(fullName.toString(), new ValueWithSource(value, + owner == null ? "anonymous" : owner.getSource(), + variant)); } /** Returns the values resulting from this visiting */ diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/BackedOverridableQueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/BackedOverridableQueryProfile.java index e6af1311bc3..99f1e26b221 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/BackedOverridableQueryProfile.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/BackedOverridableQueryProfile.java @@ -33,10 +33,13 @@ public class BackedOverridableQueryProfile extends OverridableQueryProfile imple public BackedOverridableQueryProfile(QueryProfile backingProfile) { Validator.ensureNotNull("An overridable query profile must be backed by a real query profile",backingProfile); setType(backingProfile.getType()); - this.backingProfile=backingProfile; + this.backingProfile = backingProfile; } @Override + public String getSource() { return backingProfile.getSource(); } + + @Override public synchronized void freeze() { super.freeze(); backingProfile.freeze(); diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java b/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java index b70474371d4..9eb50c0f72e 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * An immutable set of dimension values. @@ -104,7 +105,9 @@ public class DimensionValues implements Comparable<DimensionValues> { } @Override - public String toString() { return Arrays.toString(values); } + public String toString() { + return "[" + Arrays.stream(values).map(value -> value == null ? "*" : value).collect(Collectors.joining(", ")) + "]"; + } public boolean isEmpty() { return this==empty; diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/OverridableQueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/OverridableQueryProfile.java index 325c85ac491..37940b813dc 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/OverridableQueryProfile.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/OverridableQueryProfile.java @@ -17,7 +17,11 @@ public class OverridableQueryProfile extends QueryProfile { /** Creates an unbacked overridable query profile */ protected OverridableQueryProfile() { - super(ComponentId.createAnonymousComponentId(simpleClassName)); + this(""); + } + + protected OverridableQueryProfile(String sourceName) { + super(ComponentId.createAnonymousComponentId(simpleClassName), sourceName); } @Override @@ -31,7 +35,7 @@ public class OverridableQueryProfile extends QueryProfile { @Override protected QueryProfile createSubProfile(String name, DimensionBinding binding) { - return new OverridableQueryProfile(); // Nothing is set in this branch, so nothing to override, but need override checking + return new OverridableQueryProfile(getSource()); // Nothing is set in this branch, so nothing to override, but need override checking } /** Returns a clone of this which can be independently overridden */ diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java index 79426cbce3a..925d20903c6 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java @@ -15,23 +15,23 @@ public class ValueWithSource { private final Object value; /** The source of the query profile having a value */ - private final String ownerSource; + private final String source; /** The dimension values specifying a variant in that profile, or null if it is not in a variant */ private final DimensionValues variant; - public ValueWithSource(Object value, String ownerSource, DimensionValues variant) { + public ValueWithSource(Object value, String source, DimensionValues variant) { this.value = value; - this.ownerSource = ownerSource; + this.source = source; this.variant = variant; } public Object value() { return value; } - public String ownerSource() { return ownerSource; } + public String source() { return source; } public ValueWithSource withValue(Object value) { - return new ValueWithSource(value, ownerSource, variant); + return new ValueWithSource(value, source, variant); } /** Returns the variant having this value, or empty if it's not in a variant */ @@ -40,7 +40,7 @@ public class ValueWithSource { @Override public String toString() { return value + - " (from query profile '" + ownerSource + "'" + + " (from query profile '" + source + "'" + ( variant != null ? " variant " + variant : "") + ")"; } diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java index 5e2e018f375..46efb736918 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java @@ -3,16 +3,19 @@ package com.yahoo.search.query.profile.test; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.processing.request.CompoundName; import com.yahoo.processing.request.Properties; import com.yahoo.search.Query; 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.ValueWithSource; import com.yahoo.yolean.trace.TraceNode; import org.junit.Test; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -500,9 +503,32 @@ public class QueryProfileTestCase { QueryProfile p = new QueryProfile("test"); p.set("a","a-value", null); p.set("a.b","a.b-value", null); - Map<String,Object> values = p.compile(null).listValues("a"); - assertEquals(1,values.size()); - assertEquals("a.b-value",values.get("b")); + Map<String, Object> values = p.compile(null).listValues("a"); + assertEquals(1, values.size()); + assertEquals("a.b-value", values.get("b")); + } + + @Test + public void testListingSources() { + QueryProfile p = new QueryProfile("test"); + p.set("a","a-value", null); + p.set("a.b","a.b-value", null); + + { + Map<String, ValueWithSource> values = p.compile(null).listValuesWithSources(new CompoundName(""), new HashMap<>(), null); + assertEquals(2, values.size()); + assertEquals("a-value", values.get("a").value()); + assertEquals("test", values.get("a").source()); + assertEquals("a.b-value", values.get("a.b").value()); + assertEquals("test", values.get("a.b").source()); + } + + { + Map<String, ValueWithSource> values = p.compile(null).listValuesWithSources(new CompoundName("a"), new HashMap<>(), null); + assertEquals(1, values.size()); + assertEquals("a.b-value", values.get("b").value()); + assertEquals("test", values.get("b").source()); + } } @Test diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsCloneTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsCloneTestCase.java index 84326d9370d..aa1d1c243a0 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsCloneTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsCloneTestCase.java @@ -18,9 +18,6 @@ import static org.junit.Assert.assertEquals; */ public class QueryProfileVariantsCloneTestCase { - /** - * Test for Ticket 4882480. - */ @Test public void test_that_interior_and_leaf_values_on_a_path_are_preserved_when_cloning() { Map<String, String> dimensionBinding = createDimensionBinding("location", "norway"); 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 b4112b17c92..73b455c147b 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 @@ -3,6 +3,7 @@ package com.yahoo.search.query.profile.test; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.processing.request.CompoundName; import com.yahoo.search.Query; import com.yahoo.search.query.Properties; import com.yahoo.search.query.profile.BackedOverridableQueryProfile; @@ -11,6 +12,7 @@ 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.search.query.profile.compiled.ValueWithSource; import com.yahoo.yolean.trace.TraceNode; import org.junit.Test; @@ -93,6 +95,32 @@ public class QueryProfileVariantsTestCase { 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")); + + { + Map<String, ValueWithSource> values = cRegistry.findQueryProfile("test") + .listValuesWithSources(new CompoundName(""), + new HashMap<>(), + null); + assertEquals(1, values.size()); + assertEquals("default_value", values.get("feed.main.streams").value()); + assertEquals("referenced", values.get("feed.main.streams").source()); + assertTrue(values.get("feed.main.streams").variant().isEmpty()); + } + + { + Map<String, ValueWithSource> values = cRegistry.findQueryProfile("test") + .listValuesWithSources(new CompoundName(""), + toMap("x=x1", "y=y1", "z=z1"), + null); + assertEquals(2, values.size()); + assertEquals("variant_value", values.get("feed.main.streams").value()); + assertEquals("referenced", values.get("feed.main.streams").source()); + assertEquals("[x1, *, z1]", values.get("feed.main.streams").variant().get().toString()); + + assertEquals("otherValue", values.get("other").value()); + assertEquals("parent", values.get("other").source()); + assertEquals("[x1, y1]", values.get("other").variant().get().toString()); + } } @Test |