Search in sources :

Example 16 with ArrayDataType

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

the class VespaDocumentDeserializer42 method getValueUpdate.

public ValueUpdate getValueUpdate(DataType superType, DataType subType) {
    int vuTypeId = getInt(null);
    ValueUpdate.ValueUpdateClassID op = ValueUpdate.ValueUpdateClassID.getID(vuTypeId);
    if (op == null) {
        throw new IllegalArgumentException("Read type " + vuTypeId + " of bytebuffer, but this is not a legal value update type.");
    }
    switch(op) {
        case ADD:
            {
                FieldValue fval = subType.createFieldValue();
                fval.deserialize(this);
                int weight = getInt(null);
                return new AddValueUpdate(fval, weight);
            }
        case ARITHMETIC:
            int opId = getInt(null);
            ArithmeticValueUpdate.Operator operator = ArithmeticValueUpdate.Operator.getID(opId);
            double operand = getDouble(null);
            return new ArithmeticValueUpdate(operator, operand);
        case ASSIGN:
            {
                byte contents = getByte(null);
                FieldValue fval = null;
                if (contents == (byte) 1) {
                    fval = superType.createFieldValue();
                    fval.deserialize(this);
                }
                return new AssignValueUpdate(fval);
            }
        case CLEAR:
            return new ClearValueUpdate();
        case MAP:
            if (superType instanceof ArrayDataType) {
                CollectionDataType type = (CollectionDataType) superType;
                IntegerFieldValue index = new IntegerFieldValue();
                index.deserialize(this);
                ValueUpdate update = getValueUpdate(type.getNestedType(), null);
                return new MapValueUpdate(index, update);
            } else if (superType instanceof WeightedSetDataType) {
                CollectionDataType type = (CollectionDataType) superType;
                FieldValue fval = type.getNestedType().createFieldValue();
                fval.deserialize(this);
                ValueUpdate update = getValueUpdate(DataType.INT, null);
                return new MapValueUpdate(fval, update);
            } else {
                throw new DeserializationException("MapValueUpdate only works for arrays and weighted sets");
            }
        case REMOVE:
            FieldValue fval = ((CollectionDataType) superType).getNestedType().createFieldValue();
            fval.deserialize(this);
            return new RemoveValueUpdate(fval);
        default:
            throw new DeserializationException("Could not deserialize ValueUpdate, unknown valueUpdateClassID type " + vuTypeId);
    }
}
Also used : MapValueUpdate(com.yahoo.document.update.MapValueUpdate) RemoveValueUpdate(com.yahoo.document.update.RemoveValueUpdate) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ClearValueUpdate(com.yahoo.document.update.ClearValueUpdate) CollectionDataType(com.yahoo.document.CollectionDataType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) AddValueUpdate(com.yahoo.document.update.AddValueUpdate) MapValueUpdate(com.yahoo.document.update.MapValueUpdate) RemoveValueUpdate(com.yahoo.document.update.RemoveValueUpdate) ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate) ClearValueUpdate(com.yahoo.document.update.ClearValueUpdate) AddValueUpdate(com.yahoo.document.update.AddValueUpdate) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) ReferenceFieldValue(com.yahoo.document.datatypes.ReferenceFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) ArrayDataType(com.yahoo.document.ArrayDataType) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate)

Example 17 with ArrayDataType

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

the class VespaDocumentDeserializer42 method read.

public <T extends FieldValue> void read(FieldBase field, Array<T> array) {
    int numElements = getNumCollectionElems();
    ArrayList<T> list = new ArrayList<T>(numElements);
    ArrayDataType type = array.getDataType();
    for (int i = 0; i < numElements; i++) {
        if (version < 7) {
            // We don't need size for anything
            getInt(null);
        }
        FieldValue fv = type.getNestedType().createFieldValue();
        fv.deserialize(null, this);
        list.add((T) fv);
    }
    array.clear();
    array.addAll(list);
}
Also used : ArrayList(java.util.ArrayList) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) ReferenceFieldValue(com.yahoo.document.datatypes.ReferenceFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) ArrayDataType(com.yahoo.document.ArrayDataType)

Example 18 with ArrayDataType

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

the class ArrayTestCase method testToArray.

public void testToArray() {
    ArrayDataType dt = new ArrayDataType(DataType.STRING);
    Array<StringFieldValue> arr = new Array<>(dt);
    arr.add(new StringFieldValue("a"));
    arr.add(new StringFieldValue("b"));
    arr.add(new StringFieldValue("c"));
    StringFieldValue[] tooSmall = new StringFieldValue[0];
    StringFieldValue[] bigEnough = new StringFieldValue[3];
    StringFieldValue[] a = arr.toArray(tooSmall);
    assertNotSame(tooSmall, a);
    assertEquals(new StringFieldValue("a"), a[0]);
    assertEquals(new StringFieldValue("b"), a[1]);
    assertEquals(new StringFieldValue("c"), a[2]);
    StringFieldValue[] b = arr.toArray(bigEnough);
    assertSame(bigEnough, b);
    assertEquals(new StringFieldValue("a"), b[0]);
    assertEquals(new StringFieldValue("b"), b[1]);
    assertEquals(new StringFieldValue("c"), b[2]);
}
Also used : ArrayDataType(com.yahoo.document.ArrayDataType)

Example 19 with ArrayDataType

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

the class JoinExpression method doVerify.

@Override
protected void doVerify(VerificationContext context) {
    DataType input = context.getValue();
    if (!(input instanceof ArrayDataType)) {
        throw new VerificationException(this, "Expected Array input, got " + input.getName() + ".");
    }
    context.setValue(createdOutputType());
}
Also used : DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) ArrayDataType(com.yahoo.document.ArrayDataType)

Example 20 with ArrayDataType

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

the class ToArrayExpression method doExecute.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void doExecute(ExecutionContext ctx) {
    FieldValue input = ctx.getValue();
    DataType inputType = input.getDataType();
    ArrayDataType outputType = DataType.getArray(inputType);
    Array output = outputType.createFieldValue();
    output.add(input);
    ctx.setValue(output);
}
Also used : Array(com.yahoo.document.datatypes.Array) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) FieldValue(com.yahoo.document.datatypes.FieldValue) ArrayDataType(com.yahoo.document.ArrayDataType)

Aggregations

ArrayDataType (com.yahoo.document.ArrayDataType)20 DataType (com.yahoo.document.DataType)8 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)8 Field (com.yahoo.document.Field)7 MapDataType (com.yahoo.document.MapDataType)6 DocumentType (com.yahoo.document.DocumentType)5 StructDataType (com.yahoo.document.StructDataType)5 PositionDataType (com.yahoo.document.PositionDataType)4 TensorDataType (com.yahoo.document.TensorDataType)4 FieldValue (com.yahoo.document.datatypes.FieldValue)4 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)4 ReferenceDataType (com.yahoo.document.ReferenceDataType)3 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)3 SDField (com.yahoo.searchdefinition.document.SDField)3 Test (org.junit.Test)3 StructuredDataType (com.yahoo.document.StructuredDataType)2 Array (com.yahoo.document.datatypes.Array)2 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)2 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)2 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)2