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());
}
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");
}
}
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);
}
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()));
}
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());
}
}
Aggregations