Search in sources :

Example 31 with AssignFieldPathUpdate

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

the class DocumentPathUpdateTestCase method testAssignSimpleMapValueWithVariable.

public void testAssignSimpleMapValueWithVariable() {
    Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
    MapFieldValue mfv = new MapFieldValue((MapDataType) doc.getField("strmap").getDataType());
    mfv.put(new StringFieldValue("foo"), new StringFieldValue("bar"));
    mfv.put(new StringFieldValue("baz"), new StringFieldValue("bananas"));
    doc.setFieldValue("strmap", mfv);
    // Select on map value, not key
    DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:hargl:bargl"));
    docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "strmap{$x}", "foobar.strmap{$x} == \"bar\"", new StringFieldValue("shinyvalue")));
    docUp.applyTo(doc);
    MapFieldValue valueNow = (MapFieldValue) doc.getFieldValue("strmap");
    assertEquals(2, valueNow.size());
    assertEquals(new StringFieldValue("shinyvalue"), valueNow.get(new StringFieldValue("foo")));
    assertEquals(new StringFieldValue("bananas"), valueNow.get(new StringFieldValue("baz")));
}
Also used : AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)

Example 32 with AssignFieldPathUpdate

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

the class PathUpdateToDocumentTestCase method requireThatArrayFieldsAreConverted.

@SuppressWarnings({ "unchecked" })
@Test
public void requireThatArrayFieldsAreConverted() {
    DocumentType docType = new DocumentType("my_type");
    ArrayDataType arrType = DataType.getArray(DataType.INT);
    docType.addField(new Field("my_arr", arrType));
    Array<IntegerFieldValue> arrVal = arrType.createFieldValue();
    arrVal.add(new IntegerFieldValue(6));
    arrVal.add(new IntegerFieldValue(9));
    FieldPathUpdate upd = new AssignFieldPathUpdate(docType, "my_arr", "", arrVal);
    Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
    assertNotNull(doc);
    FieldValue obj = doc.getFieldValue("my_arr");
    assertTrue(obj instanceof Array);
    Array arr = (Array) obj;
    assertEquals(2, arr.size());
    assertEquals(new IntegerFieldValue(6), arr.get(0));
    assertEquals(new IntegerFieldValue(9), arr.get(1));
}
Also used : AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) FieldPathUpdate(com.yahoo.document.fieldpathupdate.FieldPathUpdate) RemoveFieldPathUpdate(com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate) AddFieldPathUpdate(com.yahoo.document.fieldpathupdate.AddFieldPathUpdate) Test(org.junit.Test)

Example 33 with AssignFieldPathUpdate

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

the class PathUpdateToDocumentTestCase method requireThatWsetKeysAreConverted.

@Test
public void requireThatWsetKeysAreConverted() {
    DocumentType docType = new DocumentType("my_type");
    WeightedSetDataType wsetType = DataType.getWeightedSet(DataType.STRING);
    docType.addField(new Field("my_wset", wsetType));
    FieldPathUpdate upd = new AssignFieldPathUpdate(docType, "my_wset{69}", "", new IntegerFieldValue(96));
    Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
    assertNotNull(doc);
    FieldValue obj = doc.getFieldValue("my_wset");
    assertTrue(obj instanceof WeightedSet);
    WeightedSet wset = (WeightedSet) obj;
    assertEquals(1, wset.size());
    assertEquals(96, wset.get(new StringFieldValue("69")).intValue());
}
Also used : AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) FieldPathUpdate(com.yahoo.document.fieldpathupdate.FieldPathUpdate) RemoveFieldPathUpdate(com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate) AddFieldPathUpdate(com.yahoo.document.fieldpathupdate.AddFieldPathUpdate) Test(org.junit.Test)

Example 34 with AssignFieldPathUpdate

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

the class PathUpdateToDocumentTestCase method requireThatStringFieldsAreConverted.

@Test
public void requireThatStringFieldsAreConverted() {
    DocumentType docType = new DocumentType("my_type");
    docType.addField(new Field("my_str", DataType.STRING));
    FieldPathUpdate upd = new AssignFieldPathUpdate(docType, "my_str", "", new StringFieldValue("69"));
    Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
    assertNotNull(doc);
    assertEquals("69", ((StringFieldValue) doc.getFieldValue("my_str")).getString());
}
Also used : AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) FieldPathUpdate(com.yahoo.document.fieldpathupdate.FieldPathUpdate) RemoveFieldPathUpdate(com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate) AddFieldPathUpdate(com.yahoo.document.fieldpathupdate.AddFieldPathUpdate) Test(org.junit.Test)

Example 35 with AssignFieldPathUpdate

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

the class PathUpdateToDocumentTestCase method requireThatIntegerFieldsAreConverted.

@Test
public void requireThatIntegerFieldsAreConverted() {
    DocumentType docType = new DocumentType("my_type");
    docType.addField(new Field("my_int", DataType.INT));
    FieldPathUpdate upd = new AssignFieldPathUpdate(docType, "my_int", "", new IntegerFieldValue(69));
    Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
    assertNotNull(doc);
    assertEquals(69, ((IntegerFieldValue) doc.getFieldValue("my_int")).getInteger());
}
Also used : AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) FieldPathUpdate(com.yahoo.document.fieldpathupdate.FieldPathUpdate) RemoveFieldPathUpdate(com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate) AddFieldPathUpdate(com.yahoo.document.fieldpathupdate.AddFieldPathUpdate) Test(org.junit.Test)

Aggregations

AssignFieldPathUpdate (com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)35 AddFieldPathUpdate (com.yahoo.document.fieldpathupdate.AddFieldPathUpdate)9 FieldPathUpdate (com.yahoo.document.fieldpathupdate.FieldPathUpdate)9 Test (org.junit.Test)9 RemoveFieldPathUpdate (com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate)8 FieldValue (com.yahoo.document.datatypes.FieldValue)3 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)3 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DocumentType (com.yahoo.document.DocumentType)2 DocumentUpdate (com.yahoo.document.DocumentUpdate)2 Struct (com.yahoo.document.datatypes.Struct)2 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 XMLStreamException (javax.xml.stream.XMLStreamException)1