use of com.yahoo.document.datatypes.Struct in project vespa by vespa-engine.
the class VespaDocumentSerializerTestCase method compressed_map_of_compressed_structs_is_supported.
@Test
public void compressed_map_of_compressed_structs_is_supported() {
CompressionFixture fixture = new CompressionFixture();
Document doc = new Document(fixture.docType, "id:foo:map_of_structs::flarn");
Struct nested = new Struct(fixture.nestedType);
nested.setFieldValue("str", new StringFieldValue(CompressionFixture.COMPRESSABLE_STRING));
MapFieldValue<StringFieldValue, Struct> map = new MapFieldValue<StringFieldValue, Struct>(fixture.mapType);
map.put(new StringFieldValue("foo"), nested);
map.put(new StringFieldValue("bar"), nested);
doc.setFieldValue("map", map);
// Should _not_ throw any deserialization exceptions
Document result = fixture.roundtripSerialize(doc);
assertEquals(doc, result);
}
use of com.yahoo.document.datatypes.Struct in project vespa by vespa-engine.
the class VespaDocumentSerializerTestCase method incompressable_structs_are_serialized_without_buffer_size_overhead_bug.
@Test
public void incompressable_structs_are_serialized_without_buffer_size_overhead_bug() {
CompressionFixture fixture = new CompressionFixture();
Document doc = new Document(fixture.docType, "id:foo:map_of_structs::flarn");
Struct nested = new Struct(fixture.nestedType);
nested.setFieldValue("str", new StringFieldValue(CompressionFixture.COMPRESSABLE_STRING));
MapFieldValue<StringFieldValue, Struct> map = new MapFieldValue<StringFieldValue, Struct>(fixture.mapType);
// Only 1 struct added. Not enough redundant information that header struct containing map itself
// can be compressed.
map.put(new StringFieldValue("foo"), nested);
doc.setFieldValue("map", map);
GrowableByteBuffer buf = CompressionFixture.asSerialized(doc);
// Explanation of arbitrary value: buffer copy bug meant that incompressable structs were all serialized
// rounded up to 4096 bytes.
assertTrue(buf.remaining() < 4096);
}
use of com.yahoo.document.datatypes.Struct in project vespa by vespa-engine.
the class DocumentTestCase method testGetRecursiveValue.
@Test
public void testGetRecursiveValue() {
Document doc = new Document(testDocType, new DocumentId("doc:ns:testdoc"));
doc.setFieldValue("primitive1", 1);
Struct l1s1 = new Struct(doc.getField("l1s1").getDataType());
l1s1.setFieldValue("primitive1", 2);
Struct l2s1 = new Struct(doc.getField("struct2").getDataType());
l2s1.setFieldValue("primitive1", 3);
l2s1.setFieldValue("primitive2", 4);
Array<IntegerFieldValue> iarr1 = new Array<>(l2s1.getField("iarray").getDataType());
iarr1.add(new IntegerFieldValue(11));
iarr1.add(new IntegerFieldValue(12));
iarr1.add(new IntegerFieldValue(13));
l2s1.setFieldValue("iarray", iarr1);
ArrayDataType dt = (ArrayDataType) l2s1.getField("sarray").getDataType();
Array<Struct> sarr1 = new Array<>(dt);
{
Struct l3s1 = new Struct(dt.getNestedType());
l3s1.setFieldValue("primitive1", 1);
l3s1.setFieldValue("primitive2", 2);
sarr1.add(l3s1);
}
{
Struct l3s1 = new Struct(dt.getNestedType());
l3s1.setFieldValue("primitive1", 1);
l3s1.setFieldValue("primitive2", 2);
sarr1.add(l3s1);
}
l2s1.setFieldValue("sarray", sarr1);
MapFieldValue<StringFieldValue, StringFieldValue> smap1 = new MapFieldValue<>((MapDataType) l2s1.getField("smap").getDataType());
smap1.put(new StringFieldValue("leonardo"), new StringFieldValue("dicaprio"));
smap1.put(new StringFieldValue("ellen"), new StringFieldValue("page"));
smap1.put(new StringFieldValue("joseph"), new StringFieldValue("gordon-levitt"));
l2s1.setFieldValue("smap", smap1);
l1s1.setFieldValue("ss", l2s1.clone());
MapFieldValue<StringFieldValue, Struct> structmap1 = new MapFieldValue<>((MapDataType) l1s1.getField("structmap").getDataType());
structmap1.put(new StringFieldValue("test"), l2s1.clone());
l1s1.setFieldValue("structmap", structmap1);
WeightedSet<StringFieldValue> wset1 = new WeightedSet<>(l1s1.getField("wset").getDataType());
wset1.add(new StringFieldValue("foo"));
wset1.add(new StringFieldValue("bar"));
wset1.add(new StringFieldValue("zoo"));
l1s1.setFieldValue("wset", wset1);
Struct l2s2 = new Struct(doc.getField("struct2").getDataType());
l2s2.setFieldValue("primitive1", 5);
l2s2.setFieldValue("primitive2", 6);
WeightedSet<Struct> wset2 = new WeightedSet<>(l1s1.getField("structwset").getDataType());
wset2.add(l2s1.clone());
wset2.add(l2s2.clone());
l1s1.setFieldValue("structwset", wset2);
doc.setFieldValue("l1s1", l1s1.clone());
{
FieldValue fv = doc.getRecursiveValue("l1s1");
assertEquals(l1s1, fv);
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.primitive1");
assertEquals(new IntegerFieldValue(2), fv);
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.ss");
assertEquals(l2s1, fv);
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.ss.iarray");
assertEquals(iarr1, fv);
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.ss.iarray[2]");
assertEquals(new IntegerFieldValue(13), fv);
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.ss.iarray[3]");
assertNull(fv);
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.ss.sarray[0].primitive1");
assertEquals(new IntegerFieldValue(1), fv);
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.ss.smap{joseph}");
assertEquals(new StringFieldValue("gordon-levitt"), fv);
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.ss.smap.key");
assertEquals(3, ((Array) fv).size());
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.structmap{test}.primitive1");
assertEquals(new IntegerFieldValue(3), fv);
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.structmap.value.primitive1");
assertEquals(new IntegerFieldValue(3), fv);
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.wset{foo}");
assertEquals(new IntegerFieldValue(1), fv);
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.wset.key");
assertEquals(3, ((Array) fv).size());
}
{
FieldValue fv = doc.getRecursiveValue("l1s1.structwset.key.primitive1");
assertEquals(DataType.INT, (((ArrayDataType) fv.getDataType()).getNestedType()));
assertEquals(2, ((Array) fv).size());
}
}
use of com.yahoo.document.datatypes.Struct in project vespa by vespa-engine.
the class PositionTypeTestCase method requireThatAccessorsWork.
@Test
public void requireThatAccessorsWork() {
Struct val = PositionDataType.valueOf(6, 9);
assertEquals(new IntegerFieldValue(6), PositionDataType.getXValue(val));
assertEquals(new IntegerFieldValue(9), PositionDataType.getYValue(val));
}
use of com.yahoo.document.datatypes.Struct 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);
}
Aggregations