Search in sources :

Example 26 with Field

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));
}
Also used : StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) Field(com.yahoo.document.Field) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 27 with 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());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Field(com.yahoo.document.Field) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) FieldUpdate(com.yahoo.document.update.FieldUpdate)

Example 28 with Field

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;
}
Also used : Field(com.yahoo.document.Field) FieldPath(com.yahoo.document.FieldPath)

Example 29 with Field

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;
}
Also used : Field(com.yahoo.document.Field) FieldPath(com.yahoo.document.FieldPath)

Example 30 with Field

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)");
}
Also used : Field(com.yahoo.document.Field) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Field (com.yahoo.document.Field)115 Test (org.junit.Test)50 StructDataType (com.yahoo.document.StructDataType)46 DocumentType (com.yahoo.document.DocumentType)24 DataType (com.yahoo.document.DataType)17 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)14 ReferenceDataType (com.yahoo.document.ReferenceDataType)13 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)13 ArrayDataType (com.yahoo.document.ArrayDataType)12 MapDataType (com.yahoo.document.MapDataType)12 TensorDataType (com.yahoo.document.TensorDataType)11 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)11 SDField (com.yahoo.searchdefinition.document.SDField)10 PositionDataType (com.yahoo.document.PositionDataType)9 FieldValue (com.yahoo.document.datatypes.FieldValue)9 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)9 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)8 Struct (com.yahoo.document.datatypes.Struct)7 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)6 Document (com.yahoo.document.Document)5