Search in sources :

Example 1 with ValueUpdate

use of com.yahoo.document.update.ValueUpdate in project vespa by vespa-engine.

the class DocumentUpdateTestCase method requireThatArrayOfStructElementAddIsProcessedCorrectly.

@Test
public void requireThatArrayOfStructElementAddIsProcessedCorrectly() throws ParseException {
    DocumentType docType = new DocumentType("my_input");
    docType.addField(new Field("my_str", DataType.getArray(DataType.STRING)));
    docType.addField(new Field("my_pos", DataType.getArray(PositionDataType.INSTANCE)));
    DocumentUpdate docUpdate = new DocumentUpdate(docType, "doc:scheme:");
    docUpdate.addFieldUpdate(FieldUpdate.createAdd(docType.getField("my_str"), new StringFieldValue("6;9")));
    docUpdate = Expression.execute(Expression.fromString("input my_str | for_each { to_pos } | index my_pos"), docUpdate);
    assertNotNull(docUpdate);
    assertEquals(0, docUpdate.getFieldPathUpdates().size());
    assertEquals(1, docUpdate.getFieldUpdates().size());
    FieldUpdate fieldUpd = docUpdate.getFieldUpdate(0);
    assertNotNull(fieldUpd);
    assertEquals(docType.getField("my_pos"), fieldUpd.getField());
    assertEquals(1, fieldUpd.getValueUpdates().size());
    ValueUpdate valueUpd = fieldUpd.getValueUpdate(0);
    assertNotNull(valueUpd);
    assertTrue(valueUpd instanceof AddValueUpdate);
    Object val = valueUpd.getValue();
    assertNotNull(val);
    assertTrue(val instanceof Struct);
    Struct pos = (Struct) val;
    assertEquals(PositionDataType.INSTANCE, pos.getDataType());
    assertEquals(new IntegerFieldValue(6), PositionDataType.getXValue(pos));
    assertEquals(new IntegerFieldValue(9), PositionDataType.getYValue(pos));
}
Also used : AddValueUpdate(com.yahoo.document.update.AddValueUpdate) ValueUpdate(com.yahoo.document.update.ValueUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) AddValueUpdate(com.yahoo.document.update.AddValueUpdate) FieldUpdate(com.yahoo.document.update.FieldUpdate) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 2 with ValueUpdate

use of com.yahoo.document.update.ValueUpdate in project vespa by vespa-engine.

the class GuardTestCase method requireThatInputFieldsAreIncludedByUpdate.

@Test
public void requireThatInputFieldsAreIncludedByUpdate() throws ParseException {
    DocumentType docType = new DocumentType("my_input");
    docType.addField(new Field("my_lng", DataType.LONG));
    docType.addField(new Field("my_str", DataType.STRING));
    DocumentUpdate docUpdate = new DocumentUpdate(docType, "doc:scheme:");
    docUpdate.addFieldUpdate(FieldUpdate.createAssign(docType.getField("my_str"), new StringFieldValue("69")));
    assertNotNull(docUpdate = Expression.execute(Expression.fromString("guard { input my_str | to_int | attribute my_lng }"), docUpdate));
    assertEquals(0, docUpdate.getFieldPathUpdates().size());
    assertEquals(1, docUpdate.getFieldUpdates().size());
    FieldUpdate fieldUpd = docUpdate.getFieldUpdate(0);
    assertNotNull(fieldUpd);
    assertEquals(docType.getField("my_lng"), fieldUpd.getField());
    assertEquals(1, fieldUpd.getValueUpdates().size());
    ValueUpdate valueUpd = fieldUpd.getValueUpdate(0);
    assertNotNull(valueUpd);
    assertTrue(valueUpd instanceof AssignValueUpdate);
    assertEquals(new LongFieldValue(69), valueUpd.getValue());
}
Also used : ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) Test(org.junit.Test)

Example 3 with ValueUpdate

use of com.yahoo.document.update.ValueUpdate in project vespa by vespa-engine.

the class ValueUpdateToDocumentTestCase method requireThatClearValueUpdatesAreConverted.

@Test
public void requireThatClearValueUpdatesAreConverted() {
    DocumentType docType = new DocumentType("my_type");
    Field field = new Field("my_int", DataType.INT);
    docType.addField(field);
    ValueUpdate update = ValueUpdate.createClear();
    Document doc = FieldUpdateHelper.newPartialDocument(docType, new DocumentId("doc:foo:1"), field, update);
    assertNotNull(doc);
    assertNotNull(doc.getFieldValue("my_int"));
    assertEquals(new IntegerFieldValue(), doc.getFieldValue("my_int"));
}
Also used : ValueUpdate(com.yahoo.document.update.ValueUpdate) Test(org.junit.Test)

Example 4 with ValueUpdate

use of com.yahoo.document.update.ValueUpdate in project vespa by vespa-engine.

the class ValueUpdateToDocumentTestCase method requireThatWsetKeysAreConverted.

@Test
public void requireThatWsetKeysAreConverted() {
    DocumentType docType = new DocumentType("my_type");
    WeightedSetDataType wsetType = DataType.getWeightedSet(DataType.STRING);
    Field field = new Field("my_wset", wsetType);
    docType.addField(field);
    ValueUpdate update = ValueUpdate.createMap(new StringFieldValue("69"), ValueUpdate.createAssign(new IntegerFieldValue(96)));
    Document doc = FieldUpdateHelper.newPartialDocument(docType, new DocumentId("doc:foo:1"), field, update);
    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 : ValueUpdate(com.yahoo.document.update.ValueUpdate) Test(org.junit.Test)

Example 5 with ValueUpdate

use of com.yahoo.document.update.ValueUpdate in project vespa by vespa-engine.

the class ValueUpdateToDocumentTestCase 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));
    Field field = new Field("a", structType);
    docType.addField(field);
    ValueUpdate update = ValueUpdate.createMap(new StringFieldValue("b"), ValueUpdate.createAssign(new IntegerFieldValue(42)));
    Document doc = FieldUpdateHelper.newPartialDocument(docType, new DocumentId("doc:foo:1"), field, update);
    assertNotNull(doc);
    FieldValue obj = doc.getFieldValue("a");
    assertTrue(obj instanceof Struct);
    Struct struct = (Struct) obj;
    assertEquals(new IntegerFieldValue(42), struct.getFieldValue("b"));
}
Also used : ValueUpdate(com.yahoo.document.update.ValueUpdate) Test(org.junit.Test)

Aggregations

ValueUpdate (com.yahoo.document.update.ValueUpdate)21 Test (org.junit.Test)16 FieldUpdate (com.yahoo.document.update.FieldUpdate)12 AssignValueUpdate (com.yahoo.document.update.AssignValueUpdate)10 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)8 AddValueUpdate (com.yahoo.document.update.AddValueUpdate)7 DocumentUpdate (com.yahoo.document.DocumentUpdate)5 ArithmeticValueUpdate (com.yahoo.document.update.ArithmeticValueUpdate)5 ClearValueUpdate (com.yahoo.document.update.ClearValueUpdate)5 MapValueUpdate (com.yahoo.document.update.MapValueUpdate)5 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)3 Struct (com.yahoo.document.datatypes.Struct)3 FieldValue (com.yahoo.document.datatypes.FieldValue)2 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)2 DocumentSerializer (com.yahoo.document.serialization.DocumentSerializer)2 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)2 HashMap (java.util.HashMap)2 Tuple2 (com.yahoo.collections.Tuple2)1 ArrayDataType (com.yahoo.document.ArrayDataType)1 CollectionDataType (com.yahoo.document.CollectionDataType)1