Search in sources :

Example 1 with AssignFieldPathUpdate

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

the class DocumentToPathUpdateTestCase method requireThatStructAssignIsConverted.

@Test
public void requireThatStructAssignIsConverted() {
    DocumentType docType = new DocumentType("my_type");
    StructDataType structType = new StructDataType("my_struct");
    structType.addField(new Field("b", DataType.INT));
    docType.addField(new Field("a", structType));
    Struct struct = structType.createFieldValue();
    struct.setFieldValue("b", new IntegerFieldValue(69));
    FieldPathUpdate upd = new AssignFieldPathUpdate(docType, "a", "", struct);
    Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
    assertNotNull(doc);
    FieldValue obj = doc.getFieldValue("a");
    assertTrue(obj instanceof Struct);
    struct = (Struct) obj;
    struct.setFieldValue("b", new IntegerFieldValue(96));
    DocumentUpdate docUpd = new FieldPathUpdateAdapter(new SimpleDocumentAdapter(null, doc), upd).getOutput();
    assertNotNull(docUpd);
    assertEquals(1, docUpd.getFieldPathUpdates().size());
    assertNotNull(upd = docUpd.getFieldPathUpdates().get(0));
    assertTrue(upd instanceof AssignFieldPathUpdate);
    assertEquals("a", upd.getOriginalFieldPath());
    assertEquals(struct, ((AssignFieldPathUpdate) upd).getNewValue());
}
Also used : IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) FieldPathUpdate(com.yahoo.document.fieldpathupdate.FieldPathUpdate) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 2 with AssignFieldPathUpdate

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

the class DocumentToPathUpdateTestCase method requireThatIntegerAssignIsConverted.

@Test
public void requireThatIntegerAssignIsConverted() {
    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);
    doc.setFieldValue("my_int", new IntegerFieldValue(96));
    DocumentUpdate docUpd = new FieldPathUpdateAdapter(new SimpleDocumentAdapter(null, doc), upd).getOutput();
    assertNotNull(docUpd);
    assertEquals(1, docUpd.getFieldPathUpdates().size());
    assertNotNull(upd = docUpd.getFieldPathUpdates().get(0));
    assertTrue(upd instanceof AssignFieldPathUpdate);
    assertEquals("my_int", upd.getOriginalFieldPath());
    assertEquals(new IntegerFieldValue(96), ((AssignFieldPathUpdate) upd).getNewValue());
}
Also used : IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) FieldPathUpdate(com.yahoo.document.fieldpathupdate.FieldPathUpdate) Test(org.junit.Test)

Example 3 with AssignFieldPathUpdate

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

the class DocumentToPathUpdateTestCase method requireThatStringAssignIsConverted.

@Test
public void requireThatStringAssignIsConverted() {
    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);
    doc.setFieldValue("my_str", new StringFieldValue("96"));
    DocumentUpdate docUpd = new FieldPathUpdateAdapter(new SimpleDocumentAdapter(null, doc), upd).getOutput();
    assertNotNull(docUpd);
    assertEquals(1, docUpd.getFieldPathUpdates().size());
    assertNotNull(upd = docUpd.getFieldPathUpdates().get(0));
    assertTrue(upd instanceof AssignFieldPathUpdate);
    assertEquals("my_str", upd.getOriginalFieldPath());
    assertEquals(new StringFieldValue("96"), ((AssignFieldPathUpdate) upd).getNewValue());
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) FieldPathUpdate(com.yahoo.document.fieldpathupdate.FieldPathUpdate) Test(org.junit.Test)

Example 4 with AssignFieldPathUpdate

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

the class DocumentToPathUpdateTestCase method requireThatStructElementAssignIsConverted.

@Test
public void requireThatStructElementAssignIsConverted() {
    DocumentType docType = new DocumentType("my_type");
    StructDataType structType = new StructDataType("my_struct");
    structType.addField(new Field("b", DataType.INT));
    docType.addField(new Field("a", structType));
    FieldPathUpdate upd = new AssignFieldPathUpdate(docType, "a.b", "", new IntegerFieldValue(69));
    Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
    assertNotNull(doc);
    FieldValue obj = doc.getFieldValue("a");
    assertTrue(obj instanceof Struct);
    Struct struct = (Struct) obj;
    struct.setFieldValue("b", new IntegerFieldValue(96));
    DocumentUpdate docUpd = new FieldPathUpdateAdapter(new SimpleDocumentAdapter(null, doc), upd).getOutput();
    assertNotNull(docUpd);
    assertEquals(1, docUpd.getFieldPathUpdates().size());
    assertNotNull(upd = docUpd.getFieldPathUpdates().get(0));
    assertTrue(upd instanceof AssignFieldPathUpdate);
    assertEquals("a.b", upd.getOriginalFieldPath());
    obj = ((AssignFieldPathUpdate) upd).getNewValue();
    assertTrue(obj instanceof IntegerFieldValue);
    assertEquals(96, ((IntegerFieldValue) obj).getInteger());
}
Also used : IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) FieldPathUpdate(com.yahoo.document.fieldpathupdate.FieldPathUpdate) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 5 with AssignFieldPathUpdate

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

the class PathUpdateToDocumentTestCase method requireThatNestedStructsAreConverted.

@Test
public void requireThatNestedStructsAreConverted() {
    DocumentType docType = new DocumentType("my_type");
    StructDataType structType = new StructDataType("my_struct");
    structType.addField(new Field("b", DataType.INT));
    docType.addField(new Field("a", structType));
    FieldPathUpdate upd = new AssignFieldPathUpdate(docType, "a.b", "", new IntegerFieldValue(69));
    Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
    assertNotNull(doc);
    FieldValue obj = doc.getFieldValue("a");
    assertTrue(obj instanceof Struct);
    Struct struct = (Struct) obj;
    assertEquals(new IntegerFieldValue(69), struct.getFieldValue("b"));
}
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