use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class MapDataType method buildFieldPath.
public static FieldPath buildFieldPath(String remainFieldName, DataType keyType, DataType valueType) {
if (remainFieldName.length() > 0 && remainFieldName.charAt(0) == '{') {
FieldPathEntry.KeyParseResult result = FieldPathEntry.parseKey(remainFieldName);
String keyValue = result.parsed;
FieldPath path = valueType.buildFieldPath(skipDotInString(remainFieldName, result.consumedChars - 1));
List<FieldPathEntry> tmpPath = new ArrayList<FieldPathEntry>(path.getList());
if (remainFieldName.charAt(1) == '$') {
tmpPath.add(0, FieldPathEntry.newVariableLookupEntry(keyValue.substring(1), valueType));
} else {
FieldValue fv = keyType.createFieldValue();
fv.assign(keyValue);
tmpPath.add(0, FieldPathEntry.newMapLookupEntry(fv, valueType));
}
return new FieldPath(tmpPath);
} else if (remainFieldName.startsWith("key")) {
FieldPath path = keyType.buildFieldPath(skipDotInString(remainFieldName, 2));
List<FieldPathEntry> tmpPath = new ArrayList<FieldPathEntry>(path.getList());
tmpPath.add(0, FieldPathEntry.newAllKeysLookupEntry(keyType));
return new FieldPath(tmpPath);
} else if (remainFieldName.startsWith("value")) {
FieldPath path = valueType.buildFieldPath(skipDotInString(remainFieldName, 4));
List<FieldPathEntry> tmpPath = new ArrayList<FieldPathEntry>(path.getList());
tmpPath.add(0, FieldPathEntry.newAllValuesLookupEntry(valueType));
return new FieldPath(tmpPath);
}
return keyType.buildFieldPath(remainFieldName);
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class SpanTree method cleanup.
/**
* Ensures consistency of the tree in case SpanNodes have been removed, and there are still
* Annotations pointing to them. This method has a maximum upper bound of O(3nm), where n is the
* total number of Annotations, and m is the number of SpanNodes that had been removed from the tree.
* The lower bound is Omega(n), if no SpanNodes had been removed from the tree.
*/
@SuppressWarnings("unchecked")
public void cleanup() {
Map<Annotation, Annotation> removedAnnotations = removeAnnotationsThatPointToInvalidSpanNodes();
// - remove annotation and add it to removedAnnotations map
if (!removedAnnotations.isEmpty()) {
Iterator<Annotation> annotationIt = iterator();
while (annotationIt.hasNext()) {
Annotation a = annotationIt.next();
if (!a.hasFieldValue()) {
continue;
}
FieldValue value = a.getFieldValue();
if (value instanceof AnnotationReference) {
// the annotation "a" has a reference
AnnotationReference ref = (AnnotationReference) value;
if (removedAnnotations.get(ref.getReference()) != null) {
// this reference refers to a dead annotation
ref.setReference(null);
a.setFieldValue(null);
if (!a.isSpanNodeValid()) {
// this annotation has no span node, delete it
annotationIt.remove();
removedAnnotations.put(a, a);
}
}
}
}
}
// - apart from this, keep struct, map etc. and annotation
if (!removedAnnotations.isEmpty()) {
for (Annotation a : this) {
if (!a.hasFieldValue()) {
continue;
}
removeObsoleteReferencesFromFieldValue(a.getFieldValue(), removedAnnotations, true);
}
}
// was any annotations removed from the global list? do we still have references to those annotations
// that have been removed? if so, remove the references
removeAnnotationReferencesThatPointToRemovedAnnotations();
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class Expression method execute.
public final FieldValue execute(ExecutionContext context) {
DataType inputType = requiredInputType();
if (inputType != null) {
FieldValue input = context.getValue();
if (input == null) {
return null;
}
if (!inputType.isValueCompatible(input)) {
throw new IllegalArgumentException("Expression '" + this + "' expected " + inputType.getName() + " input, got " + input.getDataType().getName() + ".");
}
}
doExecute(context);
DataType outputType = createdOutputType();
if (outputType != null) {
FieldValue output = context.getValue();
if (output != null && !outputType.isValueCompatible(output)) {
throw new IllegalStateException("Expression '" + this + "' expected " + outputType.getName() + " output, got " + output.getDataType().getName() + ".");
}
}
return context.getValue();
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class SwitchExpression method doExecute.
@Override
protected void doExecute(ExecutionContext ctx) {
FieldValue input = ctx.getValue();
Expression exp = null;
if (input != null) {
if (!(input instanceof StringFieldValue)) {
throw new IllegalArgumentException("Expected " + DataType.STRING.getName() + " input, got " + input.getDataType().getName() + ".");
}
exp = cases.get(String.valueOf(input));
}
if (exp == null) {
exp = defaultExp;
}
if (exp != null) {
exp.execute(ctx);
}
ctx.setValue(input);
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class GetFieldExpression method doExecute.
@Override
protected void doExecute(ExecutionContext ctx) {
FieldValue input = ctx.getValue();
if (!(input instanceof StructuredFieldValue)) {
throw new IllegalArgumentException("Expected structured input, got " + input.getDataType().getName() + ".");
}
StructuredFieldValue struct = (StructuredFieldValue) input;
Field field = struct.getField(fieldName);
if (field == null) {
throw new IllegalArgumentException("Field '" + fieldName + "' not found.");
}
ctx.setValue(struct.getFieldValue(field));
}
Aggregations