Search in sources :

Example 41 with DataType

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

the class WeightedSetTestCase method testAssignDoesNotIgnoreSpecialProperties.

public void testAssignDoesNotIgnoreSpecialProperties() {
    DataType type = DataType.getWeightedSet(DataType.STRING);
    WeightedSet<StringFieldValue> set = new WeightedSet<>(type);
    set.put(new StringFieldValue("hello"), 5);
    set.put(new StringFieldValue("aba"), 10);
    assertEquals(2, set.size());
    assertEquals(new Integer(5), set.get(new StringFieldValue("hello")));
    assertEquals(new Integer(10), set.get(new StringFieldValue("aba")));
    DataType type2 = DataType.getWeightedSet(DataType.STRING, true, true);
    WeightedSet<StringFieldValue> set2 = new WeightedSet<>(type2);
    set2.put(new StringFieldValue("hi"), 6);
    set2.put(new StringFieldValue("bye"), 13);
    set2.put(new StringFieldValue("see you"), 15);
    assertEquals(3, set2.size());
    assertEquals(new Integer(6), set2.get(new StringFieldValue("hi")));
    assertEquals(new Integer(13), set2.get(new StringFieldValue("bye")));
    assertEquals(new Integer(15), set2.get(new StringFieldValue("see you")));
    try {
        set.assign(set2);
        fail("it shouldn't be possible to assign a weighted set to another when types differ");
    } catch (IllegalArgumentException iae) {
    // success
    }
    assertEquals(2, set.size());
    assertEquals(new Integer(5), set.get(new StringFieldValue("hello")));
    assertEquals(new Integer(10), set.get(new StringFieldValue("aba")));
}
Also used : MapDataType(com.yahoo.document.MapDataType) DataType(com.yahoo.document.DataType)

Example 42 with DataType

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

the class SerializeAnnotationsTestCase method testSerializeAdvancedTree.

public void testSerializeAdvancedTree() throws IOException {
    SpanList root = new SpanList();
    SpanTree tree = new SpanTree("html", root);
    DataType positionType = docMan.getDataType("myposition");
    StructDataType cityDataType = (StructDataType) docMan.getDataType("annotation.city");
    AnnotationTypeRegistry registry = docMan.getAnnotationTypeRegistry();
    AnnotationType textType = registry.getType("text");
    AnnotationType beginTag = registry.getType("begintag");
    AnnotationType endTag = registry.getType("endtag");
    AnnotationType bodyType = registry.getType("body");
    AnnotationType paragraphType = registry.getType("paragraph");
    AnnotationType cityType = registry.getType("city");
    AnnotationReferenceDataType annRefType = (AnnotationReferenceDataType) docMan.getDataType("annotationreference<text>");
    Struct position = new Struct(positionType);
    position.setFieldValue("latitude", new DoubleFieldValue(37.774929));
    position.setFieldValue("longitude", new DoubleFieldValue(-122.419415));
    Annotation sanAnnotation = new Annotation(textType);
    Annotation franciscoAnnotation = new Annotation(textType);
    Struct positionWithRef = cityDataType.createFieldValue();
    positionWithRef.setFieldValue("position", position);
    Field referencesField = cityDataType.getField("references");
    Array<FieldValue> refList = new Array<FieldValue>(referencesField.getDataType());
    refList.add(new AnnotationReference(annRefType, sanAnnotation));
    refList.add(new AnnotationReference(annRefType, franciscoAnnotation));
    positionWithRef.setFieldValue(referencesField, refList);
    Annotation city = new Annotation(cityType, positionWithRef);
    AlternateSpanList paragraph = new AlternateSpanList();
    paragraph.addChildren(new ArrayList<SpanNode>(), 0);
    paragraph.setProbability(0, 0.9);
    paragraph.setProbability(1, 0.1);
    {
        Span span1 = new Span(6, 3);
        Span span2 = new Span(9, 10);
        Span span3 = new Span(19, 4);
        Span span4 = new Span(23, 4);
        paragraph.add(0, span1).add(0, span2).add(0, span3).add(0, span4);
        Span alt_span1 = new Span(6, 13);
        Span alt_span2 = new Span(19, 8);
        paragraph.add(1, alt_span1).add(1, alt_span2);
        tree.annotate(span1, beginTag).annotate(span2, textType).annotate(span3, sanAnnotation).annotate(span4, endTag).annotate(alt_span1, textType).annotate(alt_span2, bodyType).annotate(paragraph, paragraphType);
    }
    {
        Span span1 = new Span(0, 6);
        Span span2 = new Span(27, 9);
        Span span3 = new Span(36, 8);
        root.add(span1).add(paragraph).add(span2).add(span3);
        tree.annotate(span1, beginTag).annotate(span2, franciscoAnnotation).annotate(span3, endTag).annotate(root, bodyType).annotate(city);
    }
    StringFieldValue value = new StringFieldValue("lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj " + "lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj l jlkj lkj lkj " + "lkjoijoij oij oij oij oij oij oijoijoij oij oij oij oij oij " + "oijoijoijoijoijoijoijoijoijoijoijoijoij oij oij oij oij " + "oijaosdifjoai fdoais jdoasi jai os oafoai ai dfojsfoa dfoi dsf" + "aosifjasofija sodfij oasdifj aosdiosifjsi ooai oais osi");
    value.setSpanTree(tree);
    // important! call readFile() before writeFile()!
    ByteBuffer serializedFromFile = readFile("test_data_serialized_advanced");
    ByteBuffer serialized = writeFile(value, "test_data_serialized_advanced");
    assertEquals(serialized.limit(), serializedFromFile.limit());
    StringFieldValue valueFromFile = new StringFieldValue();
    DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(docMan, new GrowableByteBuffer(serializedFromFile));
    deserializer.read(null, valueFromFile);
    assertEquals(value, valueFromFile);
}
Also used : DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) ByteBuffer(java.nio.ByteBuffer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) 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) DataType(com.yahoo.document.DataType) StructDataType(com.yahoo.document.StructDataType) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 43 with DataType

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

the class ArithmeticExpression method requiredInputType.

@Override
public DataType requiredInputType() {
    DataType lhsType = lhs.requiredInputType();
    DataType rhsType = rhs.requiredInputType();
    if (lhsType == null) {
        return rhsType;
    }
    if (rhsType == null) {
        return lhsType;
    }
    if (!lhsType.equals(rhsType)) {
        throw new VerificationException(this, "Operands require conflicting input types, " + lhsType.getName() + " vs " + rhsType.getName() + ".");
    }
    return lhsType;
}
Also used : NumericDataType(com.yahoo.document.NumericDataType) DataType(com.yahoo.document.DataType)

Example 44 with DataType

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

the class CatExpression method doExecute.

@Override
protected void doExecute(ExecutionContext ctx) {
    FieldValue input = ctx.getValue();
    DataType inputType = input != null ? input.getDataType() : null;
    VerificationContext ver = new VerificationContext(ctx);
    List<FieldValue> values = new LinkedList<>();
    List<DataType> types = new LinkedList<>();
    for (Expression exp : this) {
        FieldValue val = ctx.setValue(input).execute(exp).getValue();
        values.add(val);
        DataType type;
        if (val != null) {
            type = val.getDataType();
        } else {
            type = ver.setValue(inputType).execute(this).getValue();
        }
        types.add(type);
    }
    DataType type = resolveOutputType(types);
    ctx.setValue(type == DataType.STRING ? asString(values) : asCollection(type, values));
}
Also used : CollectionDataType(com.yahoo.document.CollectionDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 45 with DataType

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

the class CatExpression method doVerify.

@Override
protected void doVerify(VerificationContext context) {
    DataType input = context.getValue();
    List<DataType> types = new LinkedList<>();
    for (Expression exp : this) {
        DataType val = context.setValue(input).execute(exp).getValue();
        types.add(val);
        if (val == null) {
            throw new VerificationException(this, "Attempting to concatenate a null value (" + exp + ").");
        }
    }
    context.setValue(resolveOutputType(types));
}
Also used : CollectionDataType(com.yahoo.document.CollectionDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType)

Aggregations

DataType (com.yahoo.document.DataType)62 ArrayDataType (com.yahoo.document.ArrayDataType)20 MapDataType (com.yahoo.document.MapDataType)19 Field (com.yahoo.document.Field)17 StructDataType (com.yahoo.document.StructDataType)17 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)17 ReferenceDataType (com.yahoo.document.ReferenceDataType)13 PositionDataType (com.yahoo.document.PositionDataType)12 CollectionDataType (com.yahoo.document.CollectionDataType)11 FieldValue (com.yahoo.document.datatypes.FieldValue)11 TensorDataType (com.yahoo.document.TensorDataType)10 DocumentType (com.yahoo.document.DocumentType)9 StructuredDataType (com.yahoo.document.StructuredDataType)7 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)6 SDField (com.yahoo.searchdefinition.document.SDField)6 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)5 TemporaryStructuredDataType (com.yahoo.document.TemporaryStructuredDataType)4 AnnotationReferenceDataType (com.yahoo.document.annotation.AnnotationReferenceDataType)4 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)4 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)4