use of com.yahoo.search.query.profile.types.FieldDescription in project vespa by vespa-engine.
the class QueryProfileProperties method set.
/**
* Sets a value in this query profile
*
* @throws IllegalArgumentException if this property cannot be set in the wrapped query profile
*/
@Override
public void set(CompoundName name, Object value, Map<String, String> context) {
// TODO: Refactor
try {
name = unalias(name, context);
if (context == null)
context = Collections.emptyMap();
if (!profile.isOverridable(name, context))
return;
// Check runtime references
Pair<CompoundName, CompiledQueryProfile> runtimeReference = findReference(name);
if (runtimeReference != null && !runtimeReference.getSecond().isOverridable(name.rest(runtimeReference.getFirst().size()), context))
return;
// Check types
if (!profile.getTypes().isEmpty()) {
for (int i = 0; i < name.size(); i++) {
QueryProfileType type = profile.getType(name.first(i), context);
if (type == null)
continue;
String localName = name.get(i);
FieldDescription fieldDescription = type.getField(localName);
if (fieldDescription == null && type.isStrict())
throw new IllegalArgumentException("'" + localName + "' is not declared in " + type + ", and the type is strict");
if (i == name.size() - 1 && fieldDescription != null) {
// at the end of the path, check the assignment type
value = fieldDescription.getType().convertFrom(value, profile.getRegistry());
if (value == null)
throw new IllegalArgumentException("'" + value + "' is not a " + fieldDescription.getType().toInstanceDescription());
}
}
}
if (value instanceof String && value.toString().startsWith("ref:")) {
if (profile.getRegistry() == null)
throw new IllegalArgumentException("Runtime query profile references does not work when the " + "QueryProfileProperties are constructed without a registry");
String queryProfileId = value.toString().substring(4);
value = profile.getRegistry().findQueryProfile(queryProfileId);
if (value == null)
throw new IllegalArgumentException("Query profile '" + queryProfileId + "' is not found");
}
if (value instanceof CompiledQueryProfile) {
// this will be due to one of the two clauses above
if (references == null)
references = new ArrayList<>();
// references set later has precedence - put first
references.add(0, new Pair<>(name, (CompiledQueryProfile) value));
} else {
if (values == null)
values = new HashMap<>();
values.put(name, value);
}
} catch (IllegalArgumentException e) {
// TODO: Nest instead
throw new IllegalArgumentException("Could not set '" + name + "' to '" + value + "': " + e.getMessage());
}
}
use of com.yahoo.search.query.profile.types.FieldDescription in project vespa by vespa-engine.
the class RankingExpressionShadowingTestCase method queryProfileWith.
private QueryProfileRegistry queryProfileWith(String field, String type) {
QueryProfileType queryProfileType = new QueryProfileType("root");
queryProfileType.addField(new FieldDescription(field, type));
QueryProfileRegistry queryProfileRegistry = new QueryProfileRegistry();
queryProfileRegistry.getTypeRegistry().register(queryProfileType);
QueryProfile profile = new QueryProfile("default");
profile.setType(queryProfileType);
queryProfileRegistry.register(profile);
return queryProfileRegistry;
}
use of com.yahoo.search.query.profile.types.FieldDescription in project vespa by vespa-engine.
the class OverrideTestCase method addTypeFields.
private void addTypeFields(QueryProfileType type) {
boolean overridable = true;
type.addField(new FieldDescription("myString", FieldType.fromString("string", registry), false, !overridable));
type.addField(new FieldDescription("myInteger", FieldType.fromString("integer", registry)));
type.addField(new FieldDescription("myLong", FieldType.fromString("long", registry)));
type.addField(new FieldDescription("myFloat", FieldType.fromString("float", registry)));
type.addField(new FieldDescription("myDouble", FieldType.fromString("double", registry)));
type.addField(new FieldDescription("myQueryProfile", FieldType.fromString("query-profile", registry)));
type.addField(new FieldDescription("myUserQueryProfile", FieldType.fromString("query-profile:user", registry), false, !overridable));
}
use of com.yahoo.search.query.profile.types.FieldDescription in project vespa by vespa-engine.
the class QueryProfileTypeInheritanceTestCase method setUp.
@Override
protected void setUp() {
type = new QueryProfileType(new ComponentId("testtype"));
typeStrict = new QueryProfileType(new ComponentId("testtypeStrict"));
typeStrict.setStrict(true);
user = new QueryProfileType(new ComponentId("user"));
userStrict = new QueryProfileType(new ComponentId("userStrict"));
userStrict.setStrict(true);
registry = new QueryProfileTypeRegistry();
registry.register(type);
registry.register(typeStrict);
registry.register(user);
registry.register(userStrict);
addTypeFields(type);
type.addField(new FieldDescription("myUserQueryProfile", FieldType.fromString("query-profile:user", registry)));
addTypeFields(typeStrict);
typeStrict.addField(new FieldDescription("myUserQueryProfile", FieldType.fromString("query-profile:userStrict", registry)));
addUserFields(user);
addUserFields(userStrict);
}
use of com.yahoo.search.query.profile.types.FieldDescription in project vespa by vespa-engine.
the class QueryProfileTypeInheritanceTestCase method addTypeFields.
private void addTypeFields(QueryProfileType type) {
type.addField(new FieldDescription("myString", FieldType.fromString("string", registry)));
type.addField(new FieldDescription("myInteger", FieldType.fromString("integer", registry)));
type.addField(new FieldDescription("myLong", FieldType.fromString("long", registry)));
type.addField(new FieldDescription("myFloat", FieldType.fromString("float", registry)));
type.addField(new FieldDescription("myDouble", FieldType.fromString("double", registry)));
type.addField(new FieldDescription("myQueryProfile", FieldType.fromString("query-profile", registry)));
}
Aggregations