use of com.yahoo.search.query.profile.QueryProfileProperties in project vespa by vespa-engine.
the class QueryProfileTypeTestCase method testTypedOfPrimitivesAssignmentNonStrict.
public void testTypedOfPrimitivesAssignmentNonStrict() {
QueryProfile profile = new QueryProfile("test");
profile.setType(type);
registry.register(profile);
profile.set("myString", "anyValue", registry);
// legal because this is not strict
profile.set("nontypedString", "anyValueToo", registry);
assertWrongType(profile, "integer", "myInteger", "notInteger");
assertWrongType(profile, "integer", "myInteger", "1.5");
profile.set("myInteger", 3, registry);
assertWrongType(profile, "long", "myLong", "notLong");
assertWrongType(profile, "long", "myLong", "1.5");
profile.set("myLong", 4000000000000l, registry);
assertWrongType(profile, "float", "myFloat", "notFloat");
profile.set("myFloat", 3.14f, registry);
assertWrongType(profile, "double", "myDouble", "notDouble");
profile.set("myDouble", 2.18, registry);
profile.set("myBoolean", true, registry);
String tensorString1 = "{{a:a1, b:b1}:1.0, {a:a2, b:b1}:2.0}}";
profile.set("ranking.features.query(myTensor1)", tensorString1, registry);
String tensorString2 = "{{x:0, y:0}:1.0, {x:0, y:1}:2.0}}";
profile.set("ranking.features.query(myTensor2)", tensorString2, registry);
String tensorString3 = "{{x:x1}:1.0, {x:x2}:2.0}}";
profile.set("ranking.features.query(myTensor3)", tensorString3, registry);
// TODO
profile.set("myQuery", "...", registry);
profile.set("myQueryProfile.anyString", "value1", registry);
profile.set("myQueryProfile.anyDouble", 8.76, registry);
profile.set("myUserQueryProfile.myUserString", "value2", registry);
// Legal because user is not strict
profile.set("myUserQueryProfile.anyString", "value3", registry);
assertWrongType(profile, "integer", "myUserQueryProfile.myUserInteger", "notInteger");
// Set using alias
profile.set("myUserQueryProfile.uint", 1337, registry);
// Legal because user is not strict
profile.set("myUserQueryProfile.anyDouble", 9.13, registry);
CompiledQueryProfileRegistry cRegistry = registry.compile();
QueryProfileProperties properties = new QueryProfileProperties(cRegistry.findQueryProfile("test"));
assertEquals("anyValue", properties.get("myString"));
assertEquals("anyValueToo", properties.get("nontypedString"));
assertEquals(3, properties.get("myInteger"));
assertEquals(3, properties.get("Int"));
assertEquals(4000000000000l, properties.get("myLong"));
assertEquals(3.14f, properties.get("myFloat"));
assertEquals(2.18, properties.get("myDouble"));
assertEquals(true, properties.get("myBoolean"));
assertEquals(Tensor.from(tensorString1), properties.get("ranking.features.query(myTensor1)"));
assertEquals(Tensor.from("tensor(x[2],y[2])", tensorString2), properties.get("ranking.features.query(myTensor2)"));
assertEquals(Tensor.from("tensor(x{})", tensorString3), properties.get("ranking.features.query(myTensor3)"));
// TODO: assertEquals(..., cprofile.get("myQuery"));
assertEquals("value1", properties.get("myQueryProfile.anyString"));
assertEquals("value1", properties.get("QP.anyString"));
assertEquals(8.76, properties.get("myQueryProfile.anyDouble"));
assertEquals(8.76, properties.get("qp.anyDouble"));
assertEquals("value2", properties.get("myUserQueryProfile.myUserString"));
assertEquals("value3", properties.get("myUserQueryProfile.anyString"));
assertEquals(1337, properties.get("myUserQueryProfile.myUserInteger"));
assertEquals(1337, properties.get("myUserQueryProfile.uint"));
assertEquals(9.13, properties.get("myUserQueryProfile.anyDouble"));
assertNull(properties.get("nonExisting"));
properties.set("INt", 51);
assertEquals(51, properties.get("InT"));
assertEquals(51, properties.get("myInteger"));
}
use of com.yahoo.search.query.profile.QueryProfileProperties in project vespa by vespa-engine.
the class Query method init.
private void init(Map<String, String> requestMap, CompiledQueryProfile queryProfile) {
startTime = System.currentTimeMillis();
if (queryProfile != null) {
// Move all request parameters to the query profile just to validate that the parameter settings are legal
Properties queryProfileProperties = new QueryProfileProperties(queryProfile);
properties().chain(queryProfileProperties);
// TODO: Just checking legality rather than actually setting would be faster
// Adds errors to the query for illegal set attempts
setPropertiesFromRequestMap(requestMap, properties());
// Create the full chain
properties().chain(new QueryProperties(this, queryProfile.getRegistry())).chain(new ModelObjectMap()).chain(new RequestContextProperties(requestMap)).chain(queryProfileProperties).chain(new DefaultProperties());
// Pass the values from the query profile which maps through a field in the Query object model
// through the property chain to cause those values to be set in the Query object model
setFieldsFrom(queryProfileProperties, requestMap);
} else {
// bypass these complications if there is no query profile to get values from and validate against
properties().chain(new QueryProperties(this, CompiledQueryProfileRegistry.empty)).chain(new PropertyMap()).chain(new DefaultProperties());
setPropertiesFromRequestMap(requestMap, properties());
}
properties().setParentQuery(this);
traceProperties();
}
use of com.yahoo.search.query.profile.QueryProfileProperties in project vespa by vespa-engine.
the class Query method validate.
/**
* Validates this query
*
* @return the reason if it is invalid, null if it is valid
*/
public String validate() {
// Validate the query profile
QueryProfileProperties queryProfileProperties = properties().getInstance(QueryProfileProperties.class);
// Valid
if (queryProfileProperties == null)
return null;
StringBuilder missingName = new StringBuilder();
if (!queryProfileProperties.isComplete(missingName, httpRequest.propertyMap()))
return "Incomplete query: Parameter '" + missingName + "' is mandatory in " + queryProfileProperties.getQueryProfile() + " but is not set";
else
// is valid
return null;
}
use of com.yahoo.search.query.profile.QueryProfileProperties in project vespa by vespa-engine.
the class Query method traceProperties.
/**
* Traces how properties was resolved and from where. Done after the fact to avoid special handling
* of tracelevel, which is the property deciding whether this needs to be done
*/
private void traceProperties() {
if (traceLevel == 0)
return;
CompiledQueryProfile profile = null;
QueryProfileProperties profileProperties = properties().getInstance(QueryProfileProperties.class);
if (profileProperties != null)
profile = profileProperties.getQueryProfile();
if (profile == null)
trace("No query profile is used", false, 1);
else
trace("Using " + profile.toString(), false, 1);
if (traceLevel < 4)
return;
StringBuilder b = new StringBuilder("Resolved properties:\n");
Set<String> mentioned = new HashSet<>();
for (Map.Entry<String, String> requestProperty : requestProperties().entrySet()) {
Object resolvedValue = properties().get(requestProperty.getKey(), requestProperties());
if (resolvedValue == null && requestProperty.getKey().equals("queryProfile"))
resolvedValue = requestProperty.getValue();
b.append(requestProperty.getKey());
b.append("=");
// (may be null)
b.append(String.valueOf(resolvedValue));
b.append(" (");
if (profile != null && !profile.isOverridable(new CompoundName(requestProperty.getKey()), requestProperties()))
b.append("value from query profile - unoverridable, ignoring request value");
else
b.append("value from request");
b.append(")\n");
mentioned.add(requestProperty.getKey());
}
if (profile != null) {
appendQueryProfileProperties(profile, mentioned, b);
}
trace(b.toString(), false, 4);
}
use of com.yahoo.search.query.profile.QueryProfileProperties in project vespa by vespa-engine.
the class QueryProfileTestCase method testSettingNonLeaf1.
public void testSettingNonLeaf1() {
QueryProfile p = new QueryProfile("test");
p.set("a", "a-value", (QueryProfileRegistry) null);
p.set("a.b", "a.b-value", (QueryProfileRegistry) null);
QueryProfileProperties cp = new QueryProfileProperties(p.compile(null));
assertEquals("a-value", cp.get("a"));
assertEquals("a.b-value", cp.get("a.b"));
}
Aggregations