Search in sources :

Example 11 with CompoundName

use of com.yahoo.processing.request.CompoundName in project vespa by vespa-engine.

the class CompiledQueryProfile method listValues.

/**
 * Adds all objects that start with the given path prefix to the given value map. Use "" to list all.
 * <p>
 * For example, if {a.d =&gt; "a.d-value" ,a.e =&gt; "a.e-value", b.d =&gt; "b.d-value", then calling listValues("a")
 * will return {"d" =&gt; "a.d-value","e" =&gt; "a.e-value"}
 */
public Map<String, Object> listValues(CompoundName prefix, Map<String, String> context, Properties substitution) {
    Map<String, Object> values = new HashMap<>();
    for (Map.Entry<CompoundName, DimensionalValue<Object>> entry : entries.entrySet()) {
        if (entry.getKey().size() <= prefix.size())
            continue;
        if (!entry.getKey().hasPrefix(prefix))
            continue;
        Object value = entry.getValue().get(context);
        if (value == null)
            continue;
        value = substitute(value, context, substitution);
        CompoundName suffixName = entry.getKey().rest(prefix.size());
        values.put(suffixName.toString(), value);
    }
    return values;
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) HashMap(java.util.HashMap) SubstituteString(com.yahoo.search.query.profile.SubstituteString) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with CompoundName

use of com.yahoo.processing.request.CompoundName in project vespa by vespa-engine.

the class FederationSearcher method getProperty.

private Object getProperty(Query query, CompoundKey key) {
    CompoundName name = map.get(key);
    if (name == null) {
        name = new CompoundName(key.toString());
        map.put(key, name);
    }
    return query.properties().get(name);
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName)

Example 13 with CompoundName

use of com.yahoo.processing.request.CompoundName 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);
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) PropertyMap(com.yahoo.search.query.properties.PropertyMap) HashMap(java.util.HashMap) ModelObjectMap(com.yahoo.search.query.profile.ModelObjectMap) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties) HashSet(java.util.HashSet)

Example 14 with CompoundName

use of com.yahoo.processing.request.CompoundName in project vespa by vespa-engine.

the class QueryProfileType method addField.

/**
 * Adds a field to this
 *
 * @throws IllegalStateException if this is frozen
 */
public void addField(FieldDescription fieldDescription, QueryProfileTypeRegistry registry) {
    CompoundName name = fieldDescription.getCompoundName();
    if (name.isCompound()) {
        // Add (/to) a query profile type containing the rest of the name.
        // (we do not need the field description settings for intermediate query profile types
        // as the leaf entry will enforce them)
        QueryProfileType type = getOrCreateQueryProfileType(name.first(), registry);
        type.addField(fieldDescription.withName(name.rest()), registry);
    } else {
        ensureNotFrozen();
        fields.put(fieldDescription.getName(), fieldDescription);
    }
    for (String alias : fieldDescription.getAliases()) addAlias(alias, fieldDescription.getName());
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName)

Example 15 with CompoundName

use of com.yahoo.processing.request.CompoundName in project vespa by vespa-engine.

the class QueryProfileGetMicroBenchmark method getValues.

private void getValues(int count, Query query) {
    final int dotInterval = 10000000;
    CompoundName found = new CompoundName(propertyPrefix + "property1");
    CompoundName notFound = new CompoundName(propertyPrefix + "nonExisting");
    for (int i = 0; i < count; i++) {
        if (count > dotInterval && i % (count / dotInterval) == 0)
            System.out.print(".");
        if (null == query.properties().get(found))
            throw new RuntimeException("Expected value");
        if (null != query.properties().get(notFound))
            throw new RuntimeException("Expected no value");
    }
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName)

Aggregations

CompoundName (com.yahoo.processing.request.CompoundName)22 Test (org.junit.Test)7 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)6 HashMap (java.util.HashMap)6 Map (java.util.Map)5 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)4 PropertyMap (com.yahoo.processing.request.properties.PropertyMap)2 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)2 HashSet (java.util.HashSet)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 Request (com.yahoo.processing.Request)1 Properties (com.yahoo.processing.request.Properties)1 Query (com.yahoo.search.Query)1 ModelObjectMap (com.yahoo.search.query.profile.ModelObjectMap)1 QueryProfile (com.yahoo.search.query.profile.QueryProfile)1 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)1 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)1 SubstituteString (com.yahoo.search.query.profile.SubstituteString)1 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)1