Search in sources :

Example 91 with StringFieldValue

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

the class SpanTestCase method serializeAndAssert.

private void serializeAndAssert(Span span) {
    GrowableByteBuffer buffer;
    {
        buffer = new GrowableByteBuffer(1024);
        DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
        StringFieldValue value = new StringFieldValue("lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj lk");
        SpanTree tree = new SpanTree("bababa", span);
        value.setSpanTree(tree);
        serializer.write(null, value);
        buffer.flip();
    }
    Span span2;
    {
        DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(man, buffer);
        StringFieldValue value = new StringFieldValue();
        deserializer.read(null, value);
        span2 = (Span) value.getSpanTree("bababa").getRoot();
    }
    assertEquals(span, span2);
    assertNotSame(span, span2);
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer)

Example 92 with StringFieldValue

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

the class SpanTreeTestCase method testCopyAnnotatedString.

@Test
public void testCopyAnnotatedString() {
    StringFieldValue str = getAnnotatedString();
    StringFieldValue strCopy = str.clone();
    SpanTree balloooTree = str.getSpanTree("ballooo");
    AlternateSpanList root = (AlternateSpanList) balloooTree.getRoot();
    Span s1 = (Span) root.children(0).get(0);
    Span s2 = (Span) root.children(0).get(1);
    Span s3 = (Span) root.children(0).get(2);
    AlternateSpanList s4 = (AlternateSpanList) root.children(0).get(3);
    Span s5 = (Span) s4.children(0).get(0);
    Span s6 = (Span) s4.children(0).get(1);
    Span s7 = (Span) root.children(1).get(0);
    Span s8 = (Span) root.children(1).get(1);
    Span s9 = (Span) root.children(1).get(2);
    SpanTree balloooTreeCopy = strCopy.getSpanTree("ballooo");
    assertEquals(balloooTree, balloooTreeCopy);
    assertNotSame(balloooTree, balloooTreeCopy);
    AlternateSpanList rootCopy = (AlternateSpanList) balloooTreeCopy.getRoot();
    assertEquals(root, rootCopy);
    assertNotSame(root, rootCopy);
    Span s1Copy = (Span) rootCopy.children(0).get(0);
    assertEquals(s1, s1Copy);
    assertNotSame(s1, s1Copy);
    Span s2Copy = (Span) rootCopy.children(0).get(1);
    assertEquals(s2, s2Copy);
    assertNotSame(s2, s2Copy);
    Span s3Copy = (Span) rootCopy.children(0).get(2);
    assertEquals(s3, s3Copy);
    assertNotSame(s3, s3Copy);
    AlternateSpanList s4Copy = (AlternateSpanList) rootCopy.children(0).get(3);
    assertEquals(s4, s4Copy);
    assertNotSame(s4, s4Copy);
    Span s5Copy = (Span) s4Copy.children(0).get(0);
    assertEquals(s5, s5Copy);
    assertNotSame(s5, s5Copy);
    Span s6Copy = (Span) s4Copy.children(0).get(1);
    assertEquals(s6, s6Copy);
    assertNotSame(s6, s6Copy);
    Span s7Copy = (Span) rootCopy.children(1).get(0);
    assertEquals(s7, s7Copy);
    assertNotSame(s7, s7Copy);
    Span s8Copy = (Span) rootCopy.children(1).get(1);
    assertEquals(s8, s8Copy);
    assertNotSame(s8, s8Copy);
    Span s9Copy = (Span) rootCopy.children(1).get(2);
    assertEquals(s9, s9Copy);
    assertNotSame(s9, s9Copy);
    Iterator<Annotation> annotationsBalloooTree;
    {
        List<Annotation> allAnnotationsList = new ArrayList<>();
        for (Annotation an : balloooTree) {
            allAnnotationsList.add(an);
        }
        Collections.sort(allAnnotationsList);
        annotationsBalloooTree = allAnnotationsList.iterator();
    }
    Annotation dummyAnnForS1 = annotationsBalloooTree.next();
    Annotation dummyAnnForS2 = annotationsBalloooTree.next();
    Annotation numberAnnForS2 = annotationsBalloooTree.next();
    IntegerFieldValue integerValForS2 = (IntegerFieldValue) numberAnnForS2.getFieldValue();
    Annotation motherAnnForS2 = annotationsBalloooTree.next();
    Struct motherValForS2 = (Struct) motherAnnForS2.getFieldValue();
    Annotation dummyAnnForS3 = annotationsBalloooTree.next();
    Annotation numberAnnForS3 = annotationsBalloooTree.next();
    IntegerFieldValue integerValForS3 = (IntegerFieldValue) numberAnnForS3.getFieldValue();
    Annotation dummyAnnForS5 = annotationsBalloooTree.next();
    Annotation daughterAnnForS6 = annotationsBalloooTree.next();
    Struct daughterValForS6 = (Struct) daughterAnnForS6.getFieldValue();
    AnnotationReference refFromS6ToMotherAnn = (AnnotationReference) daughterValForS6.getFieldValue("related");
    Iterator<Annotation> annotationsBalloooTreeCopy;
    {
        List<Annotation> allAnnotationsList = new ArrayList<>();
        for (Annotation an : balloooTreeCopy) {
            allAnnotationsList.add(an);
        }
        Collections.sort(allAnnotationsList);
        annotationsBalloooTreeCopy = allAnnotationsList.iterator();
    }
    Annotation dummyAnnForS1Copy = annotationsBalloooTreeCopy.next();
    assertEquals(dummyAnnForS1, dummyAnnForS1Copy);
    assertNotSame(dummyAnnForS1, dummyAnnForS1Copy);
    Annotation dummyAnnForS2Copy = annotationsBalloooTreeCopy.next();
    assertEquals(dummyAnnForS2, dummyAnnForS2Copy);
    assertNotSame(dummyAnnForS2, dummyAnnForS2Copy);
    Annotation numberAnnForS2Copy = annotationsBalloooTreeCopy.next();
    assertEquals(numberAnnForS2, numberAnnForS2Copy);
    assertNotSame(numberAnnForS2, numberAnnForS2Copy);
    IntegerFieldValue integerValForS2Copy = (IntegerFieldValue) numberAnnForS2Copy.getFieldValue();
    assertEquals(integerValForS2, integerValForS2Copy);
    assertNotSame(integerValForS2, integerValForS2Copy);
    Annotation motherAnnForS2Copy = annotationsBalloooTreeCopy.next();
    assertEquals(motherAnnForS2, motherAnnForS2Copy);
    assertNotSame(motherAnnForS2, motherAnnForS2Copy);
    Struct motherValForS2Copy = (Struct) motherAnnForS2Copy.getFieldValue();
    assertEquals(motherValForS2, motherValForS2Copy);
    assertNotSame(motherValForS2, motherValForS2Copy);
    Annotation dummyAnnForS3Copy = annotationsBalloooTreeCopy.next();
    assertEquals(dummyAnnForS3, dummyAnnForS3Copy);
    assertNotSame(dummyAnnForS3, dummyAnnForS3Copy);
    Annotation numberAnnForS3Copy = annotationsBalloooTreeCopy.next();
    assertEquals(numberAnnForS3, numberAnnForS3Copy);
    assertNotSame(numberAnnForS3, numberAnnForS3Copy);
    IntegerFieldValue integerValForS3Copy = (IntegerFieldValue) numberAnnForS3Copy.getFieldValue();
    assertEquals(integerValForS3, integerValForS3Copy);
    assertNotSame(integerValForS3, integerValForS3Copy);
    Annotation dummyAnnForS5Copy = annotationsBalloooTreeCopy.next();
    assertEquals(dummyAnnForS5, dummyAnnForS5Copy);
    assertNotSame(dummyAnnForS5, dummyAnnForS5Copy);
    Annotation daughterAnnForS6Copy = annotationsBalloooTreeCopy.next();
    assertEquals(daughterAnnForS6, daughterAnnForS6Copy);
    assertNotSame(daughterAnnForS6, daughterAnnForS6Copy);
    Struct daughterValForS6Copy = (Struct) daughterAnnForS6Copy.getFieldValue();
    assertEquals(daughterValForS6, daughterValForS6Copy);
    assertNotSame(daughterValForS6, daughterValForS6Copy);
    AnnotationReference refFromS6ToMotherAnnCopy = (AnnotationReference) daughterValForS6Copy.getFieldValue("related");
    assertEquals(refFromS6ToMotherAnn, refFromS6ToMotherAnnCopy);
    assertNotSame(refFromS6ToMotherAnn, refFromS6ToMotherAnnCopy);
    assertEquals(str, strCopy);
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 93 with StringFieldValue

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

the class SpanTreeTestCase method testSimpleCopy.

@Test
public void testSimpleCopy() {
    StringFieldValue string = new StringFieldValue("yahoooo");
    SpanList list = new SpanList();
    Span span1 = new Span(0, 1);
    Span span2 = new Span(1, 1);
    list.add(span1).add(span2);
    SpanTree tree = new SpanTree("foo", list);
    string.setSpanTree(tree);
    Annotation a1 = new Annotation(grape);
    tree.annotate(span1, a1);
    Annotation a2 = new Annotation(apple);
    tree.annotate(span2, a2);
    StringFieldValue stringCopy = string.clone();
    assertEquals(string, stringCopy);
    assertNotSame(string, stringCopy);
    SpanTree treeCopy = stringCopy.getSpanTree("foo");
    assertEquals(tree, treeCopy);
    assertNotSame(tree, treeCopy);
    SpanList listCopy = (SpanList) treeCopy.getRoot();
    assertEquals(list, listCopy);
    assertNotSame(list, listCopy);
    Span span1Copy = (Span) listCopy.children().get(0);
    assertEquals(span1, span1Copy);
    assertNotSame(span1, span1Copy);
    Span span2Copy = (Span) listCopy.children().get(1);
    assertEquals(span2, span2Copy);
    assertNotSame(span2, span2Copy);
    Iterator<Annotation> annotationIt;
    {
        List<Annotation> allAnnotationsList = new ArrayList<>();
        for (Annotation an : treeCopy) {
            allAnnotationsList.add(an);
        }
        Collections.sort(allAnnotationsList);
        annotationIt = allAnnotationsList.iterator();
    }
    Annotation a1Copy = annotationIt.next();
    assertEquals(a1, a1Copy);
    assertNotSame(a1, a1Copy);
    assertSame(span1Copy, a1Copy.getSpanNode());
    assertNotSame(span1, a1Copy.getSpanNode());
    Annotation a2Copy = annotationIt.next();
    assertEquals(a2, a2Copy);
    assertNotSame(a2, a2Copy);
    assertSame(span2Copy, a2Copy.getSpanNode());
    assertNotSame(span2, a2Copy.getSpanNode());
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Test(org.junit.Test)

Example 94 with StringFieldValue

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

the class SpanTreeTestCase method testCyclicReferences.

@Test
public void testCyclicReferences() {
    DocumentTypeManager docMan = new DocumentTypeManager();
    AnnotationTypeRegistry reg = docMan.getAnnotationTypeRegistry();
    StringFieldValue strfval = new StringFieldValue("hohohoho");
    SpanList root = new SpanList();
    SpanTree tree = new SpanTree("habahaba", root);
    strfval.setSpanTree(tree);
    // set up types:
    AnnotationType endTagType = new AnnotationType("endtag");
    AnnotationType beginTagType = new AnnotationType("begintag");
    AnnotationReferenceDataType refToBeginTagDataType = new AnnotationReferenceDataType(beginTagType);
    AnnotationReferenceDataType refToEndTagDataType = new AnnotationReferenceDataType(endTagType);
    endTagType.setDataType(refToBeginTagDataType);
    beginTagType.setDataType(refToEndTagDataType);
    // register types:
    reg.register(endTagType);
    reg.register(beginTagType);
    docMan.register(refToBeginTagDataType);
    docMan.register(refToEndTagDataType);
    // set up annotations and their references to each other:
    AnnotationReference refToBeginTag = new AnnotationReference(refToBeginTagDataType);
    AnnotationReference refToEndTag = new AnnotationReference(refToEndTagDataType);
    Annotation beginTag = new Annotation(beginTagType, refToEndTag);
    Annotation endTag = new Annotation(endTagType, refToBeginTag);
    refToBeginTag.setReference(beginTag);
    refToEndTag.setReference(endTag);
    // create spans:
    Span beginTagSpan = new Span(0, 1);
    Span endTagSpan = new Span(1, 1);
    root.add(beginTagSpan);
    root.add(endTagSpan);
    // annotate spans:
    tree.annotate(beginTagSpan, beginTag);
    tree.annotate(endTagSpan, endTag);
    // none of the below statements should lead to a StackOverflowError:
    assertFalse(endTag.toString().equals(beginTag.toString()));
    assertTrue(endTag.hashCode() != beginTag.hashCode());
    assertFalse(endTag.equals(beginTag));
    assertFalse(beginTag.equals(endTag));
    StringFieldValue copyString = strfval.clone();
    assertEquals(strfval, copyString);
    GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
    DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
    serializer.write(new Field("stringfield", DataType.STRING), strfval);
    buffer.flip();
    DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(docMan, buffer);
    StringFieldValue stringFieldValue2 = new StringFieldValue();
    deserializer.read(new Field("stringfield", DataType.STRING), stringFieldValue2);
    assertEquals(strfval, stringFieldValue2);
    assertNotSame(strfval, stringFieldValue2);
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Field(com.yahoo.document.Field) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Test(org.junit.Test)

Example 95 with StringFieldValue

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

the class SpanTreeTestCase method testSimpleCopy2.

@Test
public void testSimpleCopy2() {
    StringFieldValue string = new StringFieldValue("yahoooo");
    SpanList list = new SpanList();
    Span span1 = new Span(0, 1);
    Span span2 = new Span(1, 1);
    list.add(span1).add(span2);
    SpanTree tree = new SpanTree("foo", list);
    string.setSpanTree(tree);
    Annotation a1 = new Annotation(grape);
    tree.annotate(span1, a1);
    Annotation a2 = new Annotation(apple);
    tree.annotate(span2, a2);
    Struct donald = new Struct(person);
    donald.setFieldValue("firstname", "donald");
    donald.setFieldValue("lastname", "duck");
    donald.setFieldValue("birthyear", 1929);
    Annotation donaldAnn = new Annotation(personA, donald);
    tree.annotate(list, donaldAnn);
    StringFieldValue stringCopy = string.clone();
    assertEquals(string, stringCopy);
    assertNotSame(string, stringCopy);
    SpanTree treeCopy = stringCopy.getSpanTree("foo");
    assertEquals(tree, treeCopy);
    assertNotSame(tree, treeCopy);
    SpanList listCopy = (SpanList) treeCopy.getRoot();
    assertEquals(list, listCopy);
    assertNotSame(list, listCopy);
    Span span1Copy = (Span) listCopy.children().get(0);
    assertEquals(span1, span1Copy);
    assertNotSame(span1, span1Copy);
    Span span2Copy = (Span) listCopy.children().get(1);
    assertEquals(span2, span2Copy);
    assertNotSame(span2, span2Copy);
    Iterator<Annotation> annotationIt;
    {
        List<Annotation> allAnnotationsList = new ArrayList<>();
        for (Annotation an : treeCopy) {
            allAnnotationsList.add(an);
        }
        Collections.sort(allAnnotationsList);
        annotationIt = allAnnotationsList.iterator();
    }
    Annotation a1Copy = annotationIt.next();
    assertEquals(a1, a1Copy);
    assertNotSame(a1, a1Copy);
    assertSame(span1Copy, a1Copy.getSpanNode());
    assertNotSame(span1, a1Copy.getSpanNode());
    Annotation donaldAnnCopy = annotationIt.next();
    assertEquals(donaldAnn, donaldAnnCopy);
    assertNotSame(donaldAnn, donaldAnnCopy);
    assertSame(listCopy, donaldAnnCopy.getSpanNode());
    assertNotSame(list, donaldAnnCopy.getSpanNode());
    Struct donaldCopy = (Struct) donaldAnnCopy.getFieldValue();
    assertEquals(donald, donaldCopy);
    assertNotSame(donald, donaldCopy);
    Annotation a2Copy = annotationIt.next();
    assertEquals(a2, a2Copy);
    assertNotSame(a2, a2Copy);
    assertSame(span2Copy, a2Copy.getSpanNode());
    assertNotSame(span2, a2Copy.getSpanNode());
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Aggregations

StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)210 Test (org.junit.Test)136 FieldValue (com.yahoo.document.datatypes.FieldValue)49 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)40 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)37 Document (com.yahoo.document.Document)30 Array (com.yahoo.document.datatypes.Array)25 DocumentType (com.yahoo.document.DocumentType)21 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)21 Struct (com.yahoo.document.datatypes.Struct)21 DocumentPut (com.yahoo.document.DocumentPut)20 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)20 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)18 SpanTree (com.yahoo.document.annotation.SpanTree)15 FieldUpdate (com.yahoo.document.update.FieldUpdate)15 DocumentUpdate (com.yahoo.document.DocumentUpdate)12 Field (com.yahoo.document.Field)12 Annotation (com.yahoo.document.annotation.Annotation)12 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)12 HashMap (java.util.HashMap)12