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));
}
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());
}
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"));
}
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());
}
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"));
}
Aggregations