Search in sources :

Example 46 with FieldValue

use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.

the class VespaXMLUpdateReader method readAdd.

FieldUpdate readAdd(DocumentUpdate update) throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        if ("field".equals(reader.getAttributeName(i).toString())) {
            Field f = update.getDocumentType().getField(reader.getAttributeValue(i));
            FieldValue value = f.getDataType().createFieldValue();
            value.deserialize(f, this);
            if (value instanceof Array) {
                List<FieldValue> l = ((Array) value).getValues();
                return FieldUpdate.createAddAll(f, l);
            } else if (value instanceof WeightedSet) {
                return FieldUpdate.createAddAll(f, ((WeightedSet) value));
            } else {
                throw newDeserializeException("Add operation only applicable to multivalue lists");
            }
        }
    }
    throw newDeserializeException("Add update without field attribute");
}
Also used : Array(com.yahoo.document.datatypes.Array) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) WeightedSet(com.yahoo.document.datatypes.WeightedSet)

Example 47 with FieldValue

use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.

the class MapReader method fillMapFromArray.

@SuppressWarnings({ "rawtypes", "cast", "unchecked" })
public static void fillMapFromArray(TokenBuffer buffer, MapFieldValue parent) {
    JsonToken token = buffer.currentToken();
    int initNesting = buffer.nesting();
    expectArrayStart(token);
    token = buffer.next();
    DataType keyType = parent.getDataType().getKeyType();
    DataType valueType = parent.getDataType().getValueType();
    while (buffer.nesting() >= initNesting) {
        FieldValue key = null;
        FieldValue value = null;
        expectObjectStart(token);
        token = buffer.next();
        for (int i = 0; i < 2; ++i) {
            if (MAP_KEY.equals(buffer.currentName())) {
                key = readSingleValue(buffer, keyType);
            } else if (MAP_VALUE.equals(buffer.currentName())) {
                value = readSingleValue(buffer, valueType);
            }
            token = buffer.next();
        }
        Preconditions.checkState(key != null && value != null, "Missing key or value for map entry.");
        parent.put(key, value);
        expectObjectEnd(token);
        // array end or next entry
        token = buffer.next();
    }
}
Also used : DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) CollectionDataType(com.yahoo.document.CollectionDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) MapDataType(com.yahoo.document.MapDataType) JsonToken(com.fasterxml.jackson.core.JsonToken) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue)

Example 48 with FieldValue

use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.

the class MapReader method fillMapFromObject.

@SuppressWarnings({ "rawtypes", "cast", "unchecked" })
public static void fillMapFromObject(TokenBuffer buffer, MapFieldValue parent) {
    JsonToken token = buffer.currentToken();
    int initNesting = buffer.nesting();
    expectObjectStart(token);
    token = buffer.next();
    DataType keyType = parent.getDataType().getKeyType();
    DataType valueType = parent.getDataType().getValueType();
    while (buffer.nesting() >= initNesting) {
        FieldValue key = readAtomic(buffer.currentName(), keyType);
        FieldValue value = readSingleValue(buffer, valueType);
        Preconditions.checkState(key != null && value != null, "Missing key or value for map entry.");
        parent.put(key, value);
        token = buffer.next();
    }
    expectObjectEnd(token);
}
Also used : DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) CollectionDataType(com.yahoo.document.CollectionDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) MapDataType(com.yahoo.document.MapDataType) JsonToken(com.fasterxml.jackson.core.JsonToken) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue)

Example 49 with FieldValue

use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.

the class VespaJsonDocumentReader method readAddFieldPathUpdate.

private AddFieldPathUpdate readAddFieldPathUpdate(DocumentType documentType, String fieldPath, TokenBuffer buffer) {
    AddFieldPathUpdate fieldPathUpdate = new AddFieldPathUpdate(documentType, fieldPath);
    FieldValue fv = SingleValueReader.readSingleValue(buffer, fieldPathUpdate.getFieldPath().getResultingDataType());
    fieldPathUpdate.setNewValues((Array) fv);
    return fieldPathUpdate;
}
Also used : AddFieldPathUpdate(com.yahoo.document.fieldpathupdate.AddFieldPathUpdate) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 50 with FieldValue

use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.

the class VespaJsonDocumentReader method readAssignFieldPathUpdate.

private AssignFieldPathUpdate readAssignFieldPathUpdate(DocumentType documentType, String fieldPath, TokenBuffer buffer) {
    AssignFieldPathUpdate fieldPathUpdate = new AssignFieldPathUpdate(documentType, fieldPath);
    FieldValue fv = SingleValueReader.readSingleValue(buffer, fieldPathUpdate.getFieldPath().getResultingDataType());
    fieldPathUpdate.setNewValue(fv);
    return fieldPathUpdate;
}
Also used : FieldValue(com.yahoo.document.datatypes.FieldValue) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)

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