use of com.yahoo.document.Field in project vespa by vespa-engine.
the class GetFieldExpression method doExecute.
@Override
protected void doExecute(ExecutionContext ctx) {
FieldValue input = ctx.getValue();
if (!(input instanceof StructuredFieldValue)) {
throw new IllegalArgumentException("Expected structured input, got " + input.getDataType().getName() + ".");
}
StructuredFieldValue struct = (StructuredFieldValue) input;
Field field = struct.getField(fieldName);
if (field == null) {
throw new IllegalArgumentException("Field '" + fieldName + "' not found.");
}
ctx.setValue(struct.getFieldValue(field));
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class ProcessingUpdateTestCase method testProcessingUpdates.
public void testProcessingUpdates() {
DocumentType articleType = new DocumentType("article");
articleType.addField(new Field("body", DataType.STRING, true));
articleType.addField(new Field("title", DataType.STRING, true));
dtm = new DocumentTypeManager();
dtm.registerDocumentType(articleType);
put = new DocumentPut(articleType, "doc:banana:apple");
put.getDocument().setFieldValue("body", "this is the body of the article, blah blah blah");
FieldUpdate upd = FieldUpdate.createAssign(articleType.getField("body"), new StringFieldValue("this is the updated body of the article, blahdi blahdi blahdi"));
update = new DocumentUpdate(articleType, new DocumentId("doc:grape:orange"));
update.addFieldUpdate(upd);
DocprocService service = new DocprocService("update");
DocumentProcessor firstP = new TitleDocumentProcessor();
service.setCallStack(new CallStack().addLast(firstP));
service.setInService(true);
Processing p = new Processing();
p.addDocumentOperation(put);
p.addDocumentOperation(update);
service.process(p);
while (service.doWork()) {
}
List<DocumentOperation> operations = p.getDocumentOperations();
Document first = ((DocumentPut) operations.get(0)).getDocument();
assertEquals(new StringFieldValue("this is the body of the article, blah blah blah"), first.getFieldValue("body"));
assertEquals(new StringFieldValue("body blah blah blah "), first.getFieldValue("title"));
DocumentUpdate second = (DocumentUpdate) operations.get(1);
FieldUpdate firstUpd = second.getFieldUpdate(0);
assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, firstUpd.getValueUpdate(0).getValueUpdateClassID());
assertEquals(new StringFieldValue("this is the updated body of the article, blahdi blahdi blahdi"), firstUpd.getValueUpdate(0).getValue());
FieldUpdate secondUpd = second.getFieldUpdate(1);
assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, secondUpd.getValueUpdate(0).getValueUpdateClassID());
assertEquals(new StringFieldValue("body blahdi blahdi blahdi "), secondUpd.getValueUpdate(0).getValue());
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class ProxyDocument method getField.
/**
* note that the returned Field may not be in this Document
* directly, but may refer to a field in a struct contained in it,
* in which case the returned Field is only useful for obtaining
* the field type; it can't be used for get() and set().
*/
@Override
public Field getField(String fieldName) {
if (fieldMap != null && fieldMap.containsKey(fieldName)) {
fieldName = fieldMap.get(fieldName);
}
FieldPath path = getFieldPath(fieldName);
Field ret = path.get(path.size() - 1).getFieldRef();
checkAccess(ret);
return ret;
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class ProxyDocument method getFieldPath.
private FieldPath getFieldPath(String fieldName) {
if (fieldMap != null && fieldMap.containsKey(fieldName)) {
fieldName = fieldMap.get(fieldName);
}
checkAccess(new Field(fieldName));
FieldPath path = FieldPath.newInstance(getDataType(), fieldName);
if (path == null || path.size() == 0) {
throw new IllegalArgumentException("Malformed schema mapping '" + fieldName + "'.");
}
return path;
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class VespaXmlUpdateReaderTestCase method requireThatArithmeticDeserializationValidateValue.
@Test
@Ignore
public void requireThatArithmeticDeserializationValidateValue() throws Exception {
// tracked in ticket 6675085
// problem caused by VespaXMLUpdateReader#readArithmetic() parsing value as double
Field field = new Field("my_field", DataType.BYTE);
assertThrows(field, "<increment field='my_field' by='-129' />", "Field 'my_field': Invalid byte \"-129\". (at line 1, column X)");
assertThrows(field, "<decrement field='my_field' by='-129' />", "Field 'my_field': Invalid byte \"-129\". (at line 1, column X)");
assertThrows(field, "<multiply field='my_field' by='-129' />", "Field 'my_field': Invalid byte \"-129\". (at line 1, column X)");
assertThrows(field, "<divide field='my_field' by='-129' />", "Field 'my_field': Invalid byte \"-129\". (at line 1, column X)");
assertThrows(field, "<alter field='my_field'><increment by='-129' /></alter>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column X)");
}
Aggregations