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());
}
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.");
}
}
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);
}
}
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);
}
}
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);
}
Aggregations