use of com.yahoo.document.Field in project vespa by vespa-engine.
the class ScriptTestCase method requireThatVariablesAreAvailableInScript.
@Test
public void requireThatVariablesAreAvailableInScript() {
SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out", DataType.INT));
newScript(newStatement(new SetValueExpression(new IntegerFieldValue(69)), new SetVarExpression("tmp")), newStatement(new GetVarExpression("tmp"), new AttributeExpression("out"))).execute(adapter);
assertEquals(new IntegerFieldValue(69), adapter.getInputValue("out"));
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class ScriptTestCase method requireThatScriptEvaluatesToInputValue.
@Test
public void requireThatScriptEvaluatesToInputValue() {
SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out", DataType.INT));
newStatement(new SetValueExpression(new IntegerFieldValue(6)), newScript(newStatement(new SetValueExpression(new IntegerFieldValue(9)))), new AttributeExpression("out")).execute(adapter);
assertEquals(new IntegerFieldValue(6), adapter.getInputValue("out"));
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class StructReader method fillStruct.
public static void fillStruct(TokenBuffer buffer, StructuredFieldValue parent) {
// do note the order of initializing initNesting and token is relevant for empty docs
int initNesting = buffer.nesting();
buffer.next();
while (buffer.nesting() >= initNesting) {
Field f = getField(buffer, parent);
try {
FieldValue v = readSingleValue(buffer, f.getDataType());
parent.setFieldValue(f, v);
buffer.next();
} catch (IllegalArgumentException e) {
throw new JsonReaderException(f, e);
}
}
}
use of com.yahoo.document.Field 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.Field in project vespa by vespa-engine.
the class VespaDocumentDeserializer42 method read.
public void read(FieldUpdate fieldUpdate) {
int fieldId = getInt(null);
Field field = fieldUpdate.getDocumentType().getField(fieldId, fieldUpdate.getSerializationVersion());
if (field == null) {
throw new DeserializationException("Cannot deserialize FieldUpdate, field fieldId " + fieldId + " not found in " + fieldUpdate.getDocumentType());
}
fieldUpdate.setField(field);
int size = getInt(null);
for (int i = 0; i < size; i++) {
if (field.getDataType() instanceof CollectionDataType) {
CollectionDataType collType = (CollectionDataType) field.getDataType();
fieldUpdate.addValueUpdate(getValueUpdate(collType, collType.getNestedType()));
} else {
fieldUpdate.addValueUpdate(getValueUpdate(field.getDataType(), null));
}
}
}
Aggregations