Search in sources :

Example 6 with StructuredFieldValue

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

the class CompositeReader method populateComposite.

// TODO createComposite is extremely similar to add/remove, refactor
// yes, this suppresswarnings ugliness is by intention, the code relies on the contracts in the builders
@SuppressWarnings({ "cast", "rawtypes" })
public static void populateComposite(TokenBuffer buffer, FieldValue fieldValue) {
    JsonToken token = buffer.currentToken();
    if ((token != JsonToken.START_OBJECT) && (token != JsonToken.START_ARRAY)) {
        throw new IllegalArgumentException("Expected '[' or '{'. Got '" + token + "'.");
    }
    if (fieldValue instanceof CollectionFieldValue) {
        DataType valueType = ((CollectionFieldValue) fieldValue).getDataType().getNestedType();
        if (fieldValue instanceof WeightedSet) {
            fillWeightedSet(buffer, valueType, (WeightedSet) fieldValue);
        } else {
            fillArray(buffer, (CollectionFieldValue) fieldValue, valueType);
        }
    } else if (fieldValue instanceof MapFieldValue) {
        MapReader.fillMap(buffer, (MapFieldValue) fieldValue);
    } else if (fieldValue instanceof StructuredFieldValue) {
        StructReader.fillStruct(buffer, (StructuredFieldValue) fieldValue);
    } else if (fieldValue instanceof TensorFieldValue) {
        TensorReader.fillTensor(buffer, (TensorFieldValue) fieldValue);
    } else {
        throw new IllegalStateException("Has created a composite field" + " value the reader does not know how to handle: " + fieldValue.getClass().getName() + " This is a bug. token = " + token);
    }
    expectCompositeEnd(buffer.currentToken());
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) DataType(com.yahoo.document.DataType) JsonToken(com.fasterxml.jackson.core.JsonToken) WeightedSet(com.yahoo.document.datatypes.WeightedSet) WeightedSetReader.fillWeightedSet(com.yahoo.document.json.readers.WeightedSetReader.fillWeightedSet)

Aggregations

StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)6 FieldValue (com.yahoo.document.datatypes.FieldValue)5 Field (com.yahoo.document.Field)2 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 DataType (com.yahoo.document.DataType)1 SpanTree (com.yahoo.document.annotation.SpanTree)1 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)1 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)1 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)1 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)1 WeightedSet (com.yahoo.document.datatypes.WeightedSet)1 JsonReaderException (com.yahoo.document.json.JsonReaderException)1 WeightedSetReader.fillWeightedSet (com.yahoo.document.json.readers.WeightedSetReader.fillWeightedSet)1 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)1 Test (org.junit.Test)1