Search in sources :

Example 6 with CompoundName

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

the class CompoundNameTestCase method testAppend.

@Test
public void testAppend() {
    assertEquals("a", new CompoundName("a").append("").toString());
    assertEquals("a", new CompoundName("").append("a").toString());
    assertEquals("a.b", new CompoundName("a").append("b").toString());
    CompoundName name = new CompoundName("a.b");
    assertEquals("a.b.c", name.append("c").toString());
    assertEquals("a.b.d", name.append("d").toString());
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) Test(org.junit.Test)

Example 7 with CompoundName

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

the class QueryProfileGetInComplexStructureMicroBenchmark method getValues.

private void getValues(int count, Query query) {
    Map<String, String> dimensionValues = createDimensionValueMap();
    String prefix = generatePrefix();
    final int dotInterval = 1000000;
    final CompoundName found = new CompoundName(prefix + "a");
    final CompoundName notFound = new CompoundName(prefix + "nonexisting");
    for (int i = 0; i < count; i++) {
        if (count > dotInterval && i % (dotInterval) == 0)
            System.out.print(".");
        if (// request the last variant for worst case
        null == query.properties().get(found, dimensionValues))
            throw new RuntimeException("Expected value");
        if (// request the last variant for worst case
        null != query.properties().get(notFound, dimensionValues))
            throw new RuntimeException("Did not expect value");
    }
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName)

Example 8 with CompoundName

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

the class QueryProfileCompiler method compile.

public static CompiledQueryProfile compile(QueryProfile in, CompiledQueryProfileRegistry registry) {
    DimensionalMap.Builder<CompoundName, Object> values = new DimensionalMap.Builder<>();
    DimensionalMap.Builder<CompoundName, QueryProfileType> types = new DimensionalMap.Builder<>();
    DimensionalMap.Builder<CompoundName, Object> references = new DimensionalMap.Builder<>();
    DimensionalMap.Builder<CompoundName, Object> unoverridables = new DimensionalMap.Builder<>();
    // Resolve values for each existing variant and combine into a single data structure
    Set<DimensionBindingForPath> variants = new HashSet<>();
    collectVariants(CompoundName.empty, in, DimensionBinding.nullBinding, variants);
    // if this contains no variants
    variants.add(new DimensionBindingForPath(DimensionBinding.nullBinding, CompoundName.empty));
    if (log.isLoggable(Level.FINE))
        log.fine("Compiling " + in.toString() + " having " + variants.size() + " variants");
    int i = 0;
    for (DimensionBindingForPath variant : variants) {
        if (log.isLoggable(Level.FINER))
            log.finer("    Compiling variant " + i++ + ": " + variant);
        for (Map.Entry<String, Object> entry : in.listValues(variant.path(), variant.binding().getContext(), null).entrySet()) values.put(variant.path().append(entry.getKey()), variant.binding(), entry.getValue());
        for (Map.Entry<CompoundName, QueryProfileType> entry : in.listTypes(variant.path(), variant.binding().getContext()).entrySet()) types.put(variant.path().append(entry.getKey()), variant.binding(), entry.getValue());
        for (CompoundName reference : in.listReferences(variant.path(), variant.binding().getContext())) // Used as a set; value is ignored
        references.put(variant.path().append(reference), variant.binding(), Boolean.TRUE);
        for (CompoundName name : in.listUnoverridable(variant.path(), variant.binding().getContext())) // Used as a set; value is ignored
        unoverridables.put(variant.path().append(name), variant.binding(), Boolean.TRUE);
    }
    return new CompiledQueryProfile(in.getId(), in.getType(), values.build(), types.build(), references.build(), unoverridables.build(), registry);
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) DimensionalMap(com.yahoo.search.query.profile.compiled.DimensionalMap) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) Map(java.util.Map) DimensionalMap(com.yahoo.search.query.profile.compiled.DimensionalMap) HashSet(java.util.HashSet)

Example 9 with CompoundName

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

the class QueryProfile method lookupParentExact.

/**
 * Looks up and, if necessary, creates, the query profile which should hold the given local name portion of the
 * given name. If the name contains no dots, this is returned.
 *
 * @param name the name of the variable to lookup the parent of
 * @param create whether or not to create the parent if it is not present
 * @return the parent, or null if not present and created is false
 */
private QueryProfile lookupParentExact(CompoundName name, boolean create, DimensionBinding dimensionBinding) {
    CompoundName rest = name.rest();
    if (rest.isEmpty())
        return this;
    QueryProfile topmostParent = getQueryProfileExact(name.first(), create, dimensionBinding);
    if (topmostParent == null)
        return null;
    return topmostParent.lookupParentExact(rest, create, dimensionBinding.createFor(topmostParent.getDimensions()));
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile)

Example 10 with CompoundName

use of com.yahoo.processing.request.CompoundName 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());
    }
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

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