use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class UriParserTestCase method requireThatUriFieldsCanBeParsed.
@Test
public void requireThatUriFieldsCanBeParsed() throws Exception {
DocumentTypeManager mgr = new DocumentTypeManager();
DocumentType docType = new DocumentType("my_doc");
docType.addField("my_uri", DataType.URI);
docType.addField("my_arr", DataType.getArray(DataType.URI));
mgr.registerDocumentType(docType);
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test_uri.xml", mgr);
Iterator<VespaXMLFeedReader.Operation> it = parser.readAll().iterator();
Document doc = nextDocument(it);
assertNotNull(doc);
assertEquals(new StringFieldValue("scheme://host"), doc.getFieldValue("my_uri"));
assertNull(doc.getFieldValue("my_arr"));
assertNotNull(doc = nextDocument(it));
assertNull(doc.getFieldValue("my_uri"));
FieldValue val = doc.getFieldValue("my_arr");
assertNotNull(val);
assertTrue(val instanceof Array);
Array arr = (Array) val;
assertEquals(1, arr.size());
assertEquals(new StringFieldValue("scheme://host"), arr.get(0));
DocumentUpdate upd = nextUpdate(it);
assertNotNull(upd);
assertEquals(1, upd.getFieldUpdates().size());
FieldUpdate fieldUpd = upd.getFieldUpdate(0);
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_arr"), fieldUpd.getField());
assertEquals(1, fieldUpd.getValueUpdates().size());
ValueUpdate valueUpd = fieldUpd.getValueUpdate(0);
assertNotNull(valueUpd);
assertTrue(valueUpd instanceof AddValueUpdate);
assertEquals(new StringFieldValue("scheme://host"), valueUpd.getValue());
assertFalse(it.hasNext());
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class CatExpression method doExecute.
@Override
protected void doExecute(ExecutionContext ctx) {
FieldValue input = ctx.getValue();
DataType inputType = input != null ? input.getDataType() : null;
VerificationContext ver = new VerificationContext(ctx);
List<FieldValue> values = new LinkedList<>();
List<DataType> types = new LinkedList<>();
for (Expression exp : this) {
FieldValue val = ctx.setValue(input).execute(exp).getValue();
values.add(val);
DataType type;
if (val != null) {
type = val.getDataType();
} else {
type = ver.setValue(inputType).execute(this).getValue();
}
types.add(type);
}
DataType type = resolveOutputType(types);
ctx.setValue(type == DataType.STRING ? asString(values) : asCollection(type, values));
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class ForEachExpression method doExecute.
@Override
protected void doExecute(final ExecutionContext ctx) {
FieldValue input = ctx.getValue();
if (input instanceof Array || input instanceof WeightedSet) {
FieldValue next = new MyConverter(ctx, exp).convert(input);
if (next == null) {
VerificationContext vctx = new VerificationContext(ctx);
vctx.setValue(input.getDataType()).execute(this);
next = vctx.getValue().createFieldValue();
}
ctx.setValue(next);
} else if (input instanceof Struct) {
ctx.setValue(new MyConverter(ctx, exp).convert(input));
} else {
throw new IllegalArgumentException("Expected Array, Struct or WeightedSet input, got " + input.getDataType().getName() + ".");
}
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class SetValueTestCase method requireThatHashCodeAndEqualsAreImplemented.
@Test
public void requireThatHashCodeAndEqualsAreImplemented() {
FieldValue foo = new StringFieldValue("foo");
Expression exp = new SetValueExpression(foo);
assertFalse(exp.equals(new Object()));
assertFalse(exp.equals(new SetValueExpression(new StringFieldValue("bar"))));
assertEquals(exp, new SetValueExpression(foo));
assertEquals(exp.hashCode(), new SetValueExpression(foo).hashCode());
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class SetValueTestCase method requireThatAccessorsWork.
@Test
public void requireThatAccessorsWork() {
FieldValue foo = new StringFieldValue("foo");
SetValueExpression exp = new SetValueExpression(foo);
assertSame(foo, exp.getValue());
}
Aggregations