Search in sources :

Example 26 with FieldValue

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);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) FieldValue(com.yahoo.document.datatypes.FieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue)

Example 27 with FieldValue

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();
}
Also used : CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue)

Example 28 with FieldValue

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();
}
Also used : DataType(com.yahoo.document.DataType) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 29 with FieldValue

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);
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 30 with FieldValue

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));
}
Also used : StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) Field(com.yahoo.document.Field) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Aggregations

FieldValue (com.yahoo.document.datatypes.FieldValue)106 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)69 Test (org.junit.Test)52 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)45 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)30 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)26 Array (com.yahoo.document.datatypes.Array)20 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)20 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)18 StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)14 Struct (com.yahoo.document.datatypes.Struct)13 DataType (com.yahoo.document.DataType)12 Document (com.yahoo.document.Document)12 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)12 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)12 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)11 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)11 ByteArrayInputStream (java.io.ByteArrayInputStream)11 InputStream (java.io.InputStream)11 DocumentPut (com.yahoo.document.DocumentPut)10