use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryProfileTestCase method testGetSubObjects.
public void testGetSubObjects() {
QueryProfile barn = new QueryProfile("barn");
QueryProfile mor = new QueryProfile("mor");
QueryProfile far = new QueryProfile("far");
QueryProfile mormor = new QueryProfile("mormor");
QueryProfile morfar = new QueryProfile("morfar");
QueryProfile farfar = new QueryProfile("farfar");
mor.addInherited(mormor);
mor.addInherited(morfar);
far.addInherited(farfar);
barn.addInherited(mor);
barn.addInherited(far);
mormor.set("a.mormor", "a.mormor", (QueryProfileRegistry) null);
barn.set("a.barn", "a.barn", (QueryProfileRegistry) null);
mor.set("b.mor", "b.mor", (QueryProfileRegistry) null);
far.set("b.far", "b.far", (QueryProfileRegistry) null);
far.set("a.far", "a.far", (QueryProfileRegistry) null);
CompiledQueryProfile cbarn = barn.compile(null);
assertSameObjects(cbarn, "a", Arrays.asList("mormor", "far", "barn"));
assertEquals("b.mor", cbarn.get("b.mor"));
assertEquals("b.far", cbarn.get("b.far"));
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryProfileTestCase method testQueryProfileInlineValueReassignmentSimpleNameGenericProperty.
public void testQueryProfileInlineValueReassignmentSimpleNameGenericProperty() {
QueryProfile p = new QueryProfile("test");
p.set("key", "%{value}", (QueryProfileRegistry) null);
p.freeze();
Query q = new Query(HttpRequest.createTestRequest("?query=test&value=foo", Method.GET), p.compile(null));
assertEquals("foo", q.properties().get("key"));
assertEquals("foo", q.properties().listProperties().get("key"));
q.properties().set("value", "bar");
assertEquals("bar", q.properties().get("key"));
assertEquals("bar", q.properties().listProperties().get("key"));
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryProfileVariantsTestCase method testRuntimeAssignmentInClone.
public void testRuntimeAssignmentInClone() {
QueryProfile test = new QueryProfile("test");
test.setDimensions(new String[] { "x" });
String[] x1 = new String[] { "x1" };
Map<String, String> x1m = toMap(test, x1);
test.set("a", "30", x1, null);
test.set("a.b", "20", x1, null);
test.set("a.b.c", "10", x1, null);
// Setting in one profile works
Query qMain = new Query(HttpRequest.createTestRequest("?query=test", Method.GET), test.compile(null));
qMain.properties().set("a.b", "50", x1m);
assertEquals("50", qMain.properties().get("a.b", x1m));
// Cloning
Query qBranch = qMain.clone();
// Setting in main still works
qMain.properties().set("a.b", "51", x1m);
assertEquals("51", qMain.properties().get("a.b", x1m));
// Clone is not affected by change in original
assertEquals("50", qBranch.properties().get("a.b", x1m));
// Setting in clone works
qBranch.properties().set("a.b", "70", x1m);
assertEquals("70", qBranch.properties().get("a.b", x1m));
// Setting in clone does not affect original
assertEquals("51", qMain.properties().get("a.b", x1m));
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryProfileVariantsTestCase method testListVariantPropertiesCompounds1.
public void testListVariantPropertiesCompounds1() {
QueryProfile parent1 = new QueryProfile("parent1");
// Defined everywhere
parent1.set("a.p1", "parent1-a", (QueryProfileRegistry) null);
// Defined everywhere, but no variants
parent1.set("b.p1", "parent1-b", (QueryProfileRegistry) null);
// Defined in both parents only
parent1.set("c.p1", "parent1-c", (QueryProfileRegistry) null);
QueryProfile parent2 = new QueryProfile("parent2");
parent2.set("a.p1", "parent2-a", (QueryProfileRegistry) null);
parent2.set("b.p1", "parent2-b", (QueryProfileRegistry) null);
parent2.set("c.p1", "parent2-c", (QueryProfileRegistry) null);
// Defined in second parent only
parent2.set("d.p1", "parent2-d", (QueryProfileRegistry) null);
QueryProfile main = new QueryProfile("main");
main.setDimensions(new String[] { "x", "y" });
main.addInherited(parent1);
main.addInherited(parent2);
main.set("a.p1", "main-a", (QueryProfileRegistry) null);
main.set("a.p1", "main-a-x1", new String[] { "x1" }, null);
// Defined in two variants only
main.set("e.p1", "main-e-x1", new String[] { "x1" }, null);
// Defined in one variants only
main.set("f.p1", "main-f-x1", new String[] { "x1" }, null);
main.set("a.p1", "main-a-x1.y1", new String[] { "x1", "y1" }, null);
main.set("a.p1", "main-a-x1.y2", new String[] { "x1", "y2" }, null);
main.set("e.p1", "main-e-x1.y2", new String[] { "x1", "y2" }, null);
// Defined in one variant only
main.set("g.p1", "main-g-x1.y2", new String[] { "x1", "y2" }, null);
main.set("b.p1", "main-b", (QueryProfileRegistry) null);
QueryProfile inheritedVariant1 = new QueryProfile("inheritedVariant1");
inheritedVariant1.set("a.p1", "inheritedVariant1-a", (QueryProfileRegistry) null);
// Only defined in two inherited variants
inheritedVariant1.set("h.p1", "inheritedVariant1-h", (QueryProfileRegistry) null);
QueryProfile inheritedVariant2 = new QueryProfile("inheritedVariant2");
inheritedVariant2.set("a.p1", "inheritedVariant2-a", (QueryProfileRegistry) null);
// Only defined in two inherited variants
inheritedVariant2.set("h.p1", "inheritedVariant2-h", (QueryProfileRegistry) null);
// Only defined in one inherited variant
inheritedVariant2.set("i.p1", "inheritedVariant2-i", (QueryProfileRegistry) null);
QueryProfile inheritedVariant3 = new QueryProfile("inheritedVariant3");
// Only defined in one inherited variant, but inherited twice
inheritedVariant3.set("j.p1", "inheritedVariant3-j", (QueryProfileRegistry) null);
main.addInherited(inheritedVariant1, new String[] { "x1" });
main.addInherited(inheritedVariant3, new String[] { "x1" });
main.addInherited(inheritedVariant2, new String[] { "x1", "y2" });
main.addInherited(inheritedVariant3, new String[] { "x1", "y2" });
Properties properties = new QueryProfileProperties(main.compile(null));
int expectedBaseSize = 4;
// No context
Map<String, Object> listed = properties.listProperties();
assertEquals(expectedBaseSize, listed.size());
assertEquals("main-a", listed.get("a.p1"));
assertEquals("main-b", listed.get("b.p1"));
assertEquals("parent1-c", listed.get("c.p1"));
assertEquals("parent2-d", listed.get("d.p1"));
// Context x=x1
listed = properties.listProperties(toMap(main, new String[] { "x1" }));
assertEquals(expectedBaseSize + 4, listed.size());
assertEquals("main-a-x1", listed.get("a.p1"));
assertEquals("main-b", listed.get("b.p1"));
assertEquals("parent1-c", listed.get("c.p1"));
assertEquals("parent2-d", listed.get("d.p1"));
assertEquals("main-e-x1", listed.get("e.p1"));
assertEquals("main-f-x1", listed.get("f.p1"));
assertEquals("inheritedVariant1-h", listed.get("h.p1"));
assertEquals("inheritedVariant3-j", listed.get("j.p1"));
// Context x=x1,y=y1
listed = properties.listProperties(toMap(main, new String[] { "x1", "y1" }));
assertEquals(expectedBaseSize + 4, listed.size());
assertEquals("main-a-x1.y1", listed.get("a.p1"));
assertEquals("main-b", listed.get("b.p1"));
assertEquals("parent1-c", listed.get("c.p1"));
assertEquals("parent2-d", listed.get("d.p1"));
assertEquals("main-e-x1", listed.get("e.p1"));
assertEquals("main-f-x1", listed.get("f.p1"));
assertEquals("inheritedVariant1-h", listed.get("h.p1"));
assertEquals("inheritedVariant3-j", listed.get("j.p1"));
// Context x=x1,y=y2
listed = properties.listProperties(toMap(main, new String[] { "x1", "y2" }));
assertEquals(expectedBaseSize + 6, listed.size());
assertEquals("main-a-x1.y2", listed.get("a.p1"));
assertEquals("main-b", listed.get("b.p1"));
assertEquals("parent1-c", listed.get("c.p1"));
assertEquals("parent2-d", listed.get("d.p1"));
assertEquals("main-e-x1.y2", listed.get("e.p1"));
assertEquals("main-f-x1", listed.get("f.p1"));
assertEquals("main-g-x1.y2", listed.get("g.p1"));
assertEquals("inheritedVariant2-h", listed.get("h.p1"));
assertEquals("inheritedVariant2-i", listed.get("i.p1"));
assertEquals("inheritedVariant3-j", listed.get("j.p1"));
// Context x=x1,y=y3
listed = properties.listProperties(toMap(main, new String[] { "x1", "y3" }));
assertEquals(expectedBaseSize + 4, listed.size());
assertEquals("main-a-x1", listed.get("a.p1"));
assertEquals("main-b", listed.get("b.p1"));
assertEquals("parent1-c", listed.get("c.p1"));
assertEquals("parent2-d", listed.get("d.p1"));
assertEquals("main-e-x1", listed.get("e.p1"));
assertEquals("main-f-x1", listed.get("f.p1"));
assertEquals("inheritedVariant1-h", listed.get("h.p1"));
assertEquals("inheritedVariant3-j", listed.get("j.p1"));
// Context x=x2,y=y1
listed = properties.listProperties(toMap(main, new String[] { "x2", "y1" }));
assertEquals(expectedBaseSize, listed.size());
assertEquals("main-a", listed.get("a.p1"));
assertEquals("main-b", listed.get("b.p1"));
assertEquals("parent1-c", listed.get("c.p1"));
assertEquals("parent2-d", listed.get("d.p1"));
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryProfileVariantsTestCase method testVariantInheritance.
public void testVariantInheritance() {
QueryProfile test = new QueryProfile("test");
test.setDimensions(new String[] { "x", "y" });
QueryProfile defaultParent = new QueryProfile("defaultParent");
defaultParent.set("a", "a-default", (QueryProfileRegistry) null);
QueryProfile x1Parent = new QueryProfile("x1Parent");
x1Parent.set("a", "a-x1", (QueryProfileRegistry) null);
x1Parent.set("d", "d-x1", (QueryProfileRegistry) null);
x1Parent.set("e", "e-x1", (QueryProfileRegistry) null);
QueryProfile x1y1Parent = new QueryProfile("x1y1Parent");
x1y1Parent.set("a", "a-x1y1", (QueryProfileRegistry) null);
QueryProfile x1y2Parent = new QueryProfile("x1y2Parent");
x1y2Parent.set("a", "a-x1y2", (QueryProfileRegistry) null);
x1y2Parent.set("b", "b-x1y2", (QueryProfileRegistry) null);
x1y2Parent.set("c", "c-x1y2", (QueryProfileRegistry) null);
test.addInherited(defaultParent);
test.addInherited(x1Parent, new String[] { "x1" });
test.addInherited(x1y1Parent, new String[] { "x1", "y1" });
test.addInherited(x1y2Parent, new String[] { "x1", "y2" });
test.set("c", "c-x1", new String[] { "x1" }, null);
test.set("e", "e-x1y2", new String[] { "x1", "y2" }, null);
CompiledQueryProfile ctest = test.compile(null);
assertEquals("a-default", ctest.get("a"));
assertEquals("a-x1", ctest.get("a", toMap("x=x1")));
assertEquals("a-x1y1", ctest.get("a", toMap("x=x1", "y=y1")));
assertEquals("a-x1y2", ctest.get("a", toMap("x=x1", "y=y2")));
assertEquals(null, ctest.get("b"));
assertEquals(null, ctest.get("b", toMap("x=x1")));
assertEquals(null, ctest.get("b", toMap("x=x1", "y=y1")));
assertEquals("b-x1y2", ctest.get("b", toMap("x=x1", "y=y2")));
assertEquals(null, ctest.get("c"));
assertEquals("c-x1", ctest.get("c", toMap("x=x1")));
assertEquals("c-x1", ctest.get("c", toMap("x=x1", "y=y1")));
assertEquals("c-x1y2", ctest.get("c", toMap("x=x1", "y=y2")));
assertEquals(null, ctest.get("d"));
assertEquals("d-x1", ctest.get("d", toMap("x=x1")));
assertEquals("d-x1", ctest.get("d", toMap("x=x1", "y=y1")));
assertEquals("d-x1", ctest.get("d", toMap("x=x1", "y=y2")));
assertEquals(null, ctest.get("d"));
assertEquals("e-x1", ctest.get("e", toMap("x=x1")));
assertEquals("e-x1", ctest.get("e", toMap("x=x1", "y=y1")));
assertEquals("e-x1y2", ctest.get("e", toMap("x=x1", "y=y2")));
}
Aggregations