Search in sources :

Example 96 with FieldValue

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

the class Bug4259784TestCase method annotate.

private void annotate(Document document, DocumentTypeManager manager) {
    AnnotationTypeRegistry registry = manager.getAnnotationTypeRegistry();
    AnnotationType company = registry.getType("company");
    AnnotationType industry = registry.getType("industry");
    AnnotationType person = registry.getType("person");
    AnnotationType location = registry.getType("location");
    SpanTree tree = new SpanTree("testannotations");
    SpanList root = (SpanList) tree.getRoot();
    SpanNode span1 = new Span(0, 5);
    SpanNode span2 = new Span(5, 10);
    SpanNode span3 = new Span(10, 15);
    SpanNode span4 = new Span(15, 20);
    SpanNode span5 = new Span(6, 10);
    SpanNode span6 = new Span(8, 4);
    SpanNode span7 = new Span(4, 2);
    root.add(span1);
    root.add(span2);
    root.add(span4);
    root.add(span5);
    root.add(span6);
    AlternateSpanList aspl = new AlternateSpanList();
    aspl.add(span7);
    List<SpanNode> subtree1 = new ArrayList<SpanNode>();
    subtree1.add(span3);
    aspl.addChildren(1, subtree1, 33.0d);
    root.add(aspl);
    Struct personValue = (Struct) person.getDataType().createFieldValue();
    personValue.setFieldValue("name", "Richard Bair");
    Annotation personAn = new Annotation(person, personValue);
    tree.annotate(span1, personAn);
    Struct companyValue = (Struct) company.getDataType().createFieldValue();
    companyValue.setFieldValue("name", "Sun");
    Annotation compAn = new Annotation(company, companyValue);
    tree.annotate(span2, compAn);
    Struct locationVal = new Struct(manager.getDataType("annotation.location"));
    locationVal.setFieldValue("lat", 37.774929);
    locationVal.setFieldValue("lon", -122.419415);
    Annotation locAnnotation = new Annotation(location, locationVal);
    tree.annotate(span3, locAnnotation);
    Struct dirValue1 = new Struct(manager.getDataType("annotation.person"));
    dirValue1.setFieldValue("name", "Jonathan Schwartz");
    Annotation dirAnnotation1 = new Annotation(person, dirValue1);
    tree.annotate(span5, dirAnnotation1);
    Struct dirValue2 = new Struct(manager.getDataType("annotation.person"));
    dirValue2.setFieldValue("name", "Scott Mcnealy");
    Annotation dirAnnotation2 = new Annotation(person, dirValue2);
    tree.annotate(span6, dirAnnotation2);
    Struct indValue = new Struct(manager.getDataType("annotation.industry"));
    indValue.setFieldValue("vertical", "Manufacturing");
    Annotation indAn = new Annotation(industry, indValue);
    tree.annotate(span4, indAn);
    Field compLocField = ((StructDataType) company.getDataType()).getField("place");
    AnnotationReferenceDataType annType = (AnnotationReferenceDataType) compLocField.getDataType();
    FieldValue compLocFieldVal = new AnnotationReference(annType, locAnnotation);
    companyValue.setFieldValue(compLocField, compLocFieldVal);
    companyValue.setFieldValue("vertical", "software");
    Field dirField = ((StructDataType) company.getDataType()).getField("directors");
    Array<FieldValue> dirFieldVal = new Array<FieldValue>(dirField.getDataType());
    AnnotationReferenceDataType annRefType = (AnnotationReferenceDataType) ((ArrayDataType) dirField.getDataType()).getNestedType();
    dirFieldVal.add(new AnnotationReference(annRefType, dirAnnotation1));
    dirFieldVal.add(new AnnotationReference(annRefType, dirAnnotation2));
    companyValue.setFieldValue(dirField, dirFieldVal);
    tree.clearAnnotations(span3);
    StringFieldValue body = (StringFieldValue) document.getFieldValue(document.getDataType().getField("body"));
    body.setSpanTree(tree);
    document.setFieldValue(document.getDataType().getField("body"), body);
}
Also used : ArrayList(java.util.ArrayList) Struct(com.yahoo.document.datatypes.Struct) Array(com.yahoo.document.datatypes.Array) Field(com.yahoo.document.Field) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StructDataType(com.yahoo.document.StructDataType) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 97 with FieldValue

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

the class VespaXMLUpdateReader method read.

public void read(AssignFieldPathUpdate update) {
    try {
        for (int i = 0; i < reader.getAttributeCount(); i++) {
            if (reader.getAttributeName(i).toString().equals("removeifzero")) {
                update.setRemoveIfZero(Boolean.parseBoolean(reader.getAttributeValue(i)));
            } else if (reader.getAttributeName(i).toString().equals("createmissingpath")) {
                update.setCreateMissingPath(Boolean.parseBoolean(reader.getAttributeValue(i)));
            }
        }
        DataType dt = update.getFieldPath().getResultingDataType();
        if (dt instanceof NumericDataType) {
            update.setExpression(reader.getElementText());
        } else {
            FieldValue fv = dt.createFieldValue();
            fv.deserialize(resolveField(update), this);
            update.setNewValue(fv);
        }
    } catch (XMLStreamException e) {
        throw newException(e);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue)

Example 98 with FieldValue

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

the class VespaXMLUpdateReader method read.

public void read(AddFieldPathUpdate update) {
    DataType dt = update.getFieldPath().getResultingDataType();
    FieldValue fv = dt.createFieldValue();
    fv.deserialize(resolveField(update), this);
    update.setNewValues((Array) fv);
}
Also used : FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue)

Example 99 with FieldValue

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

the class GetVarTestCase method requireThatGetVarCanBeUsedToImplementSum.

@Test
public void requireThatGetVarCanBeUsedToImplementSum() throws ParseException {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setOutputValue(null, "in", new StringFieldValue("0;1;2;3;4;5;6;7;8;9"));
    ScriptExpression.fromString("{ 0 | set_var tmp; " + "  input in | split ';' | for_each { to_int + get_var tmp | set_var tmp };" + "  get_var tmp | attribute out; }").execute(ctx);
    FieldValue val = ctx.getInputValue("out");
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(45, ((IntegerFieldValue) val).getInteger());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 100 with FieldValue

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

the class Base64DecodeTestCase method requireThatInputIsDecoded.

@Test
public void requireThatInputIsDecoded() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("zcIoHQ"));
    new Base64DecodeExpression().execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof LongFieldValue);
    assertEquals(489210573L, ((LongFieldValue) val).getLong());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) Test(org.junit.Test)

Aggregations

FieldValue (com.yahoo.document.datatypes.FieldValue)106 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)69 Test (org.junit.Test)52 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)45 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)30 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)26 Array (com.yahoo.document.datatypes.Array)20 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)20 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)18 StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)14 Struct (com.yahoo.document.datatypes.Struct)13 DataType (com.yahoo.document.DataType)12 Document (com.yahoo.document.Document)12 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)12 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)12 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)11 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)11 ByteArrayInputStream (java.io.ByteArrayInputStream)11 InputStream (java.io.InputStream)11 DocumentPut (com.yahoo.document.DocumentPut)10