Search in sources :

Example 56 with IntegerFieldValue

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

the class DocumentTestCase method validateCppDocNotMap.

@SuppressWarnings("unchecked")
public void validateCppDocNotMap(Document doc) throws IOException {
    // in practice to validate v6 serialization
    assertEquals("doc:serializetest:http://test.doc.id/", doc.getId().toString());
    assertEquals(new IntegerFieldValue(5), doc.getFieldValue("intfield"));
    assertEquals(new FloatFieldValue((float) -9.23), doc.getFieldValue("floatfield"));
    assertEquals(new StringFieldValue("This is a string."), doc.getFieldValue("stringfield"));
    assertEquals(new LongFieldValue(398420092938472983L), doc.getFieldValue("longfield"));
    assertEquals(new DoubleFieldValue(98374532.398820d), doc.getFieldValue("doublefield"));
    assertEquals(new StringFieldValue("http://this.is.a.test/"), doc.getFieldValue("urifield"));
    // NOTE: The value really is unsigned 254, which becomes signed -2:
    assertEquals(new ByteFieldValue(-2), doc.getFieldValue("bytefield"));
    ByteBuffer raw = ByteBuffer.wrap("RAW DATA".getBytes());
    assertEquals(new Raw(raw), doc.getFieldValue("rawfield"));
    Document docindoc = (Document) doc.getFieldValue("docfield");
    assertEquals(docMan.getDocumentType("docindoc"), docindoc.getDataType());
    assertEquals(new DocumentId("doc:docindoc:http://embedded"), docindoc.getId());
    Array<FloatFieldValue> array = (Array<FloatFieldValue>) doc.getFieldValue("arrayoffloatfield");
    assertEquals(new FloatFieldValue(1.0f), array.get(0));
    assertEquals(new FloatFieldValue(2.0f), array.get(1));
    WeightedSet<StringFieldValue> wset = (WeightedSet<StringFieldValue>) doc.getFieldValue("wsfield");
    assertEquals(new Integer(50), wset.get(new StringFieldValue("Weighted 0")));
    assertEquals(new Integer(199), wset.get(new StringFieldValue("Weighted 1")));
}
Also used : DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Raw(com.yahoo.document.datatypes.Raw) ByteBuffer(java.nio.ByteBuffer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) Array(com.yahoo.document.datatypes.Array) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) WeightedSet(com.yahoo.document.datatypes.WeightedSet)

Example 57 with IntegerFieldValue

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

the class DocumentTestCase method testDocumentComparisonDoesNotCorruptStateBug6394548.

@Test
public void testDocumentComparisonDoesNotCorruptStateBug6394548() {
    DocumentTypeManager docMan = new DocumentTypeManager();
    DocumentType docType = new DocumentType("bug2354045");
    docType.addField(new Field("string", 2, DataType.STRING, true));
    docType.addField(new Field("int", 1, DataType.INT, true));
    docType.addField(new Field("float", 0, DataType.FLOAT, true));
    docMan.register(docType);
    Document doc1 = new Document(docType, new DocumentId("doc:a:b:bug6394548"));
    doc1.setFieldValue("string", new StringFieldValue("hello world"));
    doc1.setFieldValue("int", new IntegerFieldValue(1234));
    doc1.setFieldValue("float", new FloatFieldValue(5.5f));
    String doc1Before = doc1.toXml();
    Document doc2 = new Document(docType, new DocumentId("doc:a:b:bug6394548"));
    doc2.setFieldValue("string", new StringFieldValue("aardvark"));
    doc2.setFieldValue("int", new IntegerFieldValue(90909));
    doc2.setFieldValue("float", new FloatFieldValue(777.15f));
    String doc2Before = doc2.toXml();
    doc1.compareTo(doc2);
    String doc1After = doc1.toXml();
    String doc2After = doc2.toXml();
    assertEquals(doc1Before, doc1After);
    assertEquals(doc2Before, doc2After);
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) Test(org.junit.Test)

Example 58 with IntegerFieldValue

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

the class DocumentTestCase method testVariables.

@Test
public void testVariables() {
    ArrayDataType iarr = new ArrayDataType(DataType.INT);
    ArrayDataType iiarr = new ArrayDataType(iarr);
    ArrayDataType iiiarr = new ArrayDataType(iiarr);
    DocumentType type = new DocumentType("test");
    type.addField(new Field("iiiarray", iiiarr));
    Array<Array<Array<IntegerFieldValue>>> iiiaV = new Array<>(iiiarr);
    for (int i = 1; i < 4; i++) {
        Array<Array<IntegerFieldValue>> iiaV = new Array<>(iiarr);
        for (int j = 1; j < 4; j++) {
            Array<IntegerFieldValue> iaV = new Array<>(iarr);
            for (int k = 1; k < 4; k++) {
                iaV.add(new IntegerFieldValue(i * j * k));
            }
            iiaV.add(iaV);
        }
        iiiaV.add(iiaV);
    }
    Document doc = new Document(type, new DocumentId("doc:foo:testdoc"));
    doc.setFieldValue("iiiarray", iiiaV);
    {
        VariableIteratorHandler handler = new VariableIteratorHandler();
        FieldPath path = type.buildFieldPath("iiiarray[$x][$y][$z]");
        doc.iterateNested(path, 0, handler);
        String fasit = "x: 0,y: 0,z: 0, - 1\n" + "x: 0,y: 0,z: 1, - 2\n" + "x: 0,y: 0,z: 2, - 3\n" + "x: 0,y: 1,z: 0, - 2\n" + "x: 0,y: 1,z: 1, - 4\n" + "x: 0,y: 1,z: 2, - 6\n" + "x: 0,y: 2,z: 0, - 3\n" + "x: 0,y: 2,z: 1, - 6\n" + "x: 0,y: 2,z: 2, - 9\n" + "x: 1,y: 0,z: 0, - 2\n" + "x: 1,y: 0,z: 1, - 4\n" + "x: 1,y: 0,z: 2, - 6\n" + "x: 1,y: 1,z: 0, - 4\n" + "x: 1,y: 1,z: 1, - 8\n" + "x: 1,y: 1,z: 2, - 12\n" + "x: 1,y: 2,z: 0, - 6\n" + "x: 1,y: 2,z: 1, - 12\n" + "x: 1,y: 2,z: 2, - 18\n" + "x: 2,y: 0,z: 0, - 3\n" + "x: 2,y: 0,z: 1, - 6\n" + "x: 2,y: 0,z: 2, - 9\n" + "x: 2,y: 1,z: 0, - 6\n" + "x: 2,y: 1,z: 1, - 12\n" + "x: 2,y: 1,z: 2, - 18\n" + "x: 2,y: 2,z: 0, - 9\n" + "x: 2,y: 2,z: 1, - 18\n" + "x: 2,y: 2,z: 2, - 27\n";
        assertEquals(fasit, handler.retVal);
    }
}
Also used : IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Array(com.yahoo.document.datatypes.Array) Test(org.junit.Test)

Example 59 with IntegerFieldValue

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

the class DocumentTestCase method testModifyDocument.

@Test
public void testModifyDocument() {
    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());
    {
        ModifyIteratorHandler handler = new ModifyIteratorHandler();
        FieldPath path = doc.getDataType().buildFieldPath("l1s1.structmap.value.smap{leonardo}");
        doc.iterateNested(path, 0, handler);
        FieldValue fv = doc.getRecursiveValue("l1s1.structmap.value.smap{leonardo}");
        assertEquals(new StringFieldValue("newvalue"), fv);
    }
    {
        AddIteratorHandler handler = new AddIteratorHandler();
        FieldPath path = doc.getDataType().buildFieldPath("l1s1.ss.iarray");
        doc.iterateNested(path, 0, handler);
        FieldValue fv = doc.getRecursiveValue("l1s1.ss.iarray");
        assertTrue(((Array) fv).contains(new IntegerFieldValue(32)));
        assertEquals(4, ((Array) fv).size());
    }
    {
        RemoveIteratorHandler handler = new RemoveIteratorHandler();
        FieldPath path = doc.getDataType().buildFieldPath("l1s1.ss.iarray[1]");
        doc.iterateNested(path, 0, handler);
        FieldValue fv = doc.getRecursiveValue("l1s1.ss.iarray");
        assertFalse(((Array) fv).contains(new Integer(12)));
        assertEquals(3, ((Array) fv).size());
    }
    {
        RemoveIteratorHandler handler = new RemoveIteratorHandler();
        FieldPath path = doc.getDataType().buildFieldPath("l1s1.ss.iarray[$x]");
        doc.iterateNested(path, 0, handler);
        FieldValue fv = doc.getRecursiveValue("l1s1.ss.iarray");
        assertEquals(0, ((Array) fv).size());
    }
    {
        RemoveIteratorHandler handler = new RemoveIteratorHandler();
        FieldPath path = doc.getDataType().buildFieldPath("l1s1.structmap.value.smap{leonardo}");
        doc.iterateNested(path, 0, handler);
        FieldValue fv = doc.getRecursiveValue("l1s1.structmap.value.smap");
        assertFalse(((MapFieldValue) fv).contains(new StringFieldValue("leonardo")));
    }
    {
        RemoveIteratorHandler handler = new RemoveIteratorHandler();
        FieldPath path = doc.getDataType().buildFieldPath("l1s1.wset{foo}");
        doc.iterateNested(path, 0, handler);
        FieldValue fv = doc.getRecursiveValue("l1s1.wset");
        assertFalse(((WeightedSet) fv).contains(new StringFieldValue("foo")));
    }
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Struct(com.yahoo.document.datatypes.Struct) Array(com.yahoo.document.datatypes.Array) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) WeightedSet(com.yahoo.document.datatypes.WeightedSet) Test(org.junit.Test)

Example 60 with IntegerFieldValue

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

the class PositionTypeTestCase method requireThatPositionFactoryWorks.

@Test
public void requireThatPositionFactoryWorks() {
    Struct val = PositionDataType.valueOf(6, 9);
    assertEquals(new IntegerFieldValue(6), val.getFieldValue(PositionDataType.FIELD_X));
    assertEquals(new IntegerFieldValue(9), val.getFieldValue(PositionDataType.FIELD_Y));
    assertEquals(2, val.getFieldCount());
    val = PositionDataType.fromLong((6L << 32) + 9);
    assertEquals(new IntegerFieldValue(6), val.getFieldValue(PositionDataType.FIELD_X));
    assertEquals(new IntegerFieldValue(9), val.getFieldValue(PositionDataType.FIELD_Y));
    assertEquals(2, val.getFieldCount());
}
Also used : IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Aggregations

IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)69 Test (org.junit.Test)56 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)39 FieldValue (com.yahoo.document.datatypes.FieldValue)23 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)14 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)13 Array (com.yahoo.document.datatypes.Array)12 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)10 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)10 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)10 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)10 Struct (com.yahoo.document.datatypes.Struct)10 Field (com.yahoo.document.Field)8 DocumentType (com.yahoo.document.DocumentType)7 WeightedSet (com.yahoo.document.datatypes.WeightedSet)7 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)7 Document (com.yahoo.document.Document)5 DocumentUpdate (com.yahoo.document.DocumentUpdate)5 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)4 PredicateFieldValue (com.yahoo.document.datatypes.PredicateFieldValue)4