Search in sources :

Example 51 with IntegerFieldValue

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

the class ToPositionTestCase method requireThatPositionIsParsed.

@Test
public void requireThatPositionIsParsed() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("6;9")).execute(new ToPositionExpression());
    FieldValue out = ctx.getValue();
    assertTrue(out instanceof StructuredFieldValue);
    assertEquals(PositionDataType.INSTANCE, out.getDataType());
    FieldValue val = ((StructuredFieldValue) out).getFieldValue("x");
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(6, ((IntegerFieldValue) val).getInteger());
    val = ((StructuredFieldValue) out).getFieldValue("y");
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(9, ((IntegerFieldValue) val).getInteger());
}
Also used : StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 52 with IntegerFieldValue

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

the class MapValueUpdate method checkCompatibility.

@Override
protected void checkCompatibility(DataType fieldType) {
    if (fieldType instanceof ArrayDataType) {
        if (!(value instanceof IntegerFieldValue)) {
            throw new IllegalArgumentException("Expected integer, got " + value.getClass().getName() + ".");
        }
        update.checkCompatibility(((ArrayDataType) fieldType).getNestedType());
    } else if (fieldType instanceof WeightedSetDataType) {
        ((WeightedSetDataType) fieldType).getNestedType().createFieldValue().assign(value);
        update.checkCompatibility(DataType.INT);
    } else if (fieldType instanceof StructuredDataType) {
        if (!(value instanceof StringFieldValue)) {
            throw new IllegalArgumentException("Expected string, got " + value.getClass().getName() + ".");
        }
        Field field = ((StructuredDataType) fieldType).getField(((StringFieldValue) value).getString());
        if (field == null) {
            throw new IllegalArgumentException("Field '" + value + "' not found.");
        }
        update.checkCompatibility(field.getDataType());
    } else {
        throw new UnsupportedOperationException("Field type " + fieldType.getName() + " not supported.");
    }
}
Also used : Field(com.yahoo.document.Field) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StructuredDataType(com.yahoo.document.StructuredDataType) ArrayDataType(com.yahoo.document.ArrayDataType)

Example 53 with IntegerFieldValue

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

the class VespaDocumentDeserializer42 method read.

public <T extends FieldValue> void read(FieldBase field, WeightedSet<T> ws) {
    WeightedSetDataType type = ws.getDataType();
    // Have no need for type
    getInt(null);
    int numElements = getInt(null);
    if (numElements < 0) {
        throw new DeserializationException("Bad number of weighted set elements, " + numElements);
    }
    // Avoid resizing
    ws.clearAndReserve(numElements * 2);
    for (int i = 0; i < numElements; i++) {
        int size = getInt(null);
        FieldValue value = type.getNestedType().createFieldValue();
        value.deserialize(null, this);
        IntegerFieldValue weight = new IntegerFieldValue(getInt(null));
        ws.putUnChecked((T) value, weight);
    }
}
Also used : WeightedSetDataType(com.yahoo.document.WeightedSetDataType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) 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)

Example 54 with IntegerFieldValue

use of com.yahoo.document.datatypes.IntegerFieldValue 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 55 with IntegerFieldValue

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

the class DocumentTestCase method testInheritance.

@Test
public void testInheritance() {
    // Create types that inherit each other.. And test that it works..
    DocumentType parentType = new DocumentType("parent");
    parentType.addField(new Field("parentbodyint", DataType.INT, false));
    parentType.addField(new Field("parentheaderint", DataType.INT, true));
    parentType.addField(new Field("overwritten", DataType.INT, true));
    DocumentType childType = new DocumentType("child");
    childType.addField(new Field("childbodyint", DataType.INT, false));
    childType.addField(new Field("childheaderint", DataType.INT, true));
    childType.addField(new Field("overwritten", DataType.INT, true));
    childType.inherit(parentType);
    DocumentTypeManager manager = new DocumentTypeManager();
    manager.register(childType);
    Document child = new Document(childType, new DocumentId("doc:what:test"));
    child.setFieldValue(childType.getField("parentbodyint"), new IntegerFieldValue(4));
    child.setFieldValue("parentheaderint", 6);
    child.setFieldValue("overwritten", 7);
    child.setFieldValue("childbodyint", 14);
    GrowableByteBuffer buffer = new GrowableByteBuffer(1024, 2f);
    child.serialize(buffer);
    buffer.flip();
    Document childCopy = manager.createDocument(buffer);
    // Test various ways of retrieving values
    assertEquals(new IntegerFieldValue(4), childCopy.getFieldValue(childType.getField("parentbodyint")));
    assertEquals(new IntegerFieldValue(6), childCopy.getFieldValue("parentheaderint"));
    assertEquals(new IntegerFieldValue(7), childCopy.getFieldValue("overwritten"));
    assertEquals(child, childCopy);
}
Also used : IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Test(org.junit.Test)

Aggregations

IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)69 Test (org.junit.Test)56 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)39 FieldValue (com.yahoo.document.datatypes.FieldValue)23 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)14 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)13 Array (com.yahoo.document.datatypes.Array)12 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)10 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)10 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)10 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)10 Struct (com.yahoo.document.datatypes.Struct)10 Field (com.yahoo.document.Field)8 DocumentType (com.yahoo.document.DocumentType)7 WeightedSet (com.yahoo.document.datatypes.WeightedSet)7 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)7 Document (com.yahoo.document.Document)5 DocumentUpdate (com.yahoo.document.DocumentUpdate)5 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)4 PredicateFieldValue (com.yahoo.document.datatypes.PredicateFieldValue)4